Introducing Closure Linter
Tuesday, August 31, 2010 | 3:45 PM
When collaborating with lots of engineers as we do here at Google, it’s important to keep a consistent coding style. To this end, we recently open sourced the Google JavaScript Style Guide.
Today we’re happy to announce we’re open sourcing a tool that will help you follow that style guide with minimal manual effort - the Closure Linter.
Take for example, this code:
var x = 10
var y=20;
for(var i = 0;i < 10; i++ ) {
x += i;
y -= i;
}
var z = [10, 20,];
x = y + z[0]
+ 10;
When we run
gjslint --strict fixme.js
we getLine 1, E:0010: (New error) Missing semicolon at end of line
Line 2, E:0002: Missing space before "="
Line 2, E:0002: Missing space after "="
Line 4, E:0002: Missing space before "("
Line 4, E:0002: Missing space after ";" in for statement
Line 4, E:0001: Extra space before ")"
Line 6, E:0006: (New error) Wrong indentation: expected any of {2} but got 3
Line 9, E:0121: Illegal comma at end of array literal
Line 12, E:0120: Binary operator should go on previous line "+"
Found 9 errors, including 2 new errors, in 1 files (0 files OK).
Even better, if we run
fixjsstyle --strict fixme.js
, 7 of the 9 errors are automatically fixed for us!We hope you can use the Closure Linter to improve your style consistency while simultaneously saving time. More information on how to get started can be found on the How to Use Closure Linter page.
We welcome comments and questions in the discussion forum.
20 comments:
Anonymous said...
The 'How to Use Closure Linter' link goes to the discussion forum.
August 31, 2010 at 4:56 PM
Paul Irish said...
Awesome!
Would be great to get an appspot hosted version of this.
August 31, 2010 at 10:58 PM
George Moschovitis said...
Great tool, thanks! How about releasing the Css Names extractor to make getCssName() useful?
or the utility used to split a compiled file into modules?
September 1, 2010 at 12:33 AM
trooper said...
Looks great! Thanks for the release!
September 1, 2010 at 2:09 AM
Unknown said...
This will be super handy!
September 1, 2010 at 9:34 AM
Ivan Zuzak said...
+1 to what Paul Irish said. This *definitely* deserves to be a web app.
September 1, 2010 at 9:59 AM
Unknown said...
Awesome!!! I really wanted you guys to release the linter :) Now we have one for C++ and now JavaScript =)
September 1, 2010 at 2:50 PM
Christopher Scott said...
Very cool; I'm gonna pass this, along with the link to the JS style guide to my team... thanks Google
September 1, 2010 at 3:52 PM
Victor De la Rocha said...
Very useful, Thanks!
September 1, 2010 at 3:55 PM
Alex Richards said...
Awesome! Will be using this from tomorrow!!
September 1, 2010 at 3:57 PM
Unknown said...
great tool, I wish some of the so called "js frameworks" had read this article before publishing their code.
BTW
the second example from the CONSTANT TOPIC is missing a comma at the end of line 8.
September 2, 2010 at 6:34 AM
peterbe said...
Found a bug. Where do I report it?
September 2, 2010 at 12:33 PM
Anonymous said...
Absolute useless tool. Visual Studio ctrl k + d, done.
September 2, 2010 at 3:57 PM
ajp said...
Bugs can be filed from the closure linter issues page on code.google.com: https://code.google.com/p/closure-linter/issues/list
September 2, 2010 at 8:13 PM
Sean said...
Cheers for releasing this tool - runs quickly and gives usable and coherent results.
September 4, 2010 at 8:12 PM
Fabian Fernandez said...
Good job people! I will propose this to my team and see if we can start using it. Thanks!
September 6, 2010 at 7:33 PM
turutosiya said...
fixjsstyle is vrey useful!
September 8, 2010 at 2:40 AM
Anonymous said...
excellent work, i'll recommend using this.
September 30, 2010 at 2:42 AM
idearat said...
Nice tool, I used it while @Google and am pleased to be able to keep it in my toolbox. My one complaint is that between the compiler and linter there still isn't a way to take third-party source code and cleanse it. If I run the linter on in I can't get it to fully bracket code by those who felt a few extra {'s were too much effort. If I try to run the compiler service it strips comments, although it does fully-bracket code. It'd be great if there were and option to the compiler service to say preserve comments so I could run it on other folks code and get something I'd feel comfortable checking in to a client's repository for production use.
November 14, 2010 at 2:46 PM
Zeta said...
in for(var i = ...
we need write
/** @type {number} */
for(var i =...
????
August 7, 2012 at 3:45 AM
Post a Comment