I'm working on a project that uses a specific styleguide for javascript. For instance, an if/else statement would look like this:
if( condition ){
// Bla bla
}
else {
// Another bla bla
}
What I'm looking for is a tool that would allow me to check the syntax of a file according to a specific styleguide. JSHint/JSLint don't focus on style, Closure Linter is not customizable, and Uncrustify reformats the file without warning (and doesn't officially support Javascript).
The best output I could get with this program would be the one from Closure Linter but with custom rules. Answers to this similar question were all wrong.
Does such a tool exist?
If you're still looking for an answer, you could try a project called jscs.
You can customize how your code should look like in almost any aspect, and those which you can't yet are being developed (function argument spacing, for example).
Everything is customizable via a .jscsrc
file; the following is an example of one of my projects using it:
{
"requireCurlyBraces": [ "if", "else", "for", "while", "do", "switch" ],
"requireSpaceAfterKeywords": [ "if", "else", "for", "while", "do", "switch" ],
"disallowSpaceAfterKeywords": [],
"requireSpacesInsideObjectBrackets": "all",
"disallowSpaceAfterObjectKeys": true,
"disallowImplicitTypeConversion": [],
"disallowKeywords": [ "with" ],
// ...
}
If you're using Grunt, feel free to try my own task for jscs - which is grunt-jscs-checker.
BTW, the jQuery team is using jscs :)
It sounds like you're really after a JavaScript beautifier. Checking can be done via "run it over the files and see if they change" backed by version control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With