node-jscs
JSCS — JavaScript Code Style.
jscs
is a code style checker. jscs
can check cases, which are not implemeted in jshint,
but it does not duplicate jshint
functionality, so you should use jscs
and jshint
together.
Installation
jscs
can be installed using npm
:
npm install jscs
To run jscs
, you can use the following command from the project root:
./node_modules/.bin/jscs path[ path[...]]
Configuration
jscs
is configured using .jscs.json
file, located in the project root.
Example configuration:
{
/*
Option: require_curly_braces
Requires curly braces after statements.
Valid example:
if (x) {
x++;
}
Invalid example:
if (x) x++;
*/
"require_curly_braces": ["if", "else", "for", "while", "do"],
/*
Option: require_space_after_keywords
Requires space after keyword.
Valid example:
return true;
Invalid example:
if(x) {
x++;
}
*/
"require_space_after_keywords": ["if", "else", "for", "while", "do", "switch", "return"],
/*
Option: disallow_space_after_keywords
Disallows space after keyword.
Valid example:
if(x > y) {
y++;
}
*/
"disallow_space_after_keywords": ["if", "else", "for", "while", "do", "switch"],
/*
Option: disallow_multiple_var_decl
Disallows multiple var declaration.
Valid example:
var x = 1;
var y = 2;
Invalid example:
var x = 1,
y = 2;
*/
"disallow_multiple_var_decl": true,
/*
Option: disallow_left_sticked_operators
Disallows sticking operators to the left.
Valid example:
x = y ? 1 : 2;
Invalid example:
x = y? 1 : 2;
*/
"disallow_left_sticked_operators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
/*
Option: require_right_sticked_operators
Requires sticking operators to the left.
Valid example:
x = !y;
Invalid example:
x = ! y;
*/
"require_right_sticked_operators": ["!"],
/*
Option: disallow_right_sticked_operators
Disallows sticking operators to the right.
Valid example:
x = y + 1;
Invalid example:
x = y +1;
*/
"disallow_right_sticked_operators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
/*
Option: disallow_right_sticked_operators
Requires sticking operators to the right.
Valid example:
x = [1, 2];
Invalid example:
x = [1,2];
*/
"require_left_sticked_operators": [","],
/*
Option: disallow_implicit_type_conversion
Disallows implicit type conversion.
Valid example:
x = Boolean(y);
x = Number(y);
x = String(y);
x = ~s.indexOf('.');
Invalid example:
x = !!y;
x = +y;
x = '' + y;
x = s.indexOf('.') !== -1;
*/
"disallow_implicit_type_conversion": ["numeric", "boolean", "binary", "string"],
/*
Option: disallow_keywords
Disallows usage of specified keywords.
Invalid example:
with (x) {
prop++;
}
*/
"disallow_keywords": ["with"],
/*
Option: disallow_muliple_line_breaks
Disallows multiple blank lines in a row.
Invalid example:
var x = 1;
x++;
*/
"disallow_muliple_line_breaks": true,
/*
Option: disallow_keywords_on_new_line
Disallows placing keywords on a new line.
Valid example:
if (x < 0) {
x++;
} else {
x--;
}
Invalid example:
if (x < 0) {
x++;
}
else {
x--;
}
*/
"disallow_keywords_on_new_line": ["else"],
/*
Option: require_keywords_on_new_line
Requires placing keywords on a new line.
Valid example:
if (x < 0) {
x++;
}
else {
x--;
}
Invalid example:
if (x < 0) {
x++;
} else {
x--;
}
*/
"require_keywords_on_new_line": ["else"],
/*
Option: require_line_feed_at_file_end
Requires placing line feed at file end.
*/
"require_line_feed_at_file_end": true,
/*
Option: validate_jsdoc
Enables jsdoc validation.
Option: validate_jsdoc.check_param_names
Ensures param names in jsdoc and in function declaration are equal.
Option: validate_jsdoc.require_param_types
Ensures params in jsdoc contains type.
Option: validate_jsdoc.check_redundant_params
Reports redundant params in jsdoc.
*/
"validate_jsdoc": {
"check_param_names": true,
"check_redundant_params": true,
"require_param_types": true
}
}