Loading ...
Sorry, an error occurred while loading the content.

Fast fixing for JSLint

Expand Messages
  • aceblchboy
    What tools / do you use to quickly fix JS code up to satisfy JSLint s warnings and errors? First I test the code s parsability, if I can get to the end of the
    Message 1 of 4 , Jan 9, 2011
    • 0 Attachment
      What tools / do you use to quickly fix JS code up to satisfy JSLint's warnings and errors?

      First I test the code's parsability, if I can get to the end of the code without an error, it's good to go. This is much harder to do these days, with more stopping errors.

      Without concern for code formatting:
      I use closure compiler whitespace + pretty print mode to fix missing brackets. The drawback is that it eats empty constructor brackets, optional semicolons, breaks up else if the hard way (becomes } else { if), and completely reformats the code. One advantage of this is that it reformats quotation marks for consistency and precomputes some math constants.

      I then fill the missing semicolons with jsutility.pjoneil.net (JSLint derived). The drawback here is that it also completely reformats your code.

      I beautify it with jsbeautifier, and hunt down the less noisier warnings.

      With concern for formatting:
      I have JSLint parse the code and look for missing semicolons, and fill those in by hand.

      I have jsbeautifier beautify the code with indentation to match the document's formatting and preserve lines. This makes if\for\while (\(.*\)) (\w.*;)$ -> if\for\while \1 {\2} a fast bracket fix with another beautification. Then targeting the other warnings.

      I think i'll grab a previous version of JSLint since there are now so many error stops over what were previously simple issues.
    • Felix E. Klee
      ... None. But I run JSLint directly from my IDE: http://www.emacswiki.org/emacs/FlymakeJavaScript This allows me to quickly jump to errors and fix them
      Message 2 of 4 , Jan 9, 2011
      • 0 Attachment
        On Sun, Jan 9, 2011 at 9:46 AM, aceblchboy <aceblchboy@...> wrote:
        > What tools / do you use to quickly fix JS code up to satisfy JSLint's
        > warnings and errors?

        None. But I run JSLint directly from my IDE:

        http://www.emacswiki.org/emacs/FlymakeJavaScript

        This allows me to quickly jump to errors and fix them manually. I have
        tweaked "jslint-for-wsh" to also warn about unused variables.
      • Douglas Crockford
        ... I think you would do better to fix your code. I don t recommend automating correction because of the likelihood of automatic bug insertion. Using JSLint
        Message 3 of 4 , Jan 9, 2011
        • 0 Attachment
          --- In jslint_com@yahoogroups.com, "aceblchboy" <aceblchboy@...> wrote:
          >
          > What tools / do you use to quickly fix JS code up to satisfy JSLint's warnings and errors?
          >
          > First I test the code's parsability, if I can get to the end of the code without an error, it's good to go. This is much harder to do these days, with more stopping errors.
          >
          > Without concern for code formatting:
          > I use closure compiler whitespace + pretty print mode to fix missing brackets. The drawback is that it eats empty constructor brackets, optional semicolons, breaks up else if the hard way (becomes } else { if), and completely reformats the code. One advantage of this is that it reformats quotation marks for consistency and precomputes some math constants.
          >
          > I then fill the missing semicolons with jsutility.pjoneil.net (JSLint derived). The drawback here is that it also completely reformats your code.
          >
          > I beautify it with jsbeautifier, and hunt down the less noisier warnings.
          >
          > With concern for formatting:
          > I have JSLint parse the code and look for missing semicolons, and fill those in by hand.
          >
          > I have jsbeautifier beautify the code with indentation to match the document's formatting and preserve lines. This makes if\for\while (\(.*\)) (\w.*;)$ -> if\for\while \1 {\2} a fast bracket fix with another beautification. Then targeting the other warnings.
          >
          > I think i'll grab a previous version of JSLint since there are now so many error stops over what were previously simple issues.


          I think you would do better to fix your code.

          I don't recommend automating correction because of the likelihood of automatic bug insertion. Using JSLint with an IDE seems to be the best alternative.
        • Graham King
          ... code, run jslint in the background, alert me of any errors, and display warnings on the root window. It s a bash script that wires together inotify,
          Message 4 of 4 , Jan 9, 2011
          • 0 Attachment
            On 9 January 2011 00:46, aceblchboy <aceblchboy@...> wrote:

            >
            >
            > What tools / do you use to quickly fix JS code up to satisfy JSLint's
            > warnings and errors?
            >
            > I use lintswitch (https://github.com/grahamking/lintswitch) to watch my
            code, run jslint in the background, alert me of any errors, and display
            warnings on the root window. It's a bash script that wires together inotify,
            jslint, and imagemagick for output. Only tested on Ubuntu / Gnome. I'm lucky
            enough not to have any legacy JS to maintain, so I fix the errors by hand.


            [Non-text portions of this message have been removed]
          Your message has been successfully submitted and would be delivered to recipients shortly.