Socket
Socket
Sign inDemoInstall

jscs

Package Overview
Dependencies
Maintainers
3
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.5.1 to 1.5.2

95

lib/checker.js

@@ -45,9 +45,10 @@ var vowFs = require('vow-fs');

var _this = this;
if (this._shouldProcess(path)) {
if ( !_this._isExcluded(path) && _this._hasCorrectExtension(path)) {
return vowFs.read(path, 'utf8').then(function(data) {
return _this.checkString(data, path);
});
} else {
return null;
}
return null;
};

@@ -63,25 +64,25 @@

var _this = this;
return vowFs.listDir(path).then(function(filenames) {
return Vow.all(filenames.map(function(filename) {
var fullname = path + '/' + filename;
// check for exclude path
if (_this._shouldProcess(fullname)) {
return vowFs.stat(fullname).then(function(stat) {
if (stat.isDirectory()) {
return _this.checkDirectory(fullname);
} else if (fullname.match(/\.js$/)) {
return Vow.when(_this.checkFile(fullname)).then(function(errors) {
if (errors) {
return errors;
} else {
return [];
}
});
} else {
return [];
if (_this._isExcluded(fullname)) {
return [];
}
return vowFs.stat(fullname).then(function(stat) {
if (stat.isDirectory()) {
return _this.checkDirectory(fullname);
}
return Vow.when(_this.checkFile(fullname)).then(function(errors) {
if (errors) {
return errors;
}
return [];
});
} else {
return [];
}
});
})).then(function(results) {

@@ -103,19 +104,19 @@ return [].concat.apply([], results);

return vowFs.exists(path).then(function(exists) {
if (exists) {
return vowFs.stat(path).then(function(stat) {
if (stat.isDirectory()) {
return _this.checkDirectory(path);
} else {
return Vow.when(_this.checkFile(path)).then(function(errors) {
if (errors) {
return [errors];
} else {
return [];
}
});
if (!exists) {
throw new Error('Path ' + path + ' was not found.');
}
return vowFs.stat(path).then(function(stat) {
if (stat.isDirectory()) {
return _this.checkDirectory(path);
}
return Vow.when(_this.checkFile(path)).then(function(errors) {
if (errors) {
return [errors];
}
return [];
});
} else {
throw new Error('Path ' + path + ' was not found.');
}
});
});

@@ -125,17 +126,10 @@ };

/**
* Returns true if specified path is not in exluded list and if
* the file extension matches a file extension to process.
* Returns true if specified path is in excluded list.
*
* @returns {Boolean}
*/
Checker.prototype._shouldProcess = function(testPath) {
Checker.prototype._isExcluded = function(testPath) {
testPath = path.resolve(testPath);
var extension = path.extname(testPath).toLowerCase();
if (this._fileExtensions.indexOf(extension) < 0 &&
this._fileExtensions.indexOf('*') < 0) {
return false;
}
return this._excludes.every(function(exclude) {
return !this._excludes.every(function(exclude) {
return !exclude.match(testPath);

@@ -145,2 +139,13 @@ });

/**
* Returns true if the file extension matches a file extension to process.
*
* @returns {Boolean}
*/
Checker.prototype._hasCorrectExtension = function(testPath) {
var extension = path.extname(testPath).toLowerCase();
return !(this._fileExtensions.indexOf(extension) < 0 && this._fileExtensions.indexOf('*') < 0);
};
module.exports = Checker;

@@ -33,38 +33,2 @@ var assert = require('assert');

// 2 + 2, 2 == 2
file.iterateNodesByType(
['BinaryExpression', 'AssignmentExpression', 'LogicalExpression'],
function(node) {
if (operators[node.operator]) {
var indent;
var range = node.right.range[0];
if (tokenHelper.isTokenParenthesis(file, range - 1, true)) {
indent = node.operator.length + 1;
} else {
indent = node.operator.length;
}
var part = tokenHelper.getTokenByRangeStartIfPunctuator(
file,
range - indent,
node.operator,
true
);
if (!part) {
var loc = tokenHelper.findOperatorByRangeStart(
file, node.right.range[0], node.operator, true
).loc.start;
errors.add(
'Operator ' + node.operator + ' should stick to following expression',
loc.line,
tokenHelper.getPointerEntities(loc.column, node.operator.length)
);
}
}
}
);
function errorIfApplicable(token, i, tokens, operator) {

@@ -84,3 +48,3 @@ var nextToken = tokens[i + 1];

// ":" for object property only but not for ternar
// ":" for object property only but not for ternar
if (operators[':']) {

@@ -108,4 +72,42 @@ file.iterateNodesByType(['ObjectExpression'], function(node) {

}
// For everything else
file.iterateNodesByType(
['BinaryExpression', 'AssignmentExpression', 'VariableDeclarator', 'LogicalExpression'],
function(node) {
var isDec = node.type === 'VariableDeclarator';
var operator = isDec ? '=' : node.operator;
if (!operators[operator] || node.init === null) {
return;
}
var range = (isDec ? node.init : node.right).range[0];
var indent = tokenHelper.isTokenParenthesis(file, range - 1, true) ?
operator.length + 1 :
operator.length;
var part = tokenHelper.getTokenByRangeStartIfPunctuator(
file,
range - indent,
operator,
true
);
if (!part) {
var loc = tokenHelper.findOperatorByRangeStart(
file, range, operator, true
).loc.start;
errors.add(
'Operator ' + operator + ' should stick to following expression',
loc.line,
tokenHelper.getPointerEntities(loc.column, operator.length)
);
}
}
);
}
};

@@ -74,20 +74,23 @@ var assert = require('assert');

file.iterateNodesByType(
['BinaryExpression', 'AssignmentExpression', 'LogicalExpression'],
['BinaryExpression', 'AssignmentExpression', 'VariableDeclarator', 'LogicalExpression'],
function(node) {
if (operators[node.operator]) {
var part = tokenHelper.getTokenByRangeStartIfPunctuator(
file,
node.left.range[1],
node.operator
);
var isDec = node.type === 'VariableDeclarator';
var operator = isDec ? '=' : node.operator;
if (!part) {
errors.add(
'Operator ' + node.operator + ' should stick to preceding expression',
tokenHelper.findOperatorByRangeStart(
file, node.right.range[0], node.operator, true
).loc.start
);
}
// !node.init is it's an empty assignment
if (!operators[operator] || node.init === null) {
return;
}
var range = (isDec ? node.id : node.left).range;
var part = tokenHelper.getTokenByRangeStartIfPunctuator(file, range[1], operator);
if (!part) {
errors.add(
'Operator ' + node.operator + ' should stick to preceding expression',
tokenHelper.findOperatorByRangeStart(
file, range[0], operator
).loc.start
);
}
}

@@ -94,0 +97,0 @@ );

@@ -74,30 +74,32 @@ var assert = require('assert');

file.iterateNodesByType(
['BinaryExpression', 'AssignmentExpression', 'LogicalExpression'],
['BinaryExpression', 'AssignmentExpression', 'VariableDeclarator', 'LogicalExpression'],
function(node) {
if (operators[node.operator]) {
var indent;
var range = node.right.range[0];
var isDec = node.type === 'VariableDeclarator';
var operator = isDec ? '=' : node.operator;
if (tokenHelper.isTokenParenthesis(file, range - 1, true)) {
indent = node.operator.length + 1;
} else {
indent = node.operator.length;
}
if (!operators[operator] || node.init === null) {
return;
}
var part = tokenHelper.getTokenByRangeStartIfPunctuator(
file,
range - indent,
node.operator,
true
);
var range = (isDec ? node.init : node.right).range[0];
if (part) {
var loc = part.loc.start;
var indent = tokenHelper.isTokenParenthesis(file, range - 1, true) ?
operator.length + 1 :
operator.length;
errors.add(
'Operator ' + node.operator + ' should not stick to following expression',
loc.line,
tokenHelper.getPointerEntities(loc.column, node.operator.length)
);
}
var part = tokenHelper.getTokenByRangeStartIfPunctuator(
file,
range - indent,
operator,
true
);
if (part) {
var loc = part.loc.start;
errors.add(
'Operator ' + operator + ' should not stick to following expression',
loc.line,
tokenHelper.getPointerEntities(loc.column, operator.length)
);
}

@@ -104,0 +106,0 @@ }

@@ -74,20 +74,22 @@ var assert = require('assert');

file.iterateNodesByType(
['BinaryExpression', 'AssignmentExpression', 'LogicalExpression'],
['BinaryExpression', 'AssignmentExpression', 'VariableDeclarator', 'LogicalExpression'],
function(node) {
if (operators[node.operator]) {
var part = tokenHelper.getTokenByRangeStartIfPunctuator(
file,
node.left.range[1],
node.operator
);
var isDec = node.type === 'VariableDeclarator';
var operator = isDec ? '=' : node.operator;
if (part) {
var loc = part.loc.start;
errors.add(
'Operator ' + node.operator + ' should not stick to following expression',
loc.line,
tokenHelper.getPointerEntities(loc.column, node.operator.length)
);
}
if (!operators[operator]) {
return;
}
var range = (isDec ? node.id : node.left).range[1];
var part = tokenHelper.getTokenByRangeStartIfPunctuator(file, range, operator);
if (part) {
var loc = part.loc.start;
errors.add(
'Operator ' + operator + ' should not stick to following expression',
loc.line,
tokenHelper.getPointerEntities(loc.column, operator.length)
);
}
}

@@ -94,0 +96,0 @@ );

@@ -5,3 +5,3 @@ {

"name": "jscs",
"version": "1.5.1",
"version": "1.5.2",
"main": "lib/checker",

@@ -8,0 +8,0 @@ "homepage": "https://github.com/mdevils/node-jscs",

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