Socket
Socket
Sign inDemoInstall

jscs

Package Overview
Dependencies
Maintainers
1
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.4.0 to 1.4.1

lib/options/additional-rules.js

26

lib/checker.js
var vowFs = require('vow-fs');
var Vow = require('vow');
var minimatch = require('minimatch');
var glob = require('glob');
var StringChecker = require('./string-checker');

@@ -9,2 +7,5 @@ var utils = require('util');

var additionalRules = require('./options/additional-rules');
var excludeFiles = require('./options/exclude-files');
/**

@@ -17,3 +18,2 @@ * Starts Code Style checking process.

StringChecker.apply(this, arguments);
this._excludes = null;
};

@@ -31,21 +31,5 @@

// Rule Configuration was moved to string-checker.js
excludeFiles(config, this, cwd);
additionalRules(config, this, cwd);
this._excludes = (config.excludeFiles || []).map(function(pattern) {
return new minimatch.Minimatch(path.resolve(cwd, pattern), {
dot: true
});
});
(config.additionalRules || []).forEach(function(pattern) {
glob.sync(path.resolve(cwd, pattern)).map(function(path) {
var Rule = require(path);
this.registerRule(new Rule());
}, this);
}, this);
// remove "excludeFiles" and "additionalRules" from checking for unsupported rules
delete config.additionalRules;
delete config.excludeFiles;
StringChecker.prototype.configure.apply(this, arguments);

@@ -52,0 +36,0 @@ };

@@ -19,2 +19,29 @@ var assert = require('assert');

check: function(file, errors) {
var _commentLineMap;
function getCommentLines() {
if (!_commentLineMap) {
_commentLineMap = file.getComments().reduce(function(map, comment) {
for (var x = comment.loc.start.line; x <= comment.loc.end.line; x++) {
map[x] = 1;
}
return map;
}, {});
}
return _commentLineMap;
}
function hasEmptyLine(startLine, endLine) {
var commentLines = getCommentLines();
for (var x = startLine; x < endLine; x++) {
if (!commentLines[x]) {
return true;
}
}
return false;
}
file.iterateNodesByType('BlockStatement', function(node) {

@@ -30,4 +57,6 @@ if (node.body.length === 0) {

var nextToken = tokens[openingBracketPos + 1];
var startLine = openingBracket.loc.start.line + 1;
var nextLine = nextToken.loc.start.line;
if (openingBracket.loc.start.line + 1 < nextToken.loc.start.line) {
if (startLine < nextLine && hasEmptyLine(startLine, nextLine)) {
errors.add('Expected no padding newline after opening curly brace', openingBracket.loc.end);

@@ -39,4 +68,6 @@ }

var prevToken = tokens[closingBracketPos - 1];
var closingLine = closingBracket.loc.start.line;
var prevLine = prevToken.loc.start.line + 1;
if (closingBracket.loc.start.line > prevToken.loc.start.line + 1) {
if (closingLine > prevLine && hasEmptyLine(prevLine, closingLine)) {
errors.add('Expected no padding newline before closing curly brace', prevToken.loc.end);

@@ -43,0 +74,0 @@ }

@@ -86,4 +86,34 @@ var assert = require('assert');

function getIndents(pushNode, indents) {
if (!pushNode.parentNode || !pushNode.parentNode.parentNode) {
return indents;
}
var parent = pushNode.parentNode;
var grandParent = pushNode.parentNode.parentNode;
var parentStart = parent.loc.start.line;
var grandParentStart = grandParent.loc.start.line;
if (parent.type !== 'VariableDeclarator' ) {
return indents;
}
if (parentStart !== grandParentStart) {
return indents;
}
var actualIndentation = getIndentationFromLine(grandParentStart -1);
var newIndentation;
if (grandParent.declarations.length > 1) {
newIndentation = getIndentationFromLine(grandParent.declarations[1].loc.start.line - 1);
} else {
newIndentation = getIndentationFromLine(pushNode.loc.end.line - 1);
}
return ((newIndentation - actualIndentation) / indentSize) + 1;
}
function markPushAndCheck(pushNode, indents) {
linesToCheck[pushNode.loc.start.line - 1].push = indents;
linesToCheck[pushNode.loc.start.line - 1].push = getIndents(pushNode, indents);
linesToCheck[pushNode.loc.end.line - 1].check = true;

@@ -96,4 +126,29 @@ }

children.forEach(function(childNode) {
linesToCheck[childNode.loc.start.line - 1].check = true;
children.forEach(function(childNode, i) {
/* temporary fix for holes in arrays: https://github.com/ariya/esprima/pull/241 */
if (childNode === null) {
var leftLine, rightLine, 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) {
linesToCheck[childNode.loc.start.line - 1].check = true;
}
});

@@ -135,2 +190,10 @@ }

function checkAlternateBlockStatement(node, property) {
var child = node[property];
if (child && child.type === 'BlockStatement') {
linesToCheck[child.loc.start.line - 1].push = 1;
linesToCheck[child.loc.start.line - 1].check = true;
}
}
function generateIndentations() {

@@ -161,8 +224,10 @@ file.iterateNodesByType([

file.iterateNodesByType('IfStatement', function(node) {
if (node.alternate && node.alternate.type === 'BlockStatement') {
linesToCheck[node.alternate.loc.start.line - 1].push = 1;
linesToCheck[node.alternate.loc.start.line - 1].check = true;
}
checkAlternateBlockStatement(node, 'alternate');
});
file.iterateNodesByType('TryStatement', function(node) {
checkAlternateBlockStatement(node, 'handler');
checkAlternateBlockStatement(node, 'finalizer');
});
file.iterateNodesByType('BlockStatement', function(node) {

@@ -169,0 +234,0 @@ if (!isMultiline(node)) {

var esprima = require('esprima');
var Errors = require('./errors');
var JsFile = require('./js-file');
var presets = {
jquery: require('./presets/jquery.json'),
google: require('./presets/google.json'),
};
var preset = require('./options/preset');

@@ -133,3 +130,3 @@ /**

this.throwNonCamelCaseErrorIfNeeded(config);
this.setPreset(config);
preset(config);

@@ -200,22 +197,2 @@ var configRules = Object.keys(config);

/**
* Take preset (if defined) rules and extend passed config with them
*
* @param {Object} config
*/
setPreset: function(config) {
if (!config.preset) {
return;
}
var preset = presets[config.preset];
delete config.preset;
for (var rule in preset) {
if (!(rule in config)) {
config[rule] = preset[rule];
}
}
},
/**
* Checks file provided with a string.

@@ -222,0 +199,0 @@ * @param {String} str

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

"name": "jscs",
"version": "1.4.0",
"version": "1.4.1",
"main": "lib/checker",

@@ -52,4 +52,5 @@ "homepage": "https://github.com/mdevils/node-jscs",

"lint": "jshint . && node bin/jscs lib test bin",
"test": "npm run lint && mocha -u bdd -R spec",
"browserify": "browserify --standalone JscsStringChecker lib/string-checker.js -o jscs-browser.js"
"test": "npm run lint && mocha",
"browserify": "browserify --standalone JscsStringChecker lib/string-checker.js -o jscs-browser.js",
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:'%s (%an)' | grep -v 'Merge pull request'"
},

@@ -56,0 +57,0 @@ "files": [

@@ -13,5 +13,10 @@ # node-jscs [![Build Status](https://travis-ci.org/mdevils/node-jscs.svg?branch=master)](https://travis-ci.org/mdevils/node-jscs) [![Dependency Status](https://david-dm.org/mdevils/node-jscs.svg?theme=shields.io)](https://david-dm.org/mdevils/node-jscs) [![devDependency Status](https://david-dm.org/mdevils/node-jscs/dev-status.svg?theme=shields.io)](https://david-dm.org/mdevils/node-jscs#info=devDependencies)

* Syntastic VIM Plugin: [https://github.com/scrooloose/syntastic/.../syntax_checkers/javascript/jscs.vim/](https://github.com/scrooloose/syntastic/blob/master/syntax_checkers/javascript/jscs.vim/)
* Brackets Extension: https://github.com/globexdesigns/brackets-jscs
* Web Essentials for Visual Studio 2013: https://github.com/madskristensen/WebEssentials2013/
### Extensions
* 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
## Installation

@@ -18,0 +23,0 @@

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