Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Clone in Desktop Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

86 lines (73 sloc) 1.82 KB
/**
* Requires an extra blank newline after var declarations, as long
* as it is not the last expression in the current block.
*
* Type: `Boolean`
*
* Value: `true`
*
* #### Example
*
* ```js
* "requirePaddingNewLineAfterVariableDeclaration": true
* ```
*
* ##### Valid
*
* ```js
* var x = {
* a: 1
* };
*
* foo({
* a: {
* b: 1
* }
* });
* ```
*
* ##### Invalid
*
* ```js
* var x = { a: 1 };
* foo({a:{b:1}});
* ```
*/
var assert = require('assert');
module.exports = function() {};
module.exports.prototype = {
configure: function(requirePaddingNewLineAfterVariableDeclaration) {
assert(
requirePaddingNewLineAfterVariableDeclaration === true,
this.getOptionName() + ' option requires a true value or should be removed'
);
},
getOptionName: function() {
return 'requirePaddingNewLineAfterVariableDeclaration';
},
check: function(file, errors) {
file.iterateNodesByType('VariableDeclaration', function(node) {
if (node.parentNode.type === 'ForStatement' ||
node.parentNode.type === 'ForInStatement' ||
node.parentNode.type === 'ForOfStatement') {
return;
}
var endOfDeclaration = file.getLastNodeToken(node);
var nextToken = file.getNextToken(endOfDeclaration);
if (nextToken.value in {'var': true, 'let': true, 'const': true}) {
return;
}
if (nextToken.value === '}') {
return;
}
if (nextToken.type === 'EOF') {
return;
}
errors.assert.linesBetween({
atLeast: 2,
token: endOfDeclaration,
nextToken: nextToken
});
});
}
};
Jump to Line
Something went wrong with that request. Please try again.