Socket
Socket
Sign inDemoInstall

jscs

Package Overview
Dependencies
Maintainers
4
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jscs - npm Package Compare versions

Comparing version 1.6.2 to 1.7.0

lib/options/max-errors.js

2

lib/checker.js

@@ -14,3 +14,3 @@ var vowFs = require('vow-fs');

*
* @name StringChecker
* @name Checker
*/

@@ -17,0 +17,0 @@ var Checker = function() {

@@ -26,3 +26,6 @@ /**

var promise = defer.promise();
var checker = new Checker(program.verbose);
var checker = new Checker({
verbose: program.verbose,
esnext: program.esnext
});
var args = program.args;

@@ -86,2 +89,6 @@ var returnArgs = {

if (program.maxErrors) {
config.maxErrors = Number(program.maxErrors);
}
if (program.reporter) {

@@ -122,2 +129,3 @@ reporterPath = path.resolve(process.cwd(), program.reporter);

reporter([errors]);
handleMaxErrors();

@@ -140,2 +148,3 @@ if (!errors.isEmpty()) {

reporter(errorsCollection);
handleMaxErrors();

@@ -156,2 +165,8 @@ errorsCollection.forEach(function(errors) {

return returnArgs;
function handleMaxErrors() {
if (checker.maxErrorsExceeded()) {
console.log('Too many errors... Increase `maxErrors` configuration option value to see more.');
}
}
};

@@ -80,2 +80,11 @@ var colors = require('colors');

/**
* Strips error list to the specified length.
*
* @param {Number} length
*/
stripErrorList: function(length) {
this._errorList.splice(length);
},
/**
* Formats error for further output.

@@ -82,0 +91,0 @@ *

@@ -198,3 +198,6 @@ var treeIterator = require('./tree-iterator');

var prevToken = this.getPrevToken(token);
while (prevToken && prevToken.type !== type && (value === undefined ? true : prevToken.value !== value)) {
while (prevToken) {
if (prevToken.type === type && (value === undefined || prevToken.value === value)) {
return prevToken;
}
prevToken = this.getPrevToken(prevToken);

@@ -214,3 +217,6 @@ }

var nextToken = this.getNextToken(token);
while (nextToken && nextToken.type !== type && (value === undefined ? true : nextToken.value !== value)) {
while (nextToken) {
if (nextToken.type === type && (value === undefined || nextToken.value === value)) {
return nextToken;
}
nextToken = this.getNextToken(nextToken);

@@ -231,2 +237,24 @@ }

/**
* Returns node by its range position
*
* @returns {Object}
*/
getNodeByRange: function(number) {
var result = {};
this.iterate(function(node) {
if (node && node.range) {
if (number > node.range[0] && number < node.range[1]) {
result = node;
}
if (number < node.range[0]) {
return false;
}
}
});
return result;
},
/**
* Returns nodes by type(s) from earlier built index.

@@ -296,3 +324,3 @@ *

this.getTokens().forEach(function(token, index, tokens) {
if (nameIndex[token.value]) {
if (nameIndex.hasOwnProperty(token.value)) {
cb(token, index, tokens);

@@ -299,0 +327,0 @@ }

@@ -54,3 +54,3 @@ var presets = {

for (var rule in preset) {
if (!(rule in config)) {
if (preset.hasOwnProperty(rule) && !(rule in config)) {
config[rule] = preset[rule];

@@ -57,0 +57,0 @@ }

@@ -9,9 +9,7 @@ var assert = require('assert');

assert(
typeof disallowMultipleVarDecl === 'boolean',
'disallowMultipleVarDecl option requires boolean value'
disallowMultipleVarDecl === true || disallowMultipleVarDecl === 'strict',
'disallowMultipleVarDecl option requires true or "strict" value'
);
assert(
disallowMultipleVarDecl === true,
'disallowMultipleVarDecl option requires true value or should be removed'
);
this.strictMode = disallowMultipleVarDecl === 'strict';
},

@@ -24,6 +22,8 @@

check: function(file, errors) {
var inStrictMode = this.strictMode;
file.iterateNodesByType('VariableDeclaration', function(node) {
// allow multiple var declarations in for statement
// allow multiple var declarations in for statement unless we're in strict mode
// for (var i = 0, j = myArray.length; i < j; i++) {}
if (node.declarations.length > 1 && node.parentNode.type !== 'ForStatement') {
if (node.declarations.length > 1 && (inStrictMode || node.parentNode.type !== 'ForStatement')) {
errors.add('Multiple var declaration', node.loc.start);

@@ -30,0 +30,0 @@ }

var assert = require('assert');
var tokenHelper = require('../token-helper');

@@ -23,9 +24,18 @@ module.exports = function() {};

check: function(file, errors) {
var tokens = file.getTokens();
file.iterateNodesByType('ObjectExpression', function(node) {
node.properties.forEach(function(property) {
var value = property.value;
var valuePos = file.getTokenPosByRangeStart(value.range[0]);
var colon = tokens[valuePos - 1];
if (colon.range[1] !== value.range[0]) {
var keyToken = file.getTokenByRangeStart(property.key.range[0]);
var valueToken = file.getTokenByRangeStart(property.value.range[0]);
var colon = file.findNextToken(keyToken, 'Punctuator', ':');
var tokenBeforeValue = file.getPrevToken(valueToken);
var tokenToTest;
if (tokenHelper.isTokenParenthesis(file, tokenBeforeValue.range[0], true)) {
// skip '(' if value is parenthesised
tokenToTest = tokenBeforeValue;
} else {
tokenToTest = valueToken;
}
if (colon.range[1] !== tokenToTest.range[0]) {
errors.add('Illegal space after key colon', colon.loc.end);

@@ -32,0 +42,0 @@ }

@@ -7,11 +7,27 @@ var assert = require('assert');

configure: function(disallowSpacesInsideParentheses) {
assert(
typeof disallowSpacesInsideParentheses === 'boolean',
'disallowSpacesInsideParentheses option requires boolean value'
);
assert(
disallowSpacesInsideParentheses === true,
'disallowSpacesInsideParentheses option requires true value or should be removed'
);
configure: function(option) {
var isObject = typeof option === 'object';
var error = 'disallowSpacesInsideParentheses option requires' +
' true or object value with "all" or "only" properties ';
if (typeof option === 'boolean') {
assert(option === true, error);
} else if (isObject) {
assert(!('all' in option && 'only' in option), error);
assert('all' in option || 'only' in option, error);
} else {
assert(false, error);
}
if (option.only) {
this._only = {};
(option.only || []).forEach(function(value) {
this._only[value] = true;
}, this);
} else {
this._only = null;
}
},

@@ -24,2 +40,4 @@

check: function(file, errors) {
var only = this._only;
function isCommentInRange(start, end) {

@@ -30,20 +48,42 @@ return file.getComments().some(function(comment) {

}
file.iterateTokensByType('Punctuator', function(token, index, tokens) {
if (token.value === '(') {
var nextToken = tokens[index + 1];
if (token.range[1] !== nextToken.range[0] &&
token.loc.end.line === nextToken.loc.start.line &&
!isCommentInRange(token.range[1], nextToken.range[0])) {
errors.add('Illegal space after opening round bracket', token.loc.end);
}
file.iterateTokenByValue('(', function(token, index, tokens) {
var nextToken = file.getNextToken(token);
var value = nextToken.value;
var type = nextToken.type;
if (only && !(value in only)) {
return;
}
if (token.value === ')') {
var prevToken = tokens[index - 1];
if (prevToken.range[1] !== token.range[0] &&
prevToken.loc.end.line === token.loc.start.line &&
!isCommentInRange(prevToken.range[1], token.range[0])) {
errors.add('Illegal space before closing round bracket', prevToken.loc.end);
if (token.range[1] !== nextToken.range[0] &&
token.loc.end.line === nextToken.loc.start.line &&
!isCommentInRange(token.range[1], nextToken.range[0])) {
errors.add('Illegal space after opening round bracket', token.loc.end);
}
});
file.iterateTokenByValue(')', function(token, index, tokens) {
var prevToken = file.getPrevToken(token);
var value = prevToken.value;
var type = prevToken.type;
if (only) {
if (!(value in only)) {
return;
}
if (
value === ']' &&
file.getNodeByRange(prevToken.range[0]).type === 'MemberExpression'
) {
return;
}
}
if (prevToken.range[1] !== token.range[0] &&
prevToken.loc.end.line === token.loc.start.line &&
!isCommentInRange(prevToken.range[1], token.range[0])) {
errors.add('Illegal space before closing round bracket', prevToken.loc.end);
}
});

@@ -50,0 +90,0 @@ }

@@ -47,2 +47,3 @@ var assert = require('assert');

var typeIndex = this._typeIndex;
if (typeIndex['if'] || typeIndex['else']) {

@@ -61,2 +62,3 @@ file.iterateNodesByType('IfStatement', function(node) {

}
if (typeIndex['case'] || typeIndex['default']) {

@@ -82,5 +84,7 @@ file.iterateNodesByType('SwitchCase', function(node) {

}
if (typeIndex['while']) {
checkBody('WhileStatement', 'While');
}
if (typeIndex['for']) {

@@ -90,7 +94,12 @@ checkBody('ForStatement', 'For');

}
if (typeIndex['do']) {
checkBody('DoWhileStatement', 'Do while');
}
if (typeIndex['with']) {
checkBody('WithStatement', 'With');
}
}
};

@@ -9,5 +9,8 @@ var assert = require('assert');

assert(
requireSpaceAfterLineComment === true,
'requireSpaceAfterLineComment option requires the value true'
requireSpaceAfterLineComment === true ||
requireSpaceAfterLineComment === 'allowSlash',
'requireSpaceAfterLineComment option requires the value true or `allowSlash`'
);
this._allowSlash = requireSpaceAfterLineComment === 'allowSlash';
},

@@ -21,2 +24,3 @@

var comments = file.getComments();
var allowSlash = this._allowSlash;

@@ -26,3 +30,13 @@ comments.forEach(function(comment) {

var value = comment.value;
if (value.length > 0 && value[0] !== ' ') {
// don't check triple slashed comments, microsoft js doc convention. see #593
if (allowSlash && value[0] === '/') {
value = value.substr(1);
}
if (value.length === 0) {
return;
}
if (value[0] !== ' ') {
errors.add('Missing space after line comment', comment.loc.start);

@@ -29,0 +43,0 @@ }

var assert = require('assert');
var tokenHelper = require('../token-helper');

@@ -29,2 +30,5 @@ module.exports = function() {};

var colon = tokens[valuePos - 1];
if (tokenHelper.isTokenParenthesis(file, colon.range[0], true)) {
colon = file.getPrevToken(colon);
}
if (colon.range[1] === value.range[0]) {

@@ -31,0 +35,0 @@ errors.add('Missing space after key colon', colon.loc.end);

@@ -7,3 +7,4 @@ var assert = require('assert');

configure: function(mode) {
configure: function(value) {
var mode;
var modes = {

@@ -13,8 +14,35 @@ 'all': true,

};
assert(
typeof mode === 'string' &&
modes[mode],
'requireSpacesInsideParentheses option requires string value \'all\' or \'allButNested\''
);
this._mode = mode;
var isObject = typeof value === 'object';
var error = 'requireSpacesInsideParentheses rule' +
' requires string value \'all\' or \'allButNested\' or object';
if (typeof value === 'string') {
assert(modes[value], error);
} else if (isObject) {
assert(
'all' in value || 'allButNested' in value,
error
);
} else {
assert(false, error);
}
this._exceptions = {};
if (isObject) {
mode = 'all' in value ? 'all' : 'allButNested';
(value.except || []).forEach(function(value) {
this._exceptions[value] = true;
}, this);
} else {
mode = value;
}
if (mode === 'allButNested') {
this._exceptions[')'] = this._exceptions['('] = true;
}
},

@@ -27,3 +55,3 @@

check: function(file, errors) {
var mode = this._mode;
var exceptions = this._exceptions;

@@ -36,47 +64,57 @@ function isComment(position) {

// Iterate punctuators since '(', ')' can exist in multiple contexts.
file.iterateTokensByType('Punctuator', function(token, index, tokens) {
if (token.value === '(') {
var nextToken = tokens[index + 1];
file.iterateTokenByValue('(', function(token, index, tokens) {
var nextToken = file.getNextToken(token);
var value = nextToken.value;
var type = nextToken.type;
// Skip the cases where we allow no space even if spaces are required.
if (nextToken.type === 'Punctuator' && nextToken.value === ')') {
return;
}
if (value in exceptions) {
return;
}
if (mode === 'allButNested' && nextToken.type === 'Punctuator' &&
nextToken.value === '(') {
return;
}
// Skip for empty parentheses
if (value === ')') {
return;
}
if ((token.range[1] === nextToken.range[0] &&
token.loc.end.line === nextToken.loc.start.line) ||
isComment(token.range[1])) {
errors.add('Missing space after opening round bracket', token.loc.end);
}
if (
(token.range[1] === nextToken.range[0] &&
token.loc.end.line === nextToken.loc.start.line) ||
isComment(token.range[1])
) {
errors.add('Missing space after opening round bracket', token.loc.end);
}
});
if (token.value === ')') {
var prevToken = tokens[index - 1];
file.iterateTokenByValue(')', function(token, index, tokens) {
var prevToken = file.getPrevToken(token);
var value = prevToken.value;
var type = prevToken.type;
// Skip the cases where we allow no space even if spaces are required.
if (prevToken.type === 'Punctuator' && prevToken.value === '(') {
return;
}
if (value in exceptions) {
if (mode === 'allButNested' && prevToken.type === 'Punctuator' &&
prevToken.value === ')') {
// Special case - foo( object[i] )
if (!(
value === ']' &&
file.getNodeByRange(token.range[0] - 1).type === 'MemberExpression'
)) {
return;
}
}
if ((token.range[0] === prevToken.range[1] &&
token.loc.end.line === prevToken.loc.start.line) ||
isComment(token.range[0] - 1)) {
errors.add('Missing space before closing round bracket',
token.loc.end.line,
token.loc.end.column - 2);
}
// Skip for empty parentheses
if (value === '(') {
return;
}
if (
(token.range[0] === prevToken.range[1] &&
token.loc.end.line === prevToken.loc.start.line) ||
isComment(token.range[0] - 1)
) {
errors.add('Missing space before closing round bracket',
token.loc.end.line,
token.loc.end.column - 2);
}
});
}
};

@@ -23,2 +23,4 @@ var assert = require('assert');

this._breakIndents = null;
this._indentableNodes = {

@@ -49,9 +51,4 @@ BlockStatement: 'body',

function markPop(node, indents, popAfter) {
var loc = node.loc;
if (popAfter) {
linesToCheck[loc.end.line - 1].popAfter = true;
} else {
linesToCheck[loc.end.line - 1].pop = indents;
}
function markPop(node, indents) {
linesToCheck[node.loc.end.line - 1].pop = indents;
}

@@ -69,27 +66,2 @@

children.forEach(function(childNode, i) {
/* temporary fix for holes in arrays: https://github.com/ariya/esprima/pull/241 */
if (childNode === null) {
var leftLine;
var rightLine;
var j;
for (j = i - 1; j >= 0; j -= 1) {
if (children[j]) {
leftLine = children[j].loc.end.line;
break;
}
}
for (j = i + 1; j < children.length; j += 1) {
if (children[j]) {
rightLine = children[j].loc.start.line;
break;
}
}
leftLine = leftLine || node.loc.start.line;
rightLine = rightLine || node.loc.end.line;
for (j = leftLine; j < rightLine; j++) {
linesToCheck[j - 1].check = lines[j - 1].replace(/[\s\t]/g, '').length > 0;
}
return;
}
/* /fix */
if (childNode.loc.start.line !== node.loc.start.line) {

@@ -103,10 +75,6 @@ linesToCheck[childNode.loc.start.line - 1].check = true;

linesToCheck.forEach(function(line, i) {
var expectedIndentation;
var actualIndentation = getIndentationFromLine(i);
if (line.pop !== null) {
expectedIndentation = indentStack.pop() - (indentSize * line.pop);
} else {
expectedIndentation = indentStack[indentStack.length - 1];
}
var expectedIndentation = getExpectedIndentation(line, actualIndentation);
if (line.check) {

@@ -125,8 +93,4 @@ if (actualIndentation !== expectedIndentation) {

if (line.popAfter) {
indentStack.pop();
}
if (line.push !== null) {
indentStack.push(actualIndentation + (indentSize * line.push));
pushExpectedIndentations(line, actualIndentation);
}

@@ -136,2 +100,48 @@ });

function getExpectedIndentation(line, actual) {
var outdent = indentSize * line.pop;
var expected;
var idx = indentStack.length - 1;
if (line.pop === null) {
expected = indentStack[idx];
} else {
expected = indentStack.pop();
if (Array.isArray(expected)) {
expected[0] -= outdent;
expected[1] -= outdent;
} else {
expected -= outdent;
}
}
// when the expected is an array, resolve the value
// back into a Number by checking both values are the actual indentation
if (line.check && Array.isArray(expected)) {
if (actual === expected[1]) {
indentStack[idx] = expected[1];
} else {
indentStack[idx] = expected[0];
}
expected = indentStack[idx];
}
return expected;
}
function pushExpectedIndentations(line, actualIndentation) {
var expectedIndentation = actualIndentation + (indentSize * line.push);
var expectedIndentation2;
// when a line has an alternate indentation, push an array of possible values
// on the stack, to be resolved when checked against an actual indentation
if (line.pushAltLine !== null) {
expectedIndentation2 = getIndentationFromLine(line.pushAltLine) + (indentSize * line.push);
indentStack.push([expectedIndentation, expectedIndentation2]);
} else {
indentStack.push(expectedIndentation);
}
}
function checkAlternateBlockStatement(node, property) {

@@ -145,2 +155,18 @@ var child = node[property];

function getBreakIndents(caseNode, children) {
var breakNode;
if (_this._breakIndents === null) {
children.some(function(node) {
if (node.type === 'BreakStatement') {
breakNode = node;
return true;
}
});
_this._breakIndents = (caseNode.loc.start.column === breakNode.loc.start.column) ? 1 : 0;
}
return _this._breakIndents;
}
function generateIndentations() {

@@ -157,15 +183,2 @@ file.iterateNodesByType([

file.iterateNodesByType([
'ObjectExpression',
'ArrayExpression'
], function(node) {
if (!isMultiline(node)) {
return;
}
markChildren(node);
markPop(node, 1);
markPushAndCheck(node, 1);
});
file.iterateNodesByType('BlockStatement', function(node) {

@@ -197,6 +210,11 @@ if (!isMultiline(node)) {

// Assume that if the test starts on the line following the parens,
// that the closing parens is on the line after the end of the test.
if (node.loc.start.line + 1 === test.loc.start.line) {
endLine++;
}
if (isMultiline(test) && linesToCheck[endLine].pop !== null) {
linesToCheck[endLine].push = 1;
}
});

@@ -239,3 +257,3 @@

markChildren(node);
markPop(node, 1, true);
markPop(node, getBreakIndents(node, children));
markPushAndCheck(node, 1);

@@ -245,6 +263,13 @@ } else if (children.length === 0) {

linesToCheck[node.loc.start.line - 1].check = true;
markPop(node, 1, true);
markPop(node, 0);
}
});
// indentations inside of function expressions can be offset from
// either the start of the function or the end of the function, therefore
// mark all starting lines of functions as potential indentations
file.iterateNodesByType(['FunctionDeclaration', 'FunctionExpression'], function(node) {
linesToCheck[node.loc.start.line - 1].pushAltLine = node.loc.end.line - 1;
});
file.iterateNodesByType('VariableDeclaration', function(node) {

@@ -274,2 +299,4 @@ var startLine = node.loc.start.line - 1;

var _this = this;
var indentableNodes = this._indentableNodes;

@@ -284,4 +311,4 @@ var indentChar = this._indentChar;

push: null,
pushAltLine: null,
pop: null,
popAfter: null,
check: null

@@ -288,0 +315,0 @@ };

@@ -1,5 +0,7 @@

var esprima = require('esprima');
var defaultEsprima = require('esprima');
var harmonyEsprima = require('esprima-harmony-jscs');
var Errors = require('./errors');
var JsFile = require('./js-file');
var preset = require('./options/preset');
var maxErrors = require('./options/max-errors');

@@ -10,9 +12,21 @@ /**

* @name StringChecker
* @param {Boolean} verbose
* @param {Boolean|Object} options either a boolean flag representing verbosity (deprecated), or an options object
* @param {Boolean} options.verbose true adds the rule name to the error messages it produces, false does not
* @param {Boolean} options.esnext true attempts to parse the code as es6, false does not
* @param {Object} options.esprima if provided, will be used to parse source code instead of the built-in esprima parser
*/
var StringChecker = function(verbose) {
var StringChecker = function(options) {
this._rules = [];
this._activeRules = [];
this._config = {};
this._verbose = verbose || false;
this._errorsFound = 0;
this._maxErrorsExceeded = false;
if (typeof options === 'boolean') {
this._verbose = options;
} else {
options = options || {};
this._verbose = options.verbose || false;
this._esprima = options.esprima || (options.esnext ? harmonyEsprima : defaultEsprima);
}
};

@@ -47,2 +61,3 @@

this.registerRule(new (require('./rules/disallow-right-sticked-operators'))());
this.registerRule(new (require('./rules/validate-jsdoc'))());
/* deprecated rules (end) */

@@ -65,3 +80,2 @@

this.registerRule(new (require('./rules/maximum-line-length'))());
this.registerRule(new (require('./rules/validate-jsdoc'))());
this.registerRule(new (require('./rules/require-yoda-conditions'))());

@@ -86,2 +100,4 @@ this.registerRule(new (require('./rules/disallow-yoda-conditions'))());

this.registerRule(new (require('./rules/require-padding-newlines-in-blocks'))());
this.registerRule(new (require('./rules/require-padding-newlines-in-objects'))());
this.registerRule(new (require('./rules/disallow-padding-newlines-in-objects'))());
this.registerRule(new (require('./rules/require-newline-before-block-statements'))());

@@ -125,2 +141,5 @@ this.registerRule(new (require('./rules/disallow-newline-before-block-statements'))());

this.registerRule(new (require('./rules/require-spaces-in-call-expression'))());
this.registerRule(new (require('./rules/disallow-spaces-in-call-expression'))());
this.registerRule(new (require('./rules/validate-parameter-separator'))());

@@ -139,2 +158,8 @@

this.registerRule(new (require('./rules/disallow-anonymous-functions'))());
this.registerRule(new (require('./rules/require-function-declarations'))());
this.registerRule(new (require('./rules/disallow-function-declarations'))());
this.registerRule(new (require('./rules/require-capitalized-comments'))());
this.registerRule(new (require('./rules/disallow-capitalized-comments'))());
},

@@ -156,2 +181,4 @@

configure: function(config) {
maxErrors(config, this);
this.throwNonCamelCaseErrorIfNeeded(config);

@@ -242,3 +269,3 @@

try {
tree = esprima.parse(str, {loc: true, range: true, comment: true, tokens: true});
tree = this._esprima.parse(str, {loc: true, range: true, comment: true, tokens: true});
} catch (e) {

@@ -250,25 +277,43 @@ parseError = e;

if (parseError) {
errors.setCurrentRule('parseError');
errors.add(parseError.description, parseError.lineNumber, parseError.column);
if (!this._maxErrorsExceeded) {
if (parseError) {
errors.setCurrentRule('parseError');
errors.add(parseError.description, parseError.lineNumber, parseError.column);
return errors;
}
return errors;
}
this._activeRules.forEach(function(rule) {
this._activeRules.forEach(function(rule) {
// Do not process the rule if it's equals to null (#203)
if (this._config[rule.getOptionName()] !== null) {
errors.setCurrentRule(rule.getOptionName());
rule.check(file, errors);
}
}, this);
// Do not process the rule if it's equals to null (#203)
if (this._config[rule.getOptionName()] !== null) {
errors.setCurrentRule(rule.getOptionName());
rule.check(file, errors);
// sort errors list to show errors as they appear in source
errors.getErrorList().sort(function(a, b) {
return (a.line - b.line) || (a.column - b.column);
});
if (this._maxErrors !== undefined) {
if (!this._maxErrorsExceeded) {
this._maxErrorsExceeded = this._errorsFound + errors.getErrorCount() > this._maxErrors;
}
errors.stripErrorList(Math.max(0, this._maxErrors - this._errorsFound));
}
}, this);
this._errorsFound += errors.getErrorCount();
}
// sort errors list to show errors as they appear in source
errors.getErrorList().sort(function(a, b) {
return (a.line - b.line) || (a.column - b.column);
});
return errors;
},
return errors;
/**
* Returns `true` if error count exceeded `maxErrors` option value.
*
* @returns {Boolean}
*/
maxErrorsExceeded: function() {
return this._maxErrorsExceeded;
}

@@ -275,0 +320,0 @@ };

@@ -99,6 +99,5 @@ // 7.5.2 Keywords

'do',
'try',
'catch',
'case',
'default'
'default',
'with'
];

@@ -105,0 +104,0 @@

@@ -5,12 +5,12 @@ {

"name": "jscs",
"version": "1.6.2",
"version": "1.7.0",
"main": "lib/checker",
"homepage": "https://github.com/mdevils/node-jscs",
"homepage": "https://github.com/jscs-dev/node-jscs",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/mdevils/node-jscs"
"url": "https://github.com/jscs-dev/node-jscs"
},
"bugs": {
"url": "https://github.com/mdevils/node-jscs/issues"
"url": "https://github.com/jscs-dev/node-jscs/issues"
},

@@ -23,3 +23,4 @@ "contributors": [

"Oleg Gaidarenko <markelog@gmail.com>",
"Mike Sherov <mike.sherov@gmail.com>"
"Mike Sherov <mike.sherov@gmail.com>",
"Joel Kemp <joel@mrjoelkemp.com>"
],

@@ -33,2 +34,3 @@ "engines": {

"esprima": "~1.2.2",
"esprima-harmony-jscs": "1.1.0-dev-harmony",
"exit": "~0.1.2",

@@ -35,0 +37,0 @@ "glob": "~4.0.0",

@@ -66,3 +66,4 @@ {

"disallowMultipleLineBreaks": true
"disallowMultipleLineBreaks": true,
"disallowNewlineBeforeBlockStatements": true
}

@@ -30,3 +30,3 @@ {

"requireSpaceBeforeBlockStatements": true,
"requireSpacesInFunctionExpression": {

@@ -33,0 +33,0 @@ "beforeOpeningCurlyBrace": true

@@ -10,2 +10,17 @@ # node-jscs

## Table of Contents
- [Presets](#presets)
- [Friendly Packages](#friendly-packages)
- [Extensions](#extensions)
- [Installation](#installation)
- [CLI](#cli)
- [Options](#options)
- [Error Suppression](#error-suppression)
- [Versioning & Semver](#versioning--semver)
- [Rules](#rules)
- [Removed Rules](#removed-rules)
- [Browser Usage](#browser-usage)
- [How to Contribute](https://github.com/jscs-dev/node-jscs/blob/master/CONTRIBUTING.md)
## Presets

@@ -84,5 +99,11 @@

### '--esnext'
Attempts to parse your code as ES6 using the harmony version of the esprima parser. Please note that this is currently experimental, and will improve over time.
### `--no-colors`
Clean output without colors.
### '--max-errors'
Set the maximum number of errors to report
### `--help`

@@ -169,2 +190,16 @@ Outputs usage information.

### maxErrors
Set the maximum number of errors to report
Type: `Number`
Default: Infinity
#### Example
```js
"maxErrors": 10
```
## Error Suppression

@@ -220,2 +255,23 @@

## Versioning & Semver
We recommend installing JSCS via NPM using `^`, or `~` if you want more stable releases.
Semver (http://semver.org/) dictates that breaking changes be major version bumps. In the context of a linting tool, a bug fix that causes more errors to be reported can be interpreted as a breaking change. However, that would require major version bumps to occur more often than can be desirable. Therefore, as a compromise, we will only release bug fixes that cause more errors to be reported in minor versions.
Below you fill find our versioning strategy, and what you can expect to come out of a new JSCS release.
* Patch release:
* A bug fix in a rule that causes JSCS to report less errors.
* Docs, refactoring and other "invisible" changes for user;
* Minor release:
* Any preset changes.
* A bug fix in a rule that causes JSCS to report more errors.
* New rules or new options for existing rules that don't change existing behavior.
* Modifying rules so they report less errors, and don't cause build failures.
* Major release:
* Purposefully modifying existing rules so that they report more errors or change the meaning of a rule.
* Any architectural changes that could cause builds to fail.
## Rules

@@ -701,3 +757,3 @@

```js
function a () {}
var x = function a () {}
```

@@ -708,4 +764,4 @@

```js
function a() {}
function a(){}
var x = function a() {}
var x = function a(){}
```

@@ -869,5 +925,5 @@

### disallowMultipleVarDecl
### requireSpacesInCallExpression
Disallows multiple `var` declaration (except for-loop).
Requires space before `()` in call expressions.

@@ -881,2 +937,56 @@ Type: `Boolean`

```js
"requireSpacesInCallExpression": true
```
##### Valid
```js
var x = foobar ();
```
##### Invalid
```js
var x = foobar();
```
### disallowSpacesInCallExpression
Disallows space before `()` in call expressions.
Type: `Boolean`
Values: `true`
#### Example
```js
"disallowSpacesInCallExpression": true
```
##### Valid
```js
var x = foobar();
```
##### Invalid
```js
var x = foobar ();
```
### disallowMultipleVarDecl
Disallows multiple `var` declaration (except for-loop).
Type: `Boolean` or `String`
Values: `true` or 'strict' (to disallow multiple variable declarations within a for loop)
#### Example
```js
"disallowMultipleVarDecl": true

@@ -1074,2 +1184,70 @@ ```

### requirePaddingNewLinesInObjects
Requires newline inside curly braces of all objects.
Type: `Boolean`
Values: `true`
#### Example
```js
"requirePaddingNewLinesInObjects": true
```
##### Valid
```js
var x = {
a: 1
};
foo({
a: {
b: 1
}
});
```
##### Invalid
```js
var x = { a: 1 };
foo({a:{b:1}});
```
### disallowPaddingNewLinesInObjects
Disallows newline inside curly braces of all objects.
Type: `Boolean`
Values: `true`
#### Example
```js
"disallowPaddingNewLinesInObjects": true
```
##### Valid
```js
var x = { a: 1 };
foo({a: {b: 1}});
```
##### Invalid
```js
var x = {
a: 1
};
foo({
a: {
b: 1
}
});
```
### disallowEmptyBlocks

@@ -1172,5 +1350,5 @@

Type: `Boolean`
Type: `Object` or `Boolean`
Values: `true`
Values: `true` or Object with either `"only"` with array of tokens or `"all"` with `true` value

@@ -1183,3 +1361,3 @@ #### Example

##### Valid
##### Valid for `true` value

@@ -1190,6 +1368,17 @@ ```js

##### Valid for `only` value
```js
"disallowSpacesInsideParentheses": { "only": [ "{", "}" ] }
```
```js
var x = ( 1 + 2 );
var x = foo({});
```
##### Invalid
```js
var x = ( 1 + 2 ) * 3;
var x = foo( {} );
```

@@ -1265,5 +1454,5 @@

Type: `String`
Type: `Object` or `String`
Values: `"all"` for strict mode, `"allButNested"` ignores nested brackets in a row.
Values: `"all"` for strict mode, `"allButNested"` (*deprecated* use `"except": ['(', ')']`) ignores nested brackets in a row, you could also specify token exceptions.

@@ -1273,3 +1462,6 @@ #### Example

```js
"requireSpacesInsideParentheses": "all"
"requireSpacesInsideParentheses": {
"all": true,
"except": [ "{", "}" ]
}
```

@@ -1289,2 +1481,8 @@

##### Valid for mode `"all"` with `except`
```js
var x = Math.pow( foo({ test: 1 }) );
```
##### Invalid

@@ -2424,7 +2622,7 @@

Requires that a line comment (`//`) be followed by a space.
Requires that a line comment (`//`) be followed by a space or slash space (`/// `).
Type: `Boolean`
Type: `Boolean` or `String`
Values: `true`
Values: `true` or `'allowSlash'`

@@ -2553,2 +2751,93 @@ #### Example

### disallowFunctionDeclarations
Disallows function declarations.
Type: `Boolean`
Values: `true`
#### Example
```js
"disallowFunctionDeclarations": true
```
##### Valid
```js
var expressed = function() {
};
var expressed = function deeply() {
};
$('#foo').click(function bar() {
};)
```
##### Invalid
```js
function stated() {
}
```
### requireFunctionDeclarations
Requires function declarations by disallowing assignment of functions
expressions to variables. Function expressions are allowed in all other
contexts, including when passed as function arguments or immediately invoked.
Assignment of function expressions to object members is also permitted, since
these can't be declared.
Type: `Boolean`
Values: `true`
#### Example
```js
"requireFunctionDeclarations": true
```
##### Valid
```js
function declared() {
};
(function iife() {
void 0;
})();
var obj = {
a: function () {}
};
obj.b = function () { };
$('#foo').click(function bar() {
};)
```
##### Invalid
```js
var expressed = function() {
};
var expressed = function deeply() {
};
```
### disallowNewlineBeforeBlockStatements

@@ -2780,3 +3069,3 @@

Validates indentation for arrays, objects, switch statements, and block statements
Validates indentation for switch statements and block statements

@@ -2869,51 +3158,84 @@ Type: `Integer` or `String`

### validateJSDoc
### requireCapitalizedComments
Enables JSDoc validation.
Requires the first alphabetical character of a comment to be uppercase
Type: `Object`
Type: `Boolean`
Values:
Value: `true`
- "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
#### Example
```js
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
`requireCapitalizedComments: true`
Valid:
```
// Valid
//Valid
##### Valid
/*
Valid
*/
```js
/**
* Adds style error to the list
*
* @param {String} message
* @param {Number|Object} line
* @param {Number} [column]
* Valid
*/
add: function(message, line, column) {
}
// 123 or any non-alphabetical starting character
```
##### Invalid
Invalid:
```
// invalid
//invalid
/** invalid */
/**
* invalid
*/
```
```js
### disallowCapitalizedComments
Requires the first alphabetical character of a comment to be lowercase.
Type: `String`
Value: `true`
#### Example
`disallowCapitalizedComments: true`
Valid:
```
// valid
//valid
/*
valid
*/
/**
* Adds style error to the list
*
* @param {String} message
* @param {Number|Object} line
* @param {Number} [column]
* valid
*/
add: function() {
}
// 123 or any non-alphabetical starting character
```
Invalid:
```
// Invalid
//Invalid
/** Invalid */
/**
* Invalid
*/
```
### ~~validateJSDoc~~
Please use the [JSCS-JSDoc](https://github.com/jscs-dev/jscs-jsdoc) plugin instead.
### safeContextKeyword

@@ -2920,0 +3242,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc