Comparing version 1.5.7 to 1.5.8
@@ -11,2 +11,3 @@ var colors = require('colors'); | ||
this._file = file; | ||
this._currentRule = ''; | ||
}; | ||
@@ -28,2 +29,3 @@ | ||
this._errorList.push({ | ||
rule: this._currentRule, | ||
message: message, | ||
@@ -98,2 +100,12 @@ line: line, | ||
return result.join('\n'); | ||
}, | ||
/** | ||
* Sets the current rule so that errors are aware | ||
* of which rule triggered them. | ||
* | ||
* @param {String} rule | ||
*/ | ||
setCurrentRule: function(rule) { | ||
this._currentRule = rule; | ||
} | ||
@@ -100,0 +112,0 @@ |
@@ -47,3 +47,3 @@ var assert = require('assert'); | ||
// ":" for object property only but not for ternar | ||
// ":" for object property only but not for ternary | ||
if (operators[':']) { | ||
@@ -50,0 +50,0 @@ file.iterateNodesByType(['ObjectExpression'], function(node) { |
@@ -9,11 +9,13 @@ var assert = require('assert'); | ||
var modes = { | ||
'all': true, | ||
'skipWithFunction': true, | ||
'skipWithLineBreak': true | ||
'all': 'all', | ||
'ignoreFunction': 'ignoreFunction', | ||
'ignoreLineBreak': 'ignoreLineBreak', | ||
'skipWithFunction': 'ignoreFunction', | ||
'skipWithLineBreak': 'ignoreLineBreak' | ||
}; | ||
assert( | ||
typeof mode === 'string' && modes[mode], | ||
this.getOptionName() + ' option requires string value \'skipWithFunction\' or \'skipWithLineBreak\'' | ||
this.getOptionName() + ' requires one of the following values: ' + Object.keys(modes).join(', ') | ||
); | ||
this._mode = mode; | ||
this._mode = modes[mode]; | ||
}, | ||
@@ -33,13 +35,14 @@ | ||
var skip = false; | ||
var maxKeyEndPos = 0; | ||
var skip = node.properties.some(function(property, index) { | ||
maxKeyEndPos = Math.max(maxKeyEndPos, property.key.loc.end.column); | ||
node.properties.forEach(function(property, index) { | ||
var keyEndPos = property.key.loc.end.column; | ||
if (keyEndPos > maxKeyEndPos) { | ||
maxKeyEndPos = keyEndPos; | ||
if (mode === 'ignoreFunction' && property.value.type === 'FunctionExpression') { | ||
return true; | ||
} | ||
skip = skip || (mode === 'skipWithFunction' && property.value.type === 'FunctionExpression') || | ||
(mode === 'skipWithLineBreak' && index > 0 && | ||
node.properties[index - 1].loc.end.line !== property.loc.start.line - 1); | ||
if (mode === 'ignoreLineBreak' && index > 0 && | ||
node.properties[index - 1].loc.end.line !== property.loc.start.line - 1) { | ||
return true; | ||
} | ||
}); | ||
@@ -46,0 +49,0 @@ |
var assert = require('assert'); | ||
var tokenHelper = require('../token-helper'); | ||
@@ -7,10 +8,15 @@ module.exports = function() {}; | ||
configure: function(requireTrailingComma) { | ||
assert( | ||
typeof requireTrailingComma === 'boolean', | ||
'requireTrailingComma option requires boolean value' | ||
); | ||
assert( | ||
requireTrailingComma === true, | ||
'requireTrailingComma option requires true value or should be removed' | ||
); | ||
if (typeof requireTrailingComma === 'object') { | ||
assert( | ||
requireTrailingComma.ignoreSingleValue === true, | ||
'requireTrailingComma option skipSingleValue requires true value or should be removed' | ||
); | ||
this._ignoreSingleValue = true; | ||
} else { | ||
assert( | ||
requireTrailingComma === true, | ||
'requireTrailingComma option requires true value or should be removed' | ||
); | ||
} | ||
}, | ||
@@ -23,26 +29,22 @@ | ||
check: function(file, errors) { | ||
file.iterateTokensByType('Punctuator', function(token, i, tokens) { | ||
if (token.value === '}' || token.value === ']') { | ||
var prevToken = tokens[i - 1]; | ||
var error = false; | ||
if (prevToken) { | ||
if (prevToken.type !== 'Punctuator') { | ||
error = true; | ||
} else { | ||
if (token.value === '}' && prevToken.value === '{') { | ||
// This is just a new object declaration. | ||
} else if (token.value === ']' && prevToken.value === '[') { | ||
// This is just new array declaration. | ||
} else if (prevToken.value !== ',') { | ||
error = true; | ||
} | ||
} | ||
var _this = this; | ||
if (error) { | ||
errors.add( | ||
'Require extra comma following the final element of an array or object literal', | ||
token.loc.start | ||
); | ||
} | ||
file.iterateNodesByType(['ObjectExpression', 'ArrayExpression'], function(node) { | ||
var isObject = node.type === 'ObjectExpression'; | ||
var message = 'Missing comma before closing ' + (isObject ? ' curly brace' : ' bracket'); | ||
var entities = isObject ? node.properties : node.elements; | ||
var last; | ||
var hasTrailingComma; | ||
if (entities.length) { | ||
if (_this._ignoreSingleValue && entities.length === 1) { | ||
return; | ||
} | ||
last = entities[entities.length - 1]; | ||
hasTrailingComma = tokenHelper.getTokenByRangeStartIfPunctuator(file, last.range[1], ','); | ||
if (!hasTrailingComma) { | ||
errors.add(message, node.loc.end); | ||
} | ||
} | ||
@@ -49,0 +51,0 @@ }); |
@@ -168,3 +168,13 @@ var assert = require('assert'); | ||
markPop(node, 1); | ||
markPushAndCheck(node.parentNode, 1); | ||
// The parent of an else block statement is the entire if/else | ||
// block. In order to avoid over indenting in the case of a | ||
// non-block if with a block else, mark push where the else starts, | ||
// not where the if starts! | ||
if (node.parentNode.type === 'IfStatement' && | ||
node.parentNode.alternate === node) { | ||
markPushAndCheck(node, 1); | ||
} else { | ||
markPushAndCheck(node.parentNode, 1); | ||
} | ||
}); | ||
@@ -171,0 +181,0 @@ |
@@ -229,2 +229,3 @@ var esprima = require('esprima'); | ||
if (this._config[rule.getOptionName()] !== null) { | ||
errors.setCurrentRule(rule.getOptionName()); | ||
rule.check(file, errors); | ||
@@ -231,0 +232,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"name": "jscs", | ||
"version": "1.5.7", | ||
"version": "1.5.8", | ||
"main": "lib/checker", | ||
@@ -54,4 +54,4 @@ "homepage": "https://github.com/mdevils/node-jscs", | ||
"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'", | ||
"prepublish": "node publish/prepublish", | ||
"changelog": "git log `git describe --tags --abbrev=0`..HEAD --pretty=format:' * %s (%an)' | grep -v 'Merge pull request'", | ||
"release": "node publish/prepublish && npm publish", | ||
"postpublish": "node publish/postpublish" | ||
@@ -58,0 +58,0 @@ }, |
@@ -1331,4 +1331,4 @@ # 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) | ||
- `"all"` for strict mode, | ||
- `"skipWithFunction"` ignores objects if one of the property values is a function expression, | ||
- `"skipWithLineBreak"` ignores objects if there are line breaks between properties | ||
- `"ignoreFunction"` ignores objects if one of the property values is a function expression, | ||
- `"ignoreLineBreak"` ignores objects if there are line breaks between properties | ||
@@ -2082,6 +2082,10 @@ #### Example | ||
Type: `Boolean` | ||
Type: `Boolean` or `Object` | ||
Values: `true` | ||
Values: | ||
- `true`: validates all arrays and objects | ||
- `Object`: | ||
- `ignoreSingleValue`: allows single property objects and single element arrays to not require a trailing comma | ||
#### Example | ||
@@ -2100,2 +2104,8 @@ | ||
##### Valid with ignoreSingleValue | ||
```js | ||
var car = [1]; | ||
var dar = {a: "a"}; | ||
``` | ||
##### Invalid | ||
@@ -2201,7 +2211,7 @@ | ||
- `Object`: | ||
- `value`: lines should be at most the number of characters specified | ||
- `tabSize`: considered the tab character as number of specified spaces | ||
- `allowComments`: allows comments to break the rule | ||
- `allowUrlComments`: allows comments with long urls to break the rule | ||
- `allowRegex`: allows regular expression literals to break the rule | ||
- `value`: (required) lines should be at most the number of characters specified | ||
- `tabSize`: (default: `1`) considered the tab character as number of specified spaces | ||
- `allowComments`: (default: `false`) allows comments to break the rule | ||
- `allowUrlComments`: (default: `false`) allows comments with long urls to break the rule | ||
- `allowRegex`: (default: `false`) allows regular expression literals to break the rule | ||
@@ -2515,3 +2525,3 @@ JSHint: [`maxlen`](http://jshint.com/docs/options/#maxlen) | ||
If you'd like to generate this file yourself, run `npm browserify` after cloning this repo. | ||
If you'd like to generate this file yourself, run `npm run browserify` after cloning this repo. | ||
@@ -2518,0 +2528,0 @@ Use `jscs-browser.js` on your page as follows: |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
591123
14464
2537