JSCS — JavaScript Code Style.
jscs is a code style checker. You can configure jscs for your project in detail using over 60 validation rules, including presets from popular style guides like jQuery.
This is a documentation for the development version, please refer to the https://www.npmjs.org/package/jscs instead
- Crockford - http://javascript.crockford.com/code.html
- Google - https://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
- jQuery - https://contribute.jquery.org/style-guide/js/
- MDCS - https://github.com/mrdoob/three.js/wiki/Mr.doob's-Code-Style%E2%84%A2
- Wikimedia - https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript
- Yandex - https://github.com/ymaps/codestyle/blob/master/js.md
- Grunt task: https://github.com/gustavohenke/grunt-jscs/
- Gulp task: https://github.com/sindresorhus/gulp-jscs/
- SublimeText 3 Plugin: https://github.com/SublimeLinter/SublimeLinter-jscs/
- Syntastic VIM Plugin: https://github.com/scrooloose/syntastic/.../syntax_checkers/javascript/jscs.vim/
- Atom plugin: https://atom.io/packages/linter-jscs
- Web Essentials for Visual Studio 2013: https://github.com/madskristensen/WebEssentials2013/
- Brackets Extension: https://github.com/globexdesigns/brackets-jscs
- A team city reporter: https://github.com/wurmr/jscs-teamcity-reporter
- JSdoc rules extension: https://github.com/zxqfox/jscs-jsdoc
jscs can be installed using npm:
npm install jscs -g
To run jscs, you can use the following command from the project root:
jscs path[ path[...]]
You can also pipe input into jscs:
cat myfile.js | jscs
Allows to define path to the config file.
jscs path[ path[...]] --config=./.config.json
If there is no --config option specified, jscs it will consequentially search for jscsConfig option in package.json file then for .jscsrc and .jscs.json files in the current working directory then in nearest ancestor until it hits the system root.
If defined will use predefined rules for specific code style.
jscs path[ path[...]] --preset=jquery
jscs itself provides six reporters: checkstyle, console, inline, junit and text.
jscs path[ path[...]] --reporter=console
But you also can specify your own reporter, since this flag accepts relative or absolute paths too.
jscs path[ path[...]] --reporter=./some-dir/my-reporter.js
Will be removed. Clean output without colors.
Outputs usage information.
Prepends the name of the offending rule to all error messages.
Outputs version of jscs.
Path to load additional rules
Type: Array
Values: Array of file matching patterns
"additionalRules": ["project-rules/*.js"]Extends defined rules with preset rules.
Type: String
Values: "crockford", "google", "jquery", "mdcs", "wikimedia", "yandex"
"preset": "jquery"If you want specifically disable preset rule assign it to null, like so:
{
"preset": "jquery",
"requireCurlyBraces": null
}Disables style checking for specified paths.
Type: Array
Values: Array of file matching patterns
"excludeFiles": ["node_modules/**"]Changes the set of file extensions that will be processed.
Type: Array or String or "*"
Values: A single file extension or an Array of file extensions, beginning with a .. The matching is case insensitive. If "*" is provided, all files regardless of extension will match.
"fileExtensions": [".js", ".jsx"]"fileExtensions": [".js"]You can disable and reenable rules inline with two special comments: // jscs:disable and // jscs:enable. Spacing in these comments is fairly lenient. All of the following are equivalent:
/* jscs: enable */
// jscs: enableYou can use them to disable rules in several ways.
Simply using // jscs:disable or // jscs:enable will disable all rules.
var a = b;
// jscs:disable
var c = d; // all errors on this line will be ignored
// jscs:enable
var e = f; // all errors on this line will be reportedIncluding a comma separated list of rules to modify after // jscs:disable or // jscs:enable will modify only those rules.
// jscs:disable requireCurlyBraces
if (x) y(); // all errors from requireCurlyBraces on this line will be ignored
// jscs:enable requireCurlyBraces
if (z) a(); // all errors, including from requireCurlyBraces, on this line will be reportedYou can enable all rules after disabling a specific rule, and that rule becomes reenabled as well.
// jscs:disable requireCurlyBraces
if (x) y(); // all errors from requireCurlyBraces on this line will be ignored
// jscs:enable
if (z) a(); // all errors, even from requireCurlyBraces, will be reportedYou can disable multiple rules at once and progressively reeanble them.
// jscs:disable requireCurlyBraces, requireDotNotation
if (x['a']) y(); // all errors from requireCurlyBraces OR requireDotNotation on this line will be ignored
// jscs:enable requireCurlyBraces
if (z['a']) a(); // all errors from requireDotNotation, but not requireCurlyBraces, will be ignored
// jscs:enable requireDotNotation
if (z['a']) a(); // all errors will be reportedRequires curly braces after statements.
Type: Array
Values: Array of quoted keywords
JSHint: curly
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch",
"case",
"default"
]if (x) {
x++;
}if (x) x++;Requires space after keyword.
Type: Array
Values: Array of quoted keywords
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
]return true;if(x) {
x++;
}Disallows space after keyword.
Type: Array
Values: Array of quoted keywords
"disallowSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"try",
"catch"
]if(x > y) {
y++;
}Requires space before block statements (for loops, control structures).
Type: Boolean
Values: true
"requireSpaceBeforeBlockStatements": trueif (cond) {
foo();
}
for (var e in elements) {
bar(e);
}
while (cond) {
foo();
}if (cond){
foo();
}
for (var e in elements){
bar(e);
}
while (cond){
foo();
}Disallows space before block statements (for loops, control structures).
Type: Boolean
Values: true
"disallowSpaceBeforeBlockStatements": trueif (cond){
foo();
}
for (var e in elements){
bar(e);
}
while (cond){
foo();
}if (cond) {
foo();
}
for (var e in elements) {
bar(e);
}
while (cond) {
foo();
}Requires parentheses around immediately invoked function expressions.
Type: Boolean
Values: true
JSHint: immed
"requireParenthesesAroundIIFE": truevar a = (function(){ return 1; })();
var b = (function(){ return 2; }());
var c = (function(){ return 3; }).call(this, arg1);
var d = (function(){ return 3; }.call(this, arg1));
var e = (function(){ return d; }).apply(this, args);
var f = (function(){ return d; }.apply(this, args));var a = function(){ return 1; }();
var c = function(){ return 3; }.call(this, arg1);
var d = function(){ return d; }.apply(this, args);Requires space before and/or after ? or : in conditional expressions.
Type: Object or Boolean
Values: "afterTest", "beforeConsequent", "afterConsequent", "beforeAlternate" as child properties, or true to set all properties to true. Child properties must be set to true.
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
}var a = b ? c : d;
var a= b ? c : d;var a = b? c : d;
var a = b ?c : d;
var a = b ? c: d;
var a = b ? c :d;Disallows space before and/or after ? or : in conditional expressions.
Type: Object or Boolean
Values: "afterTest", "beforeConsequent", "afterConsequent", "beforeAlternate" as child properties, or true to set all properties to true. Child properties must be set to true.
"disallowSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
}var a = b?c:d;
var a= b?c:d;var a = b ?c:d;
var a = b? c:d;
var a = b?c :d;
var a = b?c: d;Requires space before () or {} in function expressions (both named and anonymous).
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"requireSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function () {}
function a () {}function() {}
function (){}Disallows space before () or {} in function expressions (both named and anonymous).
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function(){}
function a(){}function () {}
function a (){}Requires space before () or {} in anonymous function expressions.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function () {}function() {}
function (){}Disallows space before () or {} in anonymous function expressions.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function(){}function () {}
function (){}Requires space before () or {} in named function expressions.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"requireSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function a () {}function a() {}
function a(){}Disallows space before () or {} in named function expressions.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function a(){}function a () {}
function a (){}Requires space before () or {} in function declarations.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"requireSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function a () {}function a() {}
function a (){}Disallows space before () or {} in function declarations.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function a(){}function a () {}
function a (){}Requires space before () or {} in function declarations and expressions.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"requireSpacesInFunction": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function a () {}function a() {}
function a (){}Disallows space before () or {} in function declarations and expressions.
Type: Object
Values: "beforeOpeningRoundBrace" and "beforeOpeningCurlyBrace" as child properties. Child properties must be set to true.
"disallowSpacesInFunction": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
}function a(){}function a () {}
function a (){}Disallows multiple var declaration (except for-loop).
Type: Boolean
Values: true
"disallowMultipleVarDecl": truevar x = 1;
var y = 2;
for (var i = 0, j = arr.length; i < j; i++) {}var x = 1,
y = 2;Requires multiple var declaration.
Type: Boolean or String
Values: true or "onevar"
if requireMultipleVarDecl defined as a true value, it will report only consecutive vars, if, on the other hand,
value equals to "onevar" string, requireMultipleVarDecl will allow only one var per function scope.
JSHint: onevar
"requireMultipleVarDecl": truevar x = 1,
y = 2;var x = 1;
var y = 2;Requires blocks to begin and end with a newline
Type: Boolean or Integer
Values: true validates all non-empty blocks, Integer specifies a minimum number of statements in the block before validating.
"requireBlocksOnNewline": trueif (true) {
doSomething();
}
var abc = function() {};if (true) {doSomething();}if (true) {
doSomething();
doSomethingElse();
}
if (true) { doSomething(); }
var abc = function() {};if (true) { doSomething(); doSomethingElse(); }Requires blocks to begin and end with 2 newlines
Type: Boolean or Integer
Values: true validates all non-empty blocks, Integer specifies a minimum number of statements in the block before validating.
"requirePaddingNewlinesInBlocks": trueif (true) {
doSomething();
}
var abc = function() {};if (true) {doSomething();}
if (true) {
doSomething();
}if (true) {
doSomething();
doSomethingElse();
}
if (true) {
doSomething();
}
if (true) { doSomething(); }
var abc = function() {};if (true) { doSomething(); doSomethingElse(); }
if (true) {
doSomething();
doSomethingElse();
}Disallows blocks from beginning and ending with 2 newlines.
Type: Boolean
Values: true validates all non-empty blocks.
"disallowPaddingNewlinesInBlocks": trueif (true) {
doSomething();
}
if (true) {doSomething();}
var abc = function() {};if (true) {
doSomething();
}Disallows empty blocks (except for catch blocks).
Type: Boolean
Values: true
JSHint: noempty
"disallowEmptyBlocks": trueif ( a == b ) { c = d; }
try { a = b; } catch( e ){}if ( a == b ) { } else { c = d; }Disallows space after opening object curly brace and before closing.
Type: Boolean or String
Values: "all" or true for strict mode, "nested" ignores closing brackets in a row.
"disallowSpacesInsideObjectBrackets": "all"var x = {a: {b: 1}};var x = { a: {b: 1} };var x = { a: { b: 1 } };Disallows space after opening array square bracket and before closing.
Type: Boolean or String
Values: "all" or true for strict mode, "nested" ignores closing brackets in a row.
"disallowSpacesInsideArrayBrackets": "all"var x = [[1]];var x = [ [1] ];var x = [ [ 1 ] ];Disallows space after opening round bracket and before closing.
Type: Boolean
Values: true
"disallowSpacesInsideParentheses": truevar x = (1 + 2) * 3;var x = ( 1 + 2 ) * 3;Requires space after opening object curly brace and before closing.
Type: String
Values: "all" for strict mode, "allButNested" ignores closing brackets in a row.
"requireSpacesInsideObjectBrackets": "all"var x = { a: { b: 1 } };var x = { a: { b: 1 }};var x = {a: 1};Requires space after opening array square bracket and before closing.
Type: String
Values: "all" for strict mode, "allButNested" ignores closing brackets in a row.
"requireSpacesInsideArrayBrackets": "all"var x = [ 1 ];var x = [[ 1 ], [ 2 ]];var x = [1];Requires space after opening round bracket and before closing.
Type: String
Values: "all" for strict mode, "allButNested" ignores nested brackets in a row.
"requireSpacesInsideParentheses": "all"var x = Math.pow( ( 1 + 2 ), ( 3 + 4 ) );var x = Math.pow(( 1 + 2 ), ( 3 + 4 ));var x = Math.pow(1 + 2, 3 + 4);Disallows quoted keys in object if possible.
Type: String or Boolean
Values:
truefor strict mode"allButReserved"allows ES3+ reserved words to remain quoted which is helpful when using this option with JSHint'ses3flag.
"disallowQuotedKeysInObjects": truevar x = { a: { default: 1 } };var x = {a: 1, 'default': 2};var x = {'a': 1};Disallows identifiers that start or end in _, except for some popular exceptions:
_(underscore.js)__filename(node.js global)__dirname(node.js global)
Type: Boolean
Values: true
JSHint: nomen
"disallowDanglingUnderscores": truevar x = 1;
var y = _.extend;
var z = __dirname;
var w = __filename;
var x_y = 1;var _x = 1;
var x_ = 1;
var x_y_ = 1;Disallows space after object keys.
Type: Boolean
Values: true
"disallowSpaceAfterObjectKeys": truevar x = {a: 1};var x = {a : 1};Requires space after object keys.
Type: Boolean
Values: true
"requireSpaceAfterObjectKeys": truevar x = {a : 1};var x = {a: 1};Disallows commas as last token on a line in lists.
Type: Boolean
Values: true
JSHint: laxcomma
"disallowCommaBeforeLineBreak": truevar x = {
one: 1
, two: 2
};
var y = { three: 3, four: 4};var x = {
one: 1,
two: 2
};Requires commas as last token on a line in lists.
Type: Boolean
Values: true
JSHint: laxcomma
"requireCommaBeforeLineBreak": truevar x = {
one: 1,
two: 2
};
var y = { three: 3, four: 4};var x = {
one: 1
, two: 2
};Requires proper alignment in object literals.
Type: String
Values:
"all"for strict mode,"ignoreFunction"ignores objects if one of the property values is a function expression,"ignoreLineBreak"ignores objects if there are line breaks between properties
"requireAlignedObjectValues": "all"var x = {
a : 1,
bcd : 2,
ef : 'str'
};var x = {
a : 1,
bcd : 2,
ef : 'str'
};Requires operators to appear before line breaks and not after.
Type: Array or Boolean
Values: Array of quoted operators or true to require all possible binary operators to appear before line breaks
JSHint: laxbreak
"requireOperatorBeforeLineBreak": [
"?",
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
]x = y ? 1 : 2;
x = y ?
1 : 2;x = y
? 1 : 2;Requires sticking unary operators to the right.
Type: Array or Boolean
Values: Array of quoted operators or true to disallow space after prefix for all unary operators
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"]x = !y; y = ++z;x = ! y; y = ++ z;Disallows sticking unary operators to the right.
Type: Array or Boolean
Values: Array of quoted operators or true to require space after prefix for all unary operators
"requireSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"]x = ! y; y = ++ z;x = !y; y = ++z;Requires sticking unary operators to the left.
Type: Array or Boolean
Values: Array of quoted operators or true to disallow space before postfix for all unary operators (i.e. increment/decrement operators)
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"]x = y++; y = z--;x = y ++; y = z --;Disallows sticking unary operators to the left.
Type: Array or Boolean
Values: Array of quoted operators or true to require space before postfix for all unary operators (i.e. increment/decrement operators)
"requireSpaceBeforePostfixUnaryOperators": ["++", "--"]x = y ++; y = z --;x = y++; y = z--;Requires sticking binary operators to the left.
Type: Array or Boolean
Values: Array of quoted operators or true to disallow space before all possible binary operators
"disallowSpaceBeforeBinaryOperators": [
"=",
",",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
// etc
]x+ y;x + y;Disallows sticking binary operators to the left.
Type: Array or Boolean
Values: Array of quoted operators or true to require space before all possible binary operators
without comma operator, since it's rarely used with this rule
"requireSpaceBeforeBinaryOperators": [
"=",
",",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
// etc
]x !== y;x!== y;Requires sticking binary operators to the right.
Type: Array or Boolean
Values: Array of quoted operators or true to disallow space after all possible binary operators
"disallowSpaceAfterBinaryOperators": [
"=",
",",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
// etc
]x +y;x+ y;Disallows sticking binary operators to the right.
Type: Array or Boolean
Values: Array of quoted operators or true to require space after all possible binary operators
"requireSpaceAfterBinaryOperators": [
"=",
",",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
// etc
]x + y;x +y;Disallows implicit type conversion.
Type: Array
Values: Array of quoted types
"disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"]x = Boolean(y);
x = Number(y);
x = String(y);
x = s.indexOf('.') !== -1;x = !!y;
x = +y;
x = '' + y;
x = ~s.indexOf('.');Requires identifiers to be camelCased or UPPERCASE_WITH_UNDERSCORES
Type: Boolean or String
Values: true or "ignoreProperties"
JSHint: camelcase
"requireCamelCaseOrUpperCaseIdentifiers": truevar camelCase = 0;
var CamelCase = 1;
var _camelCase = 2;
var camelCase_ = 3;
var UPPER_CASE = 4;var lower_case = 1;
var Mixed_case = 2;
var mixed_Case = 3;var camelCase = 0;
var CamelCase = 1;
var _camelCase = 2;
var camelCase_ = 3;
var UPPER_CASE = 4;
var obj.snake_case = 5;
var camelCase = { snake_case: 6 };var lower_case = 1;
var Mixed_case = 2;
var mixed_Case = 3;
var snake_case = { snake_case: 6 };Disallows usage of specified keywords.
Type: Array
Values: Array of quoted keywords
"disallowKeywords": ["with"]with (x) {
prop++;
}Disallows strings that span multiple lines without using concatenation.
Type: Boolean
Values: true
JSHint: multistr
"disallowMultipleLineStrings": truevar x = "multi" +
"line";
var y = "single line";var x = "multi \
line";Disallows multiple blank lines in a row.
Type: Boolean
Values: true
"disallowMultipleLineBreaks": truevar x = 1;
x++;var x = 1;
x++;Option to check line break characters
Type: String
Values: "CR", "LF", "CRLF"
"validateLineBreaks": "LF"var x = 1;<LF>
x++;var x = 1;<CRLF>
x++;Requires all quote marks to be either the supplied value, or consistent if true
Type: String or Object
Values:
"\"": all strings require double quotes"'": all strings require single quotestrue: all strings require the quote mark first encountered in the source codeObject:escape: allow the "other" quote mark to be used, but only to avoid having to escapemark: the same effect as the non-object values
JSHint: quotmark
"validateQuoteMarks": "\"""validateQuoteMarks": { "mark": "\"", "escape": true }var x = "x";
var y = '"x"';var x = "x";
var y = 'x';var x = "x";var x = 'x';var x = "x", y = 'y';Validates indentation for arrays, objects, switch statements, and block statements
Type: Integer or String
Values: A positive integer or "\t"
JSHint: indent
"validateIndentation": "\t"if (a) {
b=c;
function(d) {
e=f;
}
}if (a) {
b=c;
function(d) {
e=f;
}
}if (a) {
b=c;
function(d) {
e=f;
}
}if (a) {
b=c;
function(d) {
e=f;
}
}Requires lines to not contain both spaces and tabs consecutively, or spaces after tabs only for alignment if "smart"
Type: Boolean or String
Values: true or "smart"
JSHint: smarttabs
"disallowMixedSpacesAndTabs": true\tvar foo = "blah blah";
\s\s\s\svar foo = "blah blah";
\t/**
\t\s*
\t\s*/ //a single space to align the star in a multi-line comment is allowed\t\svar foo = "blah blah";
\s\tsvar foo = "blah blah";\tvar foo = "blah blah";
\t\svar foo = "blah blah";
\s\s\s\svar foo = "blah blah";
\t/**
\t\s*
\t\s*/ //a single space to align the star in a multi-line comment is allowed\s\tsvar foo = "blah blah";Requires all lines to end on a non-whitespace character
Type: Boolean
Values: true
JSHint: trailing
"disallowTrailingWhitespace": truevar foo = "blah blah";var foo = "blah blah"; //<-- whitespace character hereDisallows an extra comma following the final element of an array or object literal.
Type: Boolean
Values: true
JSHint: es3
"disallowTrailingComma": truevar foo = [1, 2, 3];
var bar = {a: "a", b: "b"}var foo = [1, 2, 3, ];
var bar = {a: "a", b: "b", }Requires an extra comma following the final element of an array or object literal.
Type: Boolean or Object
Values:
true: validates all arrays and objectsObject:ignoreSingleValue: allows single property objects and single element arrays to not require a trailing comma
"requireTrailingComma": truevar foo = [1, 2, 3,];
var bar = {a: "a", b: "b",}var car = [1];
var dar = {a: "a"};var foo = [1, 2, 3];
var bar = {a: "a", b: "b"}Disallows placing keywords on a new line.
Type: Array
Values: Array of quoted keywords
"disallowKeywordsOnNewLine": ["else"]if (x < 0) {
x++;
} else {
x--;
}if (x < 0) {
x++;
}
else {
x--;
}Requires placing keywords on a new line.
Type: Array
Values: Array of quoted keywords
"requireKeywordsOnNewLine": ["else"]if (x < 0) {
x++;
}
else {
x--;
}if (x < 0) {
x++;
} else {
x--;
}Requires placing line feed at file end.
Type: Boolean
Values: true
"requireLineFeedAtFileEnd": trueRequires all lines to be at most the number of characters specified
Type: Integer or Object
Values:
Integer: lines should be at most the number of characters specifiedObject:value: (required) lines should be at most the number of characters specifiedtabSize: (default:1) considered the tab character as number of specified spacesallowComments: (default:false) allows comments to break the ruleallowUrlComments: (default:false) allows comments with long urls to break the ruleallowRegex: (default:false) allows regular expression literals to break the rule
JSHint: maxlen
"maximumLineLength": 40var aLineOf40Chars = 123456789012345678;var aLineOf41Chars = 1234567890123456789;Requires constructors to be capitalized (except for this)
Type: Boolean
Values: true
JSHint: newcap
"requireCapitalizedConstructors": truevar a = new B();
var c = new this();var d = new e();Option to check var that = this expressions
Type: Array or String
Values: String value used for context local declaration
"safeContextKeyword": ["that"]var that = this;var _this = this;Requires member expressions to use dot notation when possible
Type: Boolean
Values: true
JSHint: sub
"requireDotNotation": truevar a = b[c];
var a = b.c;
var a = b[c.d];
var a = b[1];
var a = b['while']; //reserved wordvar a = b['c'];Requires the variable to be the right hand operator when doing a boolean comparison
Type: Boolean
Values: true
"requireYodaConditions": trueif (1 == a) {
return
}if (a == 1) {
return
}Requires the variable to be the left hand operator when doing a boolean comparison
Type: Boolean
Values: true
"disallowYodaConditions": trueif (a == 1) {
return
}if (1 == a) {
return
}Enables JSDoc validation.
Type: Object
Values:
- "checkParamNames" ensures param names in jsdoc and in function declaration are equal
- "requireParamTypes" ensures params in jsdoc contains type
- "checkRedundantParams" reports redundant params in jsdoc
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}/**
* Adds style error to the list
*
* @param {String} message
* @param {Number|Object} line
* @param {Number} [column]
*/
add: function(message, line, column) {
}/**
* Adds style error to the list
*
* @param {String} message
* @param {Number|Object} line
* @param {Number} [column]
*/
add: function() {
}Requires that a line comment (//) be followed by a space.
Type: Boolean
Values: true
"requireSpaceAfterLineComment": true// A comment
/*A comment*///A commentRequires that a line comment (//) not be followed by a space.
Type: Boolean
Values: true
"disallowSpaceAfterLineComment": true//A comment
/* A comment*/// A commentRequires that a function expression be named.
Type: Boolean
Values: true
"disallowAnonymousFunctions": truevar a = function foo(){
};
$('#foo').click(function bar(){
};)var a = function(){
};
$('#foo').click(function(){
};)Requires that a function expression be anonymous.
Type: Boolean
Values: true
"requireAnonymousFunctions": truevar a = function(){
};
$('#foo').click(function(){
};)var a = function foo(){
};
$('#foo').click(function bar(){
};)Disallows newline before opening curly brace of all block statements.
Type: Boolean
Values: true
"disallowNewlineBeforeBlockStatements": truefunction good(){
var obj = {
val: true
};
return {
data: obj
};
}
if (cond){
foo();
}
for (var e in elements){
bar(e);
}
while (cond){
foo();
}function bad()
{
var obj =
{
val: true
};
return {
data: obj
};
}
if (cond)
{
foo();
}
for (var e in elements)
{
bar(e);
}
while (cond)
{
foo();
}Requires newline before opening curly brace of all block statements.
Type: Boolean
Values: true
"requireNewlineBeforeBlockStatements": truefunction good()
{
var obj =
{
val: true
};
return {
data: obj
};
}
if (cond)
{
foo();
}
for (var e in elements)
{
bar(e);
}
while (cond)
{
foo();
}function bad(){
var obj = {
val: true
};
return {
data: obj
};
}
if (cond){
foo();
}
for (var e in elements){
bar(e);
}
while (cond){
foo();
}Use the following rules instead:
- requireSpaceBeforeBinaryOperators
- requireSpaceBeforePostfixUnaryOperators
- requireSpacesInConditionalExpression
Use the following rules instead:
- requireSpaceAfterBinaryOperators
- requireSpaceAfterPrefixUnaryOperators
- requireSpacesInConditionalExpression
Use the following rules instead:
- disallowSpaceBeforeBinaryOperators
- disallowSpaceBeforePostfixUnaryOperators
- disallowSpacesInConditionalExpression
Use the following rules instead:
- disallowSpaceAfterBinaryOperators
- disallowSpaceAfterPrefixUnaryOperators
- disallowSpacesInConditionalExpression
The npm package contains a file named jscs-browser.js (since version 1.5.7), which is a browser compatible version of jscs.
If you'd like to generate this file yourself, run npm run browserify after cloning this repo.
Use jscs-browser.js on your page as follows:
<script src="jscs-browser.js"></script>
<script>
var checker = new JscsStringChecker();
checker.registerDefaultRules();
checker.configure({disallowMultipleVarDecl: true});
var errors = checker.checkString('var x, y = 1;');
errors.getErrorList().forEach(function(error) {
console.log(errors.explainError(error));
});
</script>