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 get
Line 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.


Anonymous said...

The 'How to Use Closure Linter' link goes to the discussion forum.

Paul Irish said...


Would be great to get an appspot hosted version of this.

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?

trooper said...

Looks great! Thanks for the release!

Unknown said...

This will be super handy!

Ivan Zuzak said...

+1 to what Paul Irish said. This *definitely* deserves to be a web app.

Unknown said...

Awesome!!! I really wanted you guys to release the linter :) Now we have one for C++ and now JavaScript =)

Christopher Scott said...

Very cool; I'm gonna pass this, along with the link to the JS style guide to my team... thanks Google

Victor De la Rocha said...

Very useful, Thanks!

Alex Richards said...

Awesome! Will be using this from tomorrow!!

Unknown said...

great tool, I wish some of the so called "js frameworks" had read this article before publishing their code.

the second example from the CONSTANT TOPIC is missing a comma at the end of line 8.

peterbe said...

Found a bug. Where do I report it?

Anonymous said...

Absolute useless tool. Visual Studio ctrl k + d, done.

ajp said...

Bugs can be filed from the closure linter issues page on

Sean said...

Cheers for releasing this tool - runs quickly and gives usable and coherent results.

Fabian Fernandez said...

Good job people! I will propose this to my team and see if we can start using it. Thanks!

turutosiya said...

fixjsstyle is vrey useful!

Anonymous said...

excellent work, i'll recommend using this.

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.

Zeta said...

in for(var i = ...

we need write
/** @type {number} */
for(var i =...