Before this blog, I wrote similar JS Verification Code tools: how to use JavaScript lint in Notepad ++. Closure Linter provided by Google gave us more tools.
Closure Linter runs on python, so first configure and install the python runtime environment in the system:
- Install python. I installed Python 2.5.4.
- Install the easy install module. That is to install setuptools under windows I install: setuptools-0.6c11.win32-py2.5.exe
- Make sure that easy install is configured to the PATH environment variable.
Then, execute the following command in the command line:
easy_install E:\closure_linter\closure_linter-2-1.2.6.tar.gz
If the following figure is displayed:
The closure Linter is successfully installed! OK. Run the following command in nppexec of notepad ++:
gjslint --strict $(FULL_CURRENT_PATH)
You can save this command as closure Linter. Click "OK". If the following result is output in the console window:
gjslint –-strict D:\work\js\WOYO\event.jsProcess started >>>----- FILE : D:\work\js\WOYO\event.js -----Line 3, E:0217: Missing @return JsDoc in function with non-trivial returnLine 4, E:0002: Missing space before "{"Line 5, E:0005: Illegal tab in whitespace before "if"Line 5, E:0002: Missing space before "("Line 6, E:0005: Illegal tab in whitespace before "return"Line 7, E:0005: Illegal tab in whitespace before "}"Line 8, E:0005: Illegal tab in whitespace before "else"Line 8, E:0002: Missing space before "("Line 9, E:0005: Illegal tab in whitespace before "var"Line 9, E:0002: Missing space before "="Line 9, E:0002: Missing space before "["Line 9, E:0131: Single-quoted string preferred over double-quoted string.Line 9, E:0131: Single-quoted string preferred over double-quoted string.Line 9, E:0131: Single-quoted string preferred over double-quoted string.Line 10, E:0005: Illegal tab in whitespace before ""Line 10, E:0001: Extra space at end of lineLine 11, E:0005: Illegal tab in whitespace before "for"Line 11, E:0002: Missing space before "("Line 11, E:0002: Missing space before "="Line 11, E:0002: Missing space after "="Line 11, E:0002: Missing space before "<"Line 11, E:0002: Missing space after "<"Line 12, E:0005: Illegal tab in whitespace before "try"Line 13, E:0005: Illegal tab in whitespace before "var"Line 14, E:0005: Illegal tab in whitespace before "return"Line 15, E:0005: Illegal tab in whitespace before "}"Line 16, E:0005: Illegal tab in whitespace before "catch"Line 16, E:0002: Missing space before "("Line 16, E:0002: Missing space before "{"Line 17, E:0005: Illegal tab in whitespace before "//"Line 18, E:0005: Illegal tab in whitespace before "}"Line 19, E:0005: Illegal tab in whitespace before "}"Line 20, E:0005: Illegal tab in whitespace before "}"Line 21, E:0005: Illegal tab in whitespace before "throw"Line 21, E:0131: Single-quoted string preferred over double-quoted string.Line 24, E:0220: No docs found for member 'Ajax.Request'Line 24, E:0002: Missing space before "{"Line 25, E:0005: Illegal tab in whitespace before "var"Line 26, E:0005: Illegal tab in whitespace before "var"Line 27, E:0005: Illegal tab in whitespace before "if"Line 27, E:0002: Missing space before "("Line 28, E:0005: Illegal tab in whitespace before "var"Line 28, E:0001: Extra space at end of lineLine 29, E:0005: Illegal tab in whitespace before "if"Line 29, E:0002: Missing space before "("Line 30, E:0005: Illegal tab in whitespace before "requestType"Line 31, E:0005: Illegal tab in whitespace before "}"Line 32, E:0005: Illegal tab in whitespace before "var"Line 33, E:0005: Illegal tab in whitespace before "req.open"Line 34, E:0005: Illegal tab in whitespace before "req.onreadystatechange"Line 35, E:0005: Illegal tab in whitespace before "if"Line 36, E:0005: Illegal tab in whitespace before "callbackData"Line 36, E:0002: Missing space after "+"Line 36, E:0002: Missing space before "+"Line 37, E:0005: Illegal tab in whitespace before "}"Line 38, E:0005: Illegal tab in whitespace before "}"Line 39, E:0005: Illegal tab in whitespace before "this.onSuccess"Line 39, E:0002: Missing space before "{"Line 41, E:0002: Missing space before "{"Line 42, E:0005: Illegal tab in whitespace before "$"Line 42, E:0002: Missing space before "{"Line 43, E:0005: Illegal tab in whitespace before "var"Line 44, E:0005: Illegal tab in whitespace before "url"Line 45, E:0005: Illegal tab in whitespace before "dataType"Line 46, E:0005: Illegal tab in whitespace before "}"Line 47, E:0005: Illegal tab in whitespace before "req.onSuccess"Line 47, E:0002: Missing space before "{"Line 48, E:0005: Illegal tab in whitespace before ""Line 48, E:0001: Extra space at end of lineLine 49, E:0005: Illegal tab in whitespace before "}"Line 50, E:0005: Illegal tab in whitespace before "$.ajax"Line 51, E:0005: Illegal tab in whitespace before "url"Line 52, E:0005: Illegal tab in whitespace before "dataType"Line 53, E:0005: Illegal tab in whitespace before "success"Line 54, E:0005: Illegal tab in whitespace before "$"Line 55, E:0005: Illegal tab in whitespace before "}"Line 56, E:0005: Illegal tab in whitespace before "}"Line 57, E:0005: Illegal tab in whitespace before "return"Line 58, E:0005: Illegal tab in whitespace before "}"Line 66, E:0210: Missing docs for parameter: "file"Line 66, E:0210: Missing docs for parameter: "postData"Line 67, E:0005: Illegal tab in whitespace before "var"Line 68, E:0005: Illegal tab in whitespace before "if"Line 68, E:0002: Missing space before "("Line 69, E:0005: Illegal tab in whitespace before "req.onreadystatechange"Line 70, E:0005: Illegal tab in whitespace before "if"Line 71, E:0005: Illegal tab in whitespace before "if"Line 72, E:0005: Illegal tab in whitespace before "alert"Line 73, E:0005: Illegal tab in whitespace before "return"Line 74, E:0005: Illegal tab in whitespace before "}"Line 75, E:0005: Illegal tab in whitespace before ""Line 75, E:0001: Extra space at end of lineLine 76, E:0005: Illegal tab in whitespace before "updateobj"Line 76, E:0110: Line too long (94 characters).Line 77, E:0005: Illegal tab in whitespace before "}"Line 78, E:0005: Illegal tab in whitespace before "req.open"Line 79, E:0005: Illegal tab in whitespace before "req.setRequestHeader"Line 79, E:0002: Missing space after ","Line 80, E:0005: Illegal tab in whitespace before "if"Line 81, E:0005: Illegal tab in whitespace before "req.send"Line 84, E:0005: Illegal tab in whitespace before "document.getElementsByTagName"Line 88, E:0005: Illegal tab in whitespace before "function"Line 89, E:0005: Illegal tab in whitespace before "function"Line 89, E:0001: Extra space after "function"Line 89, E:0131: Single-quoted string preferred over double-quoted string.Line 90, E:0005: Illegal tab in whitespace before "function"Line 90, E:0001: Extra space after "function"Line 90, E:0131: Single-quoted string preferred over double-quoted string.Line 91, E:0005: Illegal tab in whitespace before "function"Line 91, E:0001: Extra space after "function"Line 91, E:0131: Single-quoted string preferred over double-quoted string.Line 95, E:0005: Illegal tab in whitespace before "var"Line 96, E:0005: Illegal tab in whitespace before "for"Line 96, E:0002: Missing space before "("Line 96, E:0002: Missing space before "="Line 96, E:0002: Missing space after "="Line 96, E:0002: Missing space before "<"Line 96, E:0002: Missing space after "<"Line 97, E:0005: Illegal tab in whitespace before "try"Line 98, E:0005: Illegal tab in whitespace before "xmlhttp"Line 99, E:0005: Illegal tab in whitespace before "}"Line 100, E:0005: Illegal tab in whitespace before "catch"Line 100, E:0002: Missing space before "("Line 101, E:0005: Illegal tab in whitespace before "continue"Line 102, E:0005: Illegal tab in whitespace before "}"Line 103, E:0005: Illegal tab in whitespace before "break"Line 104, E:0005: Illegal tab in whitespace before "}"Line 105, E:0005: Illegal tab in whitespace before "return"Line 106, E:0300: File does not end with new line. (})Found 129 errors, including 0 new errors, in 1 files (0 files OK).Some of the errors reported by GJsLint may be auto-fixable using the scriptfixjsstyle. Please double check any changes it makes and report any bugs. Thescript can be run by executing:fixjsstyle –-strict D:\work\js\WOYO\event.js<<< Process finished.================ READY ================
The javascript code has been verified by the closure Linter tool. So many bugs! However, you can also use tools to fix bugs. Haha! Run the following command:
fixjsstyle –-strict $(FULL_CURRENT_PATH)
Result displayed in the console window:
fixjsstyle –-strict D:\work\js\WOYO\event.jsProcess started >>>Fixed 44 errors in D:\work\js\WOYO\event.js<<< Process finished.================ READY ================
44 bugs have been fixed in 129! Because the strict parameter is selected, it is very strict! Haha!
(End)