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.
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
CLI
--config
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.
--preset
If defined will use predefined rules for specific code style.
jscs path[ path[...]] --preset=jquery
--reporter
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.
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.
Example
"fileExtensions": [".js", ".jsx"]
Default
"fileExtensions": [".js"]
Error Suppression
Disabling Rules From Presets
After using the preset option, you can set any rules values to null to remove it. i.e. The following config will use the jQuery preset except will
not require the use of a.b over a['b'].:
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:
You can use them to disable rules in several ways.
Disabling All Rules
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 reported
Disabling Specific Rules
Including 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 reported
You 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 reported
You 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 reported
var 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));
Invalid
var a = function(){ return 1; }();
var c = function(){ return 3; }.call(this, arg1);
var d = function(){ return d; }.apply(this, args);
requireSpacesInConditionalExpression
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.
var a = b? c : d;
var a = b ?c : d;
var a = b ? c: d;
var a = b ? c :d;
disallowSpacesInConditionalExpression
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.
Disallows multiple var declaration (except for-loop).
Type: Boolean
Values: true
Example
"disallowMultipleVarDecl": true
Valid
var x = 1;
var y = 2;
for (var i = 0, j = arr.length; i < j; i++) {}
Invalid
var x = 1,
y = 2;
requireMultipleVarDecl
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.
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
var camelCase = 0;
var CamelCase = 1;
var _camelCase = 2;
var camelCase_ = 3;
var UPPER_CASE = 4;
Invalid for mode true
var lower_case = 1;
var Mixed_case = 2;
var mixed_Case = 3;
Valid for mode ignoreProperties
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 };
Invalid for mode ignoreProperties
var lower_case = 1;
var Mixed_case = 2;
var mixed_Case = 3;
var snake_case = { snake_case: 6 };
disallowKeywords
Disallows usage of specified keywords.
Type: Array
Values: Array of quoted keywords
Example
"disallowKeywords": ["with"]
Invalid
with (x) {
prop++;
}
disallowMultipleLineStrings
Disallows strings that span multiple lines without using concatenation.
\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
Invalid example for mode "smart"
\s\tsvar foo = "blah blah";
disallowTrailingWhitespace
Requires all lines to end on a non-whitespace character
node-jscs

JSCS — JavaScript Code Style.
jscsis a code style checker. You can configurejscsfor 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
Presets
Friendly packages
Extensions
Installation
jscscan be installed usingnpm:To run
jscs, you can use the following command from the project root:You can also pipe input into jscs:
CLI
--configAllows to define path to the config file.
If there is no
--configoption specified,jscsit will consequentially search forjscsConfigoption inpackage.jsonfile then for.jscsrcand.jscs.jsonfiles in the current working directory then in nearest ancestor until it hits the system root.--presetIf defined will use predefined rules for specific code style.
--reporterjscsitself provides six reporters:checkstyle,console,inline,junitandtext.But you also can specify your own reporter, since this flag accepts relative or absolute paths too.
--no-colorsWill be removed. Clean output without colors.
--helpOutputs usage information.
--verbosePrepends the name of the offending rule to all error messages.
--versionOutputs version of
jscs.Options
additionalRules
Path to load additional rules
Type:
ArrayValues: Array of file matching patterns
Example
preset
Extends defined rules with preset rules.
Type:
StringValues:
"crockford","google","jquery","mdcs","wikimedia","yandex"Example
If you want specifically disable preset rule assign it to
null, like so:excludeFiles
Disables style checking for specified paths.
Type:
ArrayValues: Array of file matching patterns
Example
fileExtensions
Changes the set of file extensions that will be processed.
Type:
ArrayorStringor"*"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.Example
Default
Error Suppression
Disabling Rules From Presets
After using the
presetoption, you can set any rules values tonullto remove it. i.e. The following config will use the jQuery preset except will not require the use ofa.bovera['b'].:Inline Comments
You can disable and reenable rules inline with two special comments:
//jscs:disableand//jscs:enable. Spacing in these comments is fairly lenient. All of the following are equivalent:You can use them to disable rules in several ways.
Disabling All Rules
Simply using
//jscs:disableor//jscs:enablewill disable all rules.Disabling Specific Rules
Including a comma separated list of rules to modify after
//jscs:disableor//jscs:enablewill modify only those rules.You can enable all rules after disabling a specific rule, and that rule becomes reenabled as well.
You can disable multiple rules at once and progressively reeanble them.
Rules
requireCurlyBraces
Requires curly braces after statements.
Type:
ArrayValues: Array of quoted keywords
JSHint:
curlyExample
Valid
Invalid
requireSpaceAfterKeywords
Requires space after keyword.
Type:
ArrayValues: Array of quoted keywords
Example
Valid
Invalid
disallowSpaceAfterKeywords
Disallows space after keyword.
Type:
ArrayValues: Array of quoted keywords
Example
Valid
requireSpaceBeforeBlockStatements
Requires space before block statements (for loops, control structures).
Type:
BooleanValues:
trueExample
Valid
Invalid
disallowSpaceBeforeBlockStatements
Disallows space before block statements (for loops, control structures).
Type:
BooleanValues:
trueExample
Valid
Invalid
requireParenthesesAroundIIFE
Requires parentheses around immediately invoked function expressions.
Type:
BooleanValues:
trueJSHint:
immedExample
Valid
Invalid
requireSpacesInConditionalExpression
Requires space before and/or after
?or:in conditional expressions.Type:
ObjectorBooleanValues:
"afterTest","beforeConsequent","afterConsequent","beforeAlternate"as child properties, ortrueto set all properties totrue. Child properties must be set totrue.Example
Valid
Invalid
disallowSpacesInConditionalExpression
Disallows space before and/or after
?or:in conditional expressions.Type:
ObjectorBooleanValues:
"afterTest","beforeConsequent","afterConsequent","beforeAlternate"as child properties, ortrueto set all properties to true. Child properties must be set totrue.Example
Valid
Invalid
requireSpacesInFunctionExpression
Requires space before
()or{}in function expressions (both named and anonymous).Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
disallowSpacesInFunctionExpression
Disallows space before
()or{}in function expressions (both named and anonymous).Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
requireSpacesInAnonymousFunctionExpression
Requires space before
()or{}in anonymous function expressions.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
disallowSpacesInAnonymousFunctionExpression
Disallows space before
()or{}in anonymous function expressions.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
requireSpacesInNamedFunctionExpression
Requires space before
()or{}in named function expressions.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
disallowSpacesInNamedFunctionExpression
Disallows space before
()or{}in named function expressions.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
requireSpacesInFunctionDeclaration
Requires space before
()or{}in function declarations.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
disallowSpacesInFunctionDeclaration
Disallows space before
()or{}in function declarations.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
requireSpacesInFunction
Requires space before
()or{}in function declarations and expressions.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
disallowSpacesInFunction
Disallows space before
()or{}in function declarations and expressions.Type:
ObjectValues:
"beforeOpeningRoundBrace"and"beforeOpeningCurlyBrace"as child properties. Child properties must be set totrue.Example
Valid
Invalid
disallowMultipleVarDecl
Disallows multiple
vardeclaration (except for-loop).Type:
BooleanValues:
trueExample
Valid
Invalid
requireMultipleVarDecl
Requires multiple
vardeclaration.Type:
BooleanorStringValues:
trueor"onevar"if
requireMultipleVarDecldefined as atruevalue, it will report only consecutive vars, if, on the other hand, value equals to"onevar"string,requireMultipleVarDeclwill allow only onevarper function scope.JSHint:
onevarExample
Valid
Invalid
requireBlocksOnNewline
Requires blocks to begin and end with a newline
Type:
BooleanorIntegerValues:
truevalidates all non-empty blocks,Integerspecifies a minimum number of statements in the block before validating.Example
Valid for mode
trueInvalid
Valid for mode
1Invalid
requirePaddingNewlinesInBlocks
Requires blocks to begin and end with 2 newlines
Type:
BooleanorIntegerValues:
truevalidates all non-empty blocks,Integerspecifies a minimum number of statements in the block before validating.Example
Valid for mode
trueInvalid
Valid for mode
1Invalid
disallowPaddingNewlinesInBlocks
Disallows blocks from beginning and ending with 2 newlines.
Type:
BooleanValues:
truevalidates all non-empty blocks.Example
Valid
Invalid
disallowEmptyBlocks
Disallows empty blocks (except for catch blocks).
Type:
BooleanValues:
trueJSHint:
noemptyExample
Valid
Invalid
disallowSpacesInsideObjectBrackets
Disallows space after opening object curly brace and before closing.
Type:
BooleanorStringValues:
"all"ortruefor strict mode,"nested"ignores closing brackets in a row.Example
Valid for mode
"all"Valid for mode
"nested"Invalid
disallowSpacesInsideArrayBrackets
Disallows space after opening array square bracket and before closing.
Type:
BooleanorStringValues:
"all"ortruefor strict mode,"nested"ignores closing brackets in a row.Example
Valid for mode
"all"Valid for mode
"nested"Invalid
disallowSpacesInsideParentheses
Disallows space after opening round bracket and before closing.
Type:
BooleanValues:
trueExample
Valid
Invalid
requireSpacesInsideObjectBrackets
Requires space after opening object curly brace and before closing.
Type:
StringValues:
"all"for strict mode,"allButNested"ignores closing brackets in a row.Example
Valid for mode
"all"Valid for mode
"allButNested"Invalid
requireSpacesInsideArrayBrackets
Requires space after opening array square bracket and before closing.
Type:
StringValues:
"all"for strict mode,"allButNested"ignores closing brackets in a row.Example
Valid for mode
"all"Valid for mode
"allButNested"Invalid
requireSpacesInsideParentheses
Requires space after opening round bracket and before closing.
Type:
StringValues:
"all"for strict mode,"allButNested"ignores nested brackets in a row.Example
Valid for mode
"all"Valid for mode
"allButNested"Invalid
disallowQuotedKeysInObjects
Disallows quoted keys in object if possible.
Type:
StringorBooleanValues:
truefor strict mode"allButReserved"allows ES3+ reserved words to remain quoted which is helpful when using this option with JSHint’ses3flag.Example
Valid for mode
trueValid for mode
"allButReserved"Invalid
disallowDanglingUnderscores
Disallows identifiers that start or end in
_, except for some popular exceptions:_(underscore.js)__filename(node.js global)__dirname(node.js global)Type:
BooleanValues:
trueJSHint:
nomenExample
Valid
Invalid
disallowSpaceAfterObjectKeys
Disallows space after object keys.
Type:
BooleanValues:
trueExample
Valid
Invalid
requireSpaceAfterObjectKeys
Requires space after object keys.
Type:
BooleanValues:
trueExample
Valid
Invalid
disallowCommaBeforeLineBreak
Disallows commas as last token on a line in lists.
Type:
BooleanValues:
trueJSHint:
laxcommaExample
Valid
Invalid
requireCommaBeforeLineBreak
Requires commas as last token on a line in lists.
Type:
BooleanValues:
trueJSHint:
laxcommaExample
Valid
Invalid
requireAlignedObjectValues
Requires proper alignment in object literals.
Type:
StringValues:
"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 propertiesExample
Valid
Invalid
requireOperatorBeforeLineBreak
Requires operators to appear before line breaks and not after.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto require all possible binary operators to appear before line breaksJSHint:
laxbreakExample
Valid
Invalid
disallowSpaceAfterPrefixUnaryOperators
Requires sticking unary operators to the right.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto disallow space after prefix for all unary operatorsExample
Valid
Invalid
requireSpaceAfterPrefixUnaryOperators
Disallows sticking unary operators to the right.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto require space after prefix for all unary operatorsExample
Valid
Invalid
disallowSpaceBeforePostfixUnaryOperators
Requires sticking unary operators to the left.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto disallow space before postfix for all unary operators (i.e. increment/decrement operators)Example
Valid
Invalid
requireSpaceBeforePostfixUnaryOperators
Disallows sticking unary operators to the left.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto require space before postfix for all unary operators (i.e. increment/decrement operators)Example
Valid
Invalid
disallowSpaceBeforeBinaryOperators
Requires sticking binary operators to the left.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto disallow space before all possible binary operatorsExample
Valid
Invalid
requireSpaceBeforeBinaryOperators
Disallows sticking binary operators to the left.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto require space before all possible binary operators without comma operator, since it’s rarely used with this ruleExample
Valid
Invalid
disallowSpaceAfterBinaryOperators
Requires sticking binary operators to the right.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto disallow space after all possible binary operatorsExample
Valid
Invalid
requireSpaceAfterBinaryOperators
Disallows sticking binary operators to the right.
Type:
ArrayorBooleanValues: Array of quoted operators or
trueto require space after all possible binary operatorsExample
Valid
Invalid
disallowImplicitTypeConversion
Disallows implicit type conversion.
Type:
ArrayValues: Array of quoted types
Example
Valid
Invalid
requireCamelCaseOrUpperCaseIdentifiers
Requires identifiers to be camelCased or UPPERCASE_WITH_UNDERSCORES
Type:
BooleanorStringValues:
trueor"ignoreProperties"JSHint:
camelcaseExample
Valid for mode
trueInvalid for mode
trueValid for mode
ignorePropertiesInvalid for mode
ignorePropertiesdisallowKeywords
Disallows usage of specified keywords.
Type:
ArrayValues: Array of quoted keywords
Example
Invalid
disallowMultipleLineStrings
Disallows strings that span multiple lines without using concatenation.
Type:
BooleanValues:
trueJSHint:
multistrExample
Valid
Invalid
disallowMultipleLineBreaks
Disallows multiple blank lines in a row.
Type:
BooleanValues:
trueExample
Valid
Invalid
validateLineBreaks
Option to check line break characters
Type:
StringValues:
"CR","LF","CRLF"Example
Valid
Invalid
validateQuoteMarks
Requires all quote marks to be either the supplied value, or consistent if
trueType:
StringorObjectValues:
"\"": 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 valuesJSHint:
quotmarkExample
Valid example for mode
{ "mark": "\"", "escape": true }Invalid example for mode
{ "mark": "\"", "escape": true }Valid example for mode
"\""or modetrueValid example for mode
"'"or modetrueInvalid example for mode
truevalidateIndentation
Validates indentation for arrays, objects, switch statements, and block statements
Type:
IntegerorStringValues: A positive integer or
"\t"JSHint:
indentExample
Valid example for mode
2Invalid example for mode
2Valid example for mode “\t”
Invalid example for mode “\t”
disallowMixedSpacesAndTabs
Requires lines to not contain both spaces and tabs consecutively, or spaces after tabs only for alignment if “smart”
Type:
BooleanorStringValues:
trueor"smart"JSHint:
smarttabsExample
Valid example for mode
trueInvalid example for mode
trueValid example for mode
"smart"Invalid example for mode
"smart"disallowTrailingWhitespace
Requires all lines to end on a non-whitespace character
Type:
BooleanValues:
trueJSHint:
trailingExample
Valid
Invalid
disallowTrailingComma
Disallows an extra comma following the final element of an array or object literal.
Type:
BooleanValues:
trueJSHint:
es3Example
Valid
Invalid
requireTrailingComma
Requires an extra comma following the final element of an array or object literal.
Type:
BooleanorObjectValues:
true: validates all arrays and objectsObject:ignoreSingleValue: allows single property objects and single element arrays to not require a trailing commaExample
Valid
Valid with ignoreSingleValue
Invalid
disallowKeywordsOnNewLine
Disallows placing keywords on a new line.
Type:
ArrayValues: Array of quoted keywords
Example
Valid
Invalid
requireKeywordsOnNewLine
Requires placing keywords on a new line.
Type:
ArrayValues: Array of quoted keywords
Example
Valid
Invalid
requireLineFeedAtFileEnd
Requires placing line feed at file end.
Type:
BooleanValues:
trueExample
maximumLineLength
Requires all lines to be at most the number of characters specified
Type:
IntegerorObjectValues:
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 ruleJSHint:
maxlenExample
Valid
Invalid
requireCapitalizedConstructors
Requires constructors to be capitalized (except for
this)Type:
BooleanValues:
trueJSHint:
newcapExample
Valid
Invalid
safeContextKeyword
Option to check
var that = thisexpressionsType:
ArrayorStringValues: String value used for context local declaration
Example
Valid
Invalid
requireDotNotation
Requires member expressions to use dot notation when possible
Type:
BooleanValues:
trueJSHint:
subExample
Valid
Invalid
requireYodaConditions
Requires the variable to be the right hand operator when doing a boolean comparison
Type:
BooleanValues:
trueExample
Valid
Invalid
disallowYodaConditions
Requires the variable to be the left hand operator when doing a boolean comparison
Type:
BooleanValues:
trueExample
Valid
Invalid
validateJSDoc
Enables JSDoc validation.
Type:
ObjectValues:
Example
Valid
Invalid
requireSpaceAfterLineComment
Requires that a line comment (
//) be followed by a space.Type:
BooleanValues:
trueExample
Valid
Invalid
disallowSpaceAfterLineComment
Requires that a line comment (
//) not be followed by a space.Type:
BooleanValues:
trueExample
Valid
Invalid
disallowAnonymousFunctions
Requires that a function expression be named.
Type:
BooleanValues:
trueExample
Valid
Invalid
requireAnonymousFunctions
Requires that a function expression be anonymous.
Type:
BooleanValues:
trueExample
Valid
Invalid
disallowNewlineBeforeBlockStatements
Disallows newline before opening curly brace of all block statements.
Type:
BooleanValues:
trueExample
Valid
Invalid
requireNewlineBeforeBlockStatements
Requires newline before opening curly brace of all block statements.
Type:
BooleanValues:
trueExample
Valid
Invalid
Removed Rules
disallowLeftStickedOperatorsUse the following rules instead:
disallowRightStickedOperatorsUse the following rules instead:
requireLeftStickedOperatorsUse the following rules instead:
requireRightStickedOperatorsUse the following rules instead:
Browser Usage
The npm package contains a file named
jscs-browser.js(since version1.5.7), which is a browser compatible version ofjscs.If you’d like to generate this file yourself, run
npm run browserifyafter cloning this repo.Use
jscs-browser.json your page as follows: