jscs
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -9,12 +9,48 @@ /** | ||
var stripJSONComments = require('strip-json-comments'); | ||
var glob = require('glob'); | ||
// Configuration sources in priority order. | ||
var options = ['package.json', '.jscsrc', '.jscs.json']; | ||
var configs = ['package.json', '.jscsrc', '.jscs.json']; | ||
function loadConfig(config, directory) { | ||
// Before, "findup-sync" package was used, | ||
// but it does not provide filter callback | ||
function findup(patterns, options, fn) { | ||
/* jshint -W083 */ | ||
var lastpath, file; | ||
options = Object.create(options || {}); | ||
options.maxDepth = 1; | ||
options.cwd = path.resolve(options.cwd || '.'); | ||
do { | ||
file = patterns.filter(function(pattern) { | ||
var configPath = glob.sync(pattern, options)[0]; | ||
if (configPath) { | ||
return !fn || fn(path.join(options.cwd, configPath)); | ||
} | ||
})[0]; | ||
if (file) { | ||
return path.join(options.cwd, file); | ||
} | ||
lastpath = options.cwd; | ||
options.cwd = path.resolve(options.cwd, '..'); | ||
} while (options.cwd !== lastpath); | ||
} | ||
exports.getContent = function(config, directory) { | ||
if (!config) { | ||
return; | ||
} | ||
var configPath = path.resolve(directory, config); | ||
var content; | ||
config = path.basename(config); | ||
if (fs.existsSync(configPath)) { | ||
if (path.basename(config) === '.jscsrc') { | ||
if (config === '.jscsrc') { | ||
content = JSON.parse( | ||
@@ -37,16 +73,32 @@ stripJSONComments( | ||
return content && config === 'package.json' ? content.jscsConfig : content; | ||
} | ||
}; | ||
exports.load = function(config, cwd) { | ||
var content; | ||
var directory = cwd || process.cwd(); | ||
// If config option is given, attempt to load it and return. | ||
// If config option is given, attempt to load it | ||
if (config) { | ||
return loadConfig(config, directory); | ||
return this.getContent(config, directory); | ||
} | ||
// If no config option is given, attempt to load config files in order of priority. | ||
for (var i = 0, len = options.length; i < len; i++) { | ||
var content = loadConfig(options[i], directory); | ||
content = this.getContent( | ||
findup(configs, { nocase: true, cwd: directory }, function(configPath) { | ||
if (path.basename(configPath) === 'package.json') { | ||
return !!this.getContent(configPath); | ||
} | ||
return true; | ||
}.bind(this)) | ||
); | ||
if (content) { | ||
return content; | ||
} | ||
// Try to load standart configs from home dir | ||
directory = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; | ||
for (var i = 0, len = configs.length; i < len; i++) { | ||
content = this.getContent(configs[i], directory); | ||
if (content) { | ||
@@ -53,0 +105,0 @@ return content; |
@@ -15,2 +15,3 @@ var treeIterator = require('./tree-iterator'); | ||
var index = this._index = {}; | ||
var _this = this; | ||
this.iterate(function(node, parentNode, parentCollection) { | ||
@@ -23,2 +24,14 @@ if (node) { | ||
(index[type] || (index[type] = [])).push(node); | ||
// Temporary fix (i hope) for esprima tokenizer | ||
// (https://code.google.com/p/esprima/issues/detail?id=481) | ||
// Fixes #83, #180 | ||
switch (type) { | ||
case 'Property': | ||
convertKeywordToIdentifierIfRequired(node.key); | ||
break; | ||
case 'MemberExpression': | ||
convertKeywordToIdentifierIfRequired(node.property); | ||
break; | ||
} | ||
} | ||
@@ -28,14 +41,12 @@ } | ||
// Temporary fix (i hope) for esprima tokenizer | ||
// (https://code.google.com/p/esprima/issues/detail?id=481) | ||
// Fixes #83, #180 | ||
this._tree.tokens.forEach(function(token, index) { | ||
if (index && token.type === 'Keyword') { | ||
var previous = this[index - 1].value; | ||
if (previous === ',' || previous === '{' || previous === '.') { | ||
// Part of temporary esprima fix. | ||
function convertKeywordToIdentifierIfRequired(node) { | ||
var tokenPos = _this.getTokenPosByRangeStart(node.range[0]); | ||
if (tokenPos !== undefined) { | ||
var token = _this._tree.tokens[tokenPos]; | ||
if (token.type === 'Keyword') { | ||
token.type = 'Identifier'; | ||
} | ||
} | ||
}, this._tree.tokens); | ||
} | ||
}; | ||
@@ -71,5 +82,6 @@ | ||
* @param {Function} cb | ||
* @param {Function} [tree] | ||
*/ | ||
iterate: function(cb) { | ||
return treeIterator.iterate(this._tree, cb); | ||
iterate: function(cb, tree) { | ||
return treeIterator.iterate(tree || this._tree, cb); | ||
}, | ||
@@ -76,0 +88,0 @@ /** |
@@ -23,2 +23,7 @@ var assert = require('assert'); | ||
check: function(file, errors) { | ||
function isCommentInRange(start, end) { | ||
return file.getComments().some(function(comment) { | ||
return start <= comment.range[0] && end >= comment.range[1]; | ||
}); | ||
} | ||
file.iterateTokensByType('Punctuator', function(token, index, tokens) { | ||
@@ -28,3 +33,4 @@ if (token.value === '(') { | ||
if (token.range[1] !== nextToken.range[0] && | ||
token.loc.end.line === nextToken.loc.start.line) { | ||
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); | ||
@@ -37,3 +43,4 @@ } | ||
if (prevToken.range[1] !== token.range[0] && | ||
prevToken.loc.end.line === token.loc.start.line) { | ||
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); | ||
@@ -40,0 +47,0 @@ } |
@@ -9,9 +9,7 @@ var assert = require('assert'); | ||
assert( | ||
typeof requireBlocksOnNewline === 'boolean', | ||
'requireBlocksOnNewline option requires boolean value' | ||
requireBlocksOnNewline === true || typeof requireBlocksOnNewline === 'number', | ||
'requireBlocksOnNewline option requires the value true or an Integer' | ||
); | ||
assert( | ||
requireBlocksOnNewline === true, | ||
'requireBlocksOnNewline option requires true value or should be removed' | ||
); | ||
this._minStatements = requireBlocksOnNewline === true ? 0 : requireBlocksOnNewline; | ||
}, | ||
@@ -24,5 +22,6 @@ | ||
check: function(file, errors) { | ||
var minStatements = this._minStatements; | ||
file.iterateNodesByType('BlockStatement', function(node) { | ||
if (node.body.length === 0) { | ||
// Do not warn for empty blocks, such as empty function declarations | ||
if (node.body.length <= minStatements) { | ||
return; | ||
@@ -29,0 +28,0 @@ } |
var assert = require('assert'); | ||
function consecutive(file, errors) { | ||
file.iterateNodesByType('VariableDeclaration', function(node) { | ||
var pos = node.parentCollection.indexOf(node); | ||
if (pos < node.parentCollection.length - 1) { | ||
var sibling = node.parentCollection[pos + 1]; | ||
if (sibling.type === 'VariableDeclaration') { | ||
errors.add( | ||
'Var declarations should be joined', | ||
sibling.loc.start | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
function onevar(file, errors) { | ||
file.iterateNodesByType([ 'Program', 'FunctionDeclaration', 'FunctionExpression' ], function(node) { | ||
var firstVar = true; | ||
var firstParent = true; | ||
file.iterate(function(node) { | ||
var type = node && node.type; | ||
// Don't go in nested scopes | ||
if ( !firstParent && type && [ 'FunctionDeclaration', 'FunctionExpression' ].indexOf(type) > -1) { | ||
return false; | ||
} | ||
if ( firstParent ) { | ||
firstParent = false; | ||
} | ||
if (type === 'VariableDeclaration') { | ||
if (!firstVar) { | ||
errors.add( | ||
'Var declarations should be joined', | ||
node.loc.start | ||
); | ||
} else { | ||
firstVar = false; | ||
} | ||
} | ||
}, node); | ||
}); | ||
} | ||
module.exports = function() {}; | ||
@@ -8,9 +54,12 @@ | ||
assert( | ||
typeof requireMultipleVarDecl === 'boolean', | ||
'requireMultipleVarDecl option requires boolean value' | ||
typeof requireMultipleVarDecl === 'boolean' || | ||
typeof requireMultipleVarDecl === 'string', | ||
'requireMultipleVarDecl option requires boolean or string' | ||
); | ||
assert( | ||
requireMultipleVarDecl === true, | ||
'requireMultipleVarDecl option requires true value or should be removed' | ||
requireMultipleVarDecl === true || requireMultipleVarDecl === 'onevar', | ||
'requireMultipleVarDecl option requires true value or `onevar` string' | ||
); | ||
this._check = typeof requireMultipleVarDecl === 'string' ? onevar : consecutive; | ||
}, | ||
@@ -22,17 +71,5 @@ | ||
check: function(file, errors) { | ||
file.iterateNodesByType('VariableDeclaration', function(node) { | ||
var pos = node.parentCollection.indexOf(node); | ||
if (pos < node.parentCollection.length - 1) { | ||
var sibling = node.parentCollection[pos + 1]; | ||
if (sibling.type === 'VariableDeclaration') { | ||
errors.add( | ||
'Var declarations should be joined', | ||
sibling.loc.start | ||
); | ||
} | ||
} | ||
}); | ||
check: function() { | ||
return this._check.apply(this, arguments); | ||
} | ||
}; |
@@ -22,6 +22,7 @@ var assert = require('assert'); | ||
file.iterateTokensByType('Keyword', function(token, i, tokens) { | ||
file.iterateTokensByType([ 'Keyword' ], function(token, i, tokens) { | ||
if (keywordIndex[token.value]) { | ||
var nextToken = tokens[i + 1]; | ||
if (nextToken && nextToken.range[0] === token.range[1]) { | ||
if (nextToken && nextToken.range[0] - token.range[1] !== 1) { | ||
if (nextToken.type !== 'Punctuator' || nextToken.value !== ';') { | ||
@@ -28,0 +29,0 @@ errors.add( |
@@ -34,3 +34,3 @@ var assert = require('assert'); | ||
errors.add( | ||
'You should use "' + keywords.join('" or "') + '"save a reference to "this"', | ||
'You should use "' + keywords.join('" or "') + '" to save a reference to "this"', | ||
node.loc.start | ||
@@ -51,3 +51,3 @@ ); | ||
errors.add( | ||
'You should use "' + keywords.join('" or "') + '"save a reference to "this"', | ||
'You should use "' + keywords.join('" or "') + '" to save a reference to "this"', | ||
node.loc.start | ||
@@ -54,0 +54,0 @@ ); |
@@ -27,3 +27,2 @@ var assert = require('assert'); | ||
ArrayExpression: 'elements', | ||
CallExpression: 'arguments', | ||
SwitchStatement: 'cases', | ||
@@ -195,29 +194,2 @@ SwitchCase: 'consequent' | ||
file.iterateNodesByType('CallExpression', function(node) { | ||
if (!isMultiline(node)) { | ||
return; | ||
} | ||
if (!node.arguments.length) { | ||
return; | ||
} | ||
// var argumentsIndentation; | ||
var argLoc = node.arguments[0].loc; | ||
var calleeLoc = node.callee.loc; | ||
var argStartLine = argLoc.start.line - 1; | ||
var argEndLine = argLoc.end.line - 1; | ||
var calleeEndLine = calleeLoc.end.line - 1; | ||
var nodeEndLine = node.loc.end.line - 1; | ||
// only concerned with multiline arguments | ||
if (calleeEndLine === argStartLine && nodeEndLine === argEndLine) { | ||
return; | ||
} | ||
linesToCheck[calleeEndLine].push = linesToCheck[calleeEndLine].push || 0; | ||
linesToCheck[nodeEndLine].pop = linesToCheck[nodeEndLine].pop || 0; | ||
linesToCheck[nodeEndLine].check = true; | ||
}); | ||
file.iterateNodesByType('SwitchCase', function(node) { | ||
@@ -224,0 +196,0 @@ if (!isMultiline(node)) { |
@@ -5,3 +5,4 @@ var esprima = require('esprima'); | ||
var presets = { | ||
jquery: require('./presets/jquery.json') | ||
jquery: require('./presets/jquery.json'), | ||
google: require('./presets/google.json'), | ||
}; | ||
@@ -78,5 +79,14 @@ | ||
this.registerRule(new (require('./rules/disallow-padding-newlines-in-blocks'))()); | ||
this.registerRule(new (require('./rules/require-padding-newlines-in-blocks'))()); | ||
this.registerRule(new (require('./rules/disallow-trailing-comma'))()); | ||
this.registerRule(new (require('./rules/require-trailing-comma'))()); | ||
this.registerRule(new (require('./rules/disallow-comma-before-line-break'))()); | ||
this.registerRule(new (require('./rules/require-comma-before-line-break'))()); | ||
this.registerRule(new (require('./rules/disallow-space-before-block-statements.js'))()); | ||
this.registerRule(new (require('./rules/require-space-before-block-statements.js'))()); | ||
this.registerRule(new (require('./rules/disallow-space-before-postfix-unary-operators.js'))()); | ||
@@ -83,0 +93,0 @@ this.registerRule(new (require('./rules/require-space-before-postfix-unary-operators.js'))()); |
@@ -60,3 +60,6 @@ module.exports = { | ||
function iterate(node, cb, parentNode, parentCollection) { | ||
cb(node, parentNode, parentCollection); | ||
if (cb(node, parentNode, parentCollection) === false) { | ||
return; | ||
} | ||
for (var propName in node) { | ||
@@ -63,0 +66,0 @@ if (node.hasOwnProperty(propName)) { |
{ | ||
"author": "Marat Dulin <mdevils@yandex.ru>", | ||
"description": "JavaScript Style Checker", | ||
"description": "JavaScript Code Style", | ||
"name": "jscs", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"main": "lib/checker", | ||
"repository": "https://github.com/mdevils/node-jscs", | ||
"homepage": "https://github.com/mdevils/node-jscs", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mdevils/node-jscs" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mdevils/node-jscs/issues" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Marat Dulin", | ||
"email": "mdevils@yandex.ru" | ||
}, | ||
{ | ||
"name": "Konstantin Ikonnikov", | ||
"email": "ikokostya@gmail.com" | ||
}, | ||
{ | ||
"name": "Igor Agarlev" | ||
}, | ||
{ | ||
"name": "Alexey Androsov", | ||
"email": "doochik@ya.ru" | ||
}, | ||
{ | ||
"name": "Oleg Gaidarenko", | ||
"email": "markelog@gmail.com" | ||
}, | ||
{ | ||
"name": "Mike Sherov", | ||
"email": "mike.sherov@gmail.com" | ||
} | ||
"Marat Dulin <mdevils@yandex.ru>", | ||
"Konstantin Ikonnikov <ikokostya@gmail.com>", | ||
"Igor Agarlev", | ||
"Alexey Androsov <doochik@ya.ru>", | ||
"Oleg Gaidarenko <markelog@gmail.com>", | ||
"Mike Sherov <mike.sherov@gmail.com>" | ||
], | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
"node": ">= 0.10.0" | ||
}, | ||
"dependencies": { | ||
"esprima": "1.0.3", | ||
"vow": "0.3.9", | ||
"vow-fs": "0.2.3", | ||
"colors": "0.6.0-1", | ||
"commander": "1.2.0", | ||
"minimatch": "0.2.12", | ||
"glob": "3.2.7", | ||
"xmlbuilder": "1.1.2", | ||
"strip-json-comments": "0.1.1" | ||
"colors": "~0.6.2", | ||
"commander": "~2.2.0", | ||
"esprima": "~1.1.1", | ||
"glob": "~3.2.9", | ||
"minimatch": "~0.2.14", | ||
"strip-json-comments": "~0.1.1", | ||
"vow": "~0.3.12", | ||
"vow-fs": "~0.2.3", | ||
"xmlbuilder": "~2.2.1" | ||
}, | ||
"devDependencies": { | ||
"jshint": "2.1.3", | ||
"mocha": "1.11.0", | ||
"browserify": "2.35.0", | ||
"xml2js": "0.4.0", | ||
"hooker": "0.2.3", | ||
"sinon": "1.7.3" | ||
"browserify": "~3.43.0", | ||
"hooker": "~0.2.3", | ||
"jshint": "~2.5.0", | ||
"mocha": "~1.18.2", | ||
"sinon": "~1.9.1", | ||
"xml2js": "~0.4.2" | ||
}, | ||
@@ -59,5 +50,11 @@ "bin": { | ||
"scripts": { | ||
"test": "jshint . && node bin/jscs lib test bin && mocha -u bdd -R spec", | ||
"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" | ||
} | ||
}, | ||
"files": [ | ||
"bin", | ||
"lib", | ||
"LICENSE" | ||
] | ||
} |
478
README.md
@@ -1,8 +0,6 @@ | ||
# node-jscs [![Build Status](https://travis-ci.org/mdevils/node-jscs.png?branch=master)](https://travis-ci.org/mdevils/node-jscs) | ||
# 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) | ||
JSCS — JavaScript Code Style. | ||
`jscs` is a code style checker. `jscs` can check cases, which are not implemented in jshint, | ||
but it does not duplicate `jshint` functionality, so you should use `jscs` and `jshint` together. | ||
`jscs` is a code style checker. You can configure `jscs` for your project in detail using **over 60** validation rules. [jQuery](https://github.com/mdevils/node-jscs/blob/master/lib/presets/jquery.json) preset is also available. | ||
@@ -15,2 +13,3 @@ ## Friendly packages | ||
* 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/ | ||
@@ -23,3 +22,3 @@ | ||
``` | ||
npm install jscs | ||
npm install jscs -g | ||
``` | ||
@@ -30,11 +29,93 @@ | ||
``` | ||
./node_modules/.bin/jscs path[ path[...]] | ||
jscs path[ path[...]] | ||
``` | ||
## Configuration | ||
## CLI | ||
`jscs` looks for configuration in the project root. | ||
### `--config` | ||
Allows to define path to the config file. | ||
``` | ||
jscs path[ path[...]] --config=./.config.json | ||
``` | ||
If there is a `package.json` then it will use the `jscsConfig` field of it if present, if there is no `package.json`, or the `jscsConfig` field is not found, `jscs` will look for a `.jscsrc` file, and finally a `.jscs.json` file for configuration. | ||
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. | ||
``` | ||
jscs path[ path[...]] --reporter=./some-dir/my-reporter.js | ||
``` | ||
### `--no-colors` | ||
*Will be removed*. Clean output without colors. | ||
### `--help` | ||
Outputs usage information. | ||
### `--version` | ||
Outputs version of `jscs`. | ||
## Options | ||
### additionalRules | ||
Path to load additional rules | ||
Type: `Array` | ||
Values: Array of file matching patterns | ||
#### Example | ||
```js | ||
"additionalRules": ["project-rules/*.js"] | ||
``` | ||
### preset | ||
Extends defined rules with preset rules. | ||
Type: `String` | ||
Values: `"jquery"` | ||
#### Example | ||
```js | ||
"preset": "jquery" | ||
``` | ||
If you want specifically disable preset rule assign it to `null` | ||
```js | ||
"preset": "jquery", | ||
"requireCurlyBraces": null | ||
``` | ||
### excludeFiles | ||
Disables style checking for specified paths. | ||
Type: `Array` | ||
Values: Array of file matching patterns | ||
#### Example | ||
```js | ||
"excludeFiles": ["node_modules/**"] | ||
``` | ||
## Rules | ||
### requireCurlyBraces | ||
@@ -46,3 +127,3 @@ | ||
Values: Arrow of quoted keywords | ||
Values: Array of quoted keywords | ||
@@ -150,2 +231,97 @@ JSHint: [`curly`](http://jshint.com/docs/options/#curly) | ||
### requireSpaceBeforeBlockStatements | ||
Requires space before block statements (for loops, control structures). | ||
Type: `Boolean` | ||
Values: `true` | ||
#### Example | ||
```js | ||
"requireSpaceBeforeBlockStatements": true | ||
``` | ||
##### Valid | ||
```js | ||
if (cond) { | ||
foo(); | ||
} | ||
for (var e in elements) { | ||
bar(e); | ||
} | ||
while (cond) { | ||
foo(); | ||
} | ||
``` | ||
##### Invalid | ||
```js | ||
if (cond){ | ||
foo(); | ||
} | ||
for (var e in elements){ | ||
bar(e); | ||
} | ||
while (cond){ | ||
foo(); | ||
} | ||
``` | ||
### disallowSpaceBeforeBlockStatements | ||
Disallows space before block statements (for loops, control structures). | ||
Type: `Boolean` | ||
Values: `true` | ||
#### Example | ||
```js | ||
"disallowSpaceBeforeBlockStatements": true | ||
``` | ||
##### Valid | ||
```js | ||
if (cond){ | ||
foo(); | ||
} | ||
for (var e in elements){ | ||
bar(e); | ||
} | ||
while (cond){ | ||
foo(); | ||
} | ||
``` | ||
##### Invalid | ||
```js | ||
if (cond) { | ||
foo(); | ||
} | ||
for (var e in elements) { | ||
bar(e); | ||
} | ||
while (cond) { | ||
foo(); | ||
} | ||
``` | ||
### requireParenthesesAroundIIFE | ||
@@ -445,4 +621,2 @@ | ||
JSHint: [`onevar`](http://jshint.com/docs/options/#onevar) | ||
#### Example | ||
@@ -474,6 +648,9 @@ | ||
Type: `Boolean` | ||
Type: `Boolean` or `String` | ||
Values: `true` | ||
Values: `true` or `onevar` | ||
if `requireMultipleVarDecl` defined as a `boolean` 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. | ||
JSHint: [`onevar`](http://jshint.com/docs/options/#onevar) | ||
@@ -505,5 +682,5 @@ | ||
Type: `Boolean` | ||
Type: `Boolean` or `Integer` | ||
Values: `true` | ||
Values: `true` validates all non-empty blocks, `Integer` specifies a minimum number of statements in the block before validating. | ||
@@ -516,3 +693,3 @@ #### Example | ||
##### Valid | ||
##### Valid for mode `true` | ||
@@ -532,2 +709,113 @@ ```js | ||
##### Valid for mode `1` | ||
```js | ||
if (true) { | ||
doSomething(); | ||
doSomethingElse(); | ||
} | ||
if (true) { doSomething(); } | ||
var abc = function() {}; | ||
``` | ||
##### Invalid | ||
```js | ||
if (true) { doSomething(); doSomethingElse(); } | ||
``` | ||
### requirePaddingNewlinesInBlock | ||
Requires blocks to begin and end with 2 newlines | ||
Type: `Boolean` or `Integer` | ||
Values: `true` validates all non-empty blocks, `Integer` specifies a minimum number of statements in the block before validating. | ||
#### Example | ||
```js | ||
"requirePaddingNewlinesInBlock": true | ||
``` | ||
##### Valid for mode `true` | ||
```js | ||
if (true) { | ||
doSomething(); | ||
} | ||
var abc = function() {}; | ||
``` | ||
##### Invalid | ||
```js | ||
if (true) {doSomething();} | ||
if (true) { | ||
doSomething(); | ||
} | ||
``` | ||
##### Valid for mode `1` | ||
```js | ||
if (true) { | ||
doSomething(); | ||
doSomethingElse(); | ||
} | ||
if (true) { | ||
doSomething(); | ||
} | ||
if (true) { doSomething(); } | ||
var abc = function() {}; | ||
``` | ||
##### Invalid | ||
```js | ||
if (true) { doSomething(); doSomethingElse(); } | ||
if (true) { | ||
doSomething(); | ||
doSomethingElse(); | ||
} | ||
``` | ||
### disallowPaddingNewlinesInBlocks | ||
Disallows blocks from beginning and ending with 2 newlines. | ||
Type: `Boolean` | ||
Values: `true` validates all non-empty blocks. | ||
#### Example | ||
```js | ||
"disallowPaddingNewlinesInBlocks": true | ||
``` | ||
##### Valid | ||
```js | ||
if (true) { | ||
doSomething(); | ||
} | ||
if (true) {doSomething();} | ||
var abc = function() {}; | ||
``` | ||
##### Invalid | ||
```js | ||
if (true) { | ||
doSomething(); | ||
} | ||
``` | ||
### disallowEmptyBlocks | ||
@@ -1717,2 +2005,60 @@ | ||
### disallowTrailingComma | ||
Disallows an extra comma following the final element of an array or object literal. | ||
Type: `Boolean` | ||
Values: `true` | ||
JSHint: [`es3`](http://jshint.com/docs/options/#es3) | ||
#### Example | ||
```js | ||
"disallowTrailingComma": true | ||
``` | ||
##### Valid | ||
```js | ||
var foo = [1, 2, 3]; | ||
var bar = {a: "a", b: "b"} | ||
``` | ||
##### Invalid | ||
```js | ||
var foo = [1, 2, 3, ]; | ||
var bar = {a: "a", b: "b", } | ||
``` | ||
### requireTrailingComma | ||
Requires an extra comma following the final element of an array or object literal. | ||
Type: `Boolean` | ||
Values: `true` | ||
#### Example | ||
```js | ||
"requireTrailingComma": true | ||
``` | ||
##### Valid | ||
```js | ||
var foo = [1, 2, 3,]; | ||
var bar = {a: "a", b: "b",} | ||
``` | ||
##### Invalid | ||
```js | ||
var foo = [1, 2, 3]; | ||
var bar = {a: "a", b: "b"} | ||
``` | ||
### disallowKeywordsOnNewLine | ||
@@ -1863,3 +2209,3 @@ | ||
Type: 'Array' or `String` | ||
Type: `Array` or `String` | ||
@@ -1918,2 +2264,32 @@ Values: String value used for context local declaration | ||
### disallowYodaConditions | ||
Requires the variable to be the left hand operator when doing a boolean comparison | ||
Type: `Boolean` | ||
Values: `true` | ||
#### Example | ||
```js | ||
"disallowYodaConditions": true | ||
``` | ||
##### Valid | ||
```js | ||
if (a == 1) { | ||
return | ||
} | ||
``` | ||
##### Invalid | ||
```js | ||
if (1 == a) { | ||
return | ||
} | ||
``` | ||
### validateJSDoc | ||
@@ -1969,50 +2345,2 @@ | ||
### excludeFiles | ||
Disables style checking for specified paths. | ||
Type: `Array` | ||
Values: Array of file matching patterns | ||
#### Example | ||
```js | ||
"excludeFiles": ["node_modules/**"] | ||
``` | ||
### additionalRules | ||
Path to load additional rules | ||
Type: `Array` | ||
Values: Array of file matching patterns | ||
#### Example | ||
```js | ||
"additionalRules": ["project-rules/*.js"] | ||
``` | ||
### preset | ||
Extends defined rules with preset rules. | ||
Type: `String` | ||
Values: `"jquery"` | ||
#### Example | ||
```js | ||
"preset": "jquery" | ||
``` | ||
If you want specifically disable preset rule assign it to `null` | ||
```js | ||
"preset": "jquery", | ||
requireCurlyBraces: null | ||
``` | ||
## Browser Usage | ||
@@ -2025,12 +2353,12 @@ | ||
```html | ||
<script type="text/javascript" src="jscs-browser.js"></script> | ||
<script type="text/javascript"> | ||
var checker = new JscsStringChecker(); | ||
checker.registerDefaultRules(); | ||
checker.configure({disallowMultipleVarDecl: true}); | ||
var errors = checker.checkString('var x, y = 1;'); | ||
errors.getErrorList().forEach(function(error) { | ||
console.log(errors.explainError(error)); | ||
}); | ||
<script src="jscs-browser.js"></script> | ||
<script> | ||
var checker = new JscsStringChecker(); | ||
checker.registerDefaultRules(); | ||
checker.configure({disallowMultipleVarDecl: true}); | ||
var errors = checker.checkString('var x, y = 1;'); | ||
errors.getErrorList().forEach(function(error) { | ||
console.log(errors.explainError(error)); | ||
}); | ||
</script> | ||
``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
High entropy strings
Supply chain riskContains high entropy strings. This could be a sign of encrypted data, leaked secrets or obfuscated code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
0
2350
8
187846
87
3999
1
+ Addedcolors@0.6.2(transitive)
+ Addedcommander@2.2.0(transitive)
+ Addedesprima@1.1.1(transitive)
+ Addedglob@3.2.11(transitive)
+ Addedlodash-node@2.4.1(transitive)
+ Addedminimatch@0.2.140.3.0(transitive)
+ Addedstrip-json-comments@0.1.3(transitive)
+ Addedvow@0.3.13(transitive)
+ Addedxmlbuilder@2.2.1(transitive)
- Removedcolors@0.6.0-1(transitive)
- Removedcommander@1.2.0(transitive)
- Removedesprima@1.0.3(transitive)
- Removedglob@3.2.7(transitive)
- Removedkeypress@0.1.0(transitive)
- Removedminimatch@0.2.12(transitive)
- Removedstrip-json-comments@0.1.1(transitive)
- Removedunderscore@1.13.6(transitive)
- Removedvow@0.3.9(transitive)
- Removedxmlbuilder@1.1.2(transitive)
Updatedcolors@~0.6.2
Updatedcommander@~2.2.0
Updatedesprima@~1.1.1
Updatedglob@~3.2.9
Updatedminimatch@~0.2.14
Updatedstrip-json-comments@~0.1.1
Updatedvow@~0.3.12
Updatedvow-fs@~0.2.3
Updatedxmlbuilder@~2.2.1