162 lines
No EOL
17 KiB
JavaScript
162 lines
No EOL
17 KiB
JavaScript
'use strict';
|
|
|
|
var _staticRequire = require('../core/staticRequire');
|
|
|
|
var _staticRequire2 = _interopRequireDefault(_staticRequire);
|
|
|
|
var _debug = require('debug');
|
|
|
|
var _debug2 = _interopRequireDefault(_debug);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
/**
|
|
* @fileoverview Rule to enforce new line after import not followed by another import.
|
|
* @author Radek Benkel
|
|
*/
|
|
|
|
const log = (0, _debug2.default)('eslint-plugin-import:rules:newline-after-import');
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
function containsNodeOrEqual(outerNode, innerNode) {
|
|
return outerNode.range[0] <= innerNode.range[0] && outerNode.range[1] >= innerNode.range[1];
|
|
}
|
|
|
|
function getScopeBody(scope) {
|
|
if (scope.block.type === 'SwitchStatement') {
|
|
log('SwitchStatement scopes not supported');
|
|
return null;
|
|
}
|
|
|
|
const body = scope.block.body;
|
|
|
|
if (body && body.type === 'BlockStatement') {
|
|
return body.body;
|
|
}
|
|
|
|
return body;
|
|
}
|
|
|
|
function findNodeIndexInScopeBody(body, nodeToFind) {
|
|
return body.findIndex(node => containsNodeOrEqual(node, nodeToFind));
|
|
}
|
|
|
|
function getLineDifference(node, nextNode) {
|
|
return nextNode.loc.start.line - node.loc.end.line;
|
|
}
|
|
|
|
function isClassWithDecorator(node) {
|
|
return node.type === 'ClassDeclaration' && node.decorators && node.decorators.length;
|
|
}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
docs: {},
|
|
schema: [{
|
|
'type': 'object',
|
|
'properties': {
|
|
'count': {
|
|
'type': 'integer',
|
|
'minimum': 1
|
|
}
|
|
},
|
|
'additionalProperties': false
|
|
}],
|
|
fixable: 'whitespace'
|
|
},
|
|
create: function (context) {
|
|
let level = 0;
|
|
const requireCalls = [];
|
|
|
|
function checkForNewLine(node, nextNode, type) {
|
|
if (isClassWithDecorator(nextNode)) {
|
|
nextNode = nextNode.decorators[0];
|
|
}
|
|
|
|
const options = context.options[0] || { count: 1 };
|
|
const lineDifference = getLineDifference(node, nextNode);
|
|
const EXPECTED_LINE_DIFFERENCE = options.count + 1;
|
|
|
|
if (lineDifference < EXPECTED_LINE_DIFFERENCE) {
|
|
let column = node.loc.start.column;
|
|
|
|
if (node.loc.start.line !== node.loc.end.line) {
|
|
column = 0;
|
|
}
|
|
|
|
context.report({
|
|
loc: {
|
|
line: node.loc.end.line,
|
|
column
|
|
},
|
|
message: `Expected empty line after ${type} statement not followed by another ${type}.`,
|
|
fix: fixer => fixer.insertTextAfter(node, '\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference))
|
|
});
|
|
}
|
|
}
|
|
|
|
function incrementLevel() {
|
|
level++;
|
|
}
|
|
function decrementLevel() {
|
|
level--;
|
|
}
|
|
|
|
return {
|
|
ImportDeclaration: function (node) {
|
|
const parent = node.parent;
|
|
|
|
const nodePosition = parent.body.indexOf(node);
|
|
const nextNode = parent.body[nodePosition + 1];
|
|
|
|
if (nextNode && nextNode.type !== 'ImportDeclaration') {
|
|
checkForNewLine(node, nextNode, 'import');
|
|
}
|
|
},
|
|
CallExpression: function (node) {
|
|
if ((0, _staticRequire2.default)(node) && level === 0) {
|
|
requireCalls.push(node);
|
|
}
|
|
},
|
|
'Program:exit': function () {
|
|
log('exit processing for', context.getFilename());
|
|
const scopeBody = getScopeBody(context.getScope());
|
|
log('got scope:', scopeBody);
|
|
|
|
requireCalls.forEach(function (node, index) {
|
|
const nodePosition = findNodeIndexInScopeBody(scopeBody, node);
|
|
log('node position in scope:', nodePosition);
|
|
|
|
const statementWithRequireCall = scopeBody[nodePosition];
|
|
const nextStatement = scopeBody[nodePosition + 1];
|
|
const nextRequireCall = requireCalls[index + 1];
|
|
|
|
if (nextRequireCall && containsNodeOrEqual(statementWithRequireCall, nextRequireCall)) {
|
|
return;
|
|
}
|
|
|
|
if (nextStatement && (!nextRequireCall || !containsNodeOrEqual(nextStatement, nextRequireCall))) {
|
|
|
|
checkForNewLine(statementWithRequireCall, nextStatement, 'require');
|
|
}
|
|
});
|
|
},
|
|
FunctionDeclaration: incrementLevel,
|
|
FunctionExpression: incrementLevel,
|
|
ArrowFunctionExpression: incrementLevel,
|
|
BlockStatement: incrementLevel,
|
|
ObjectExpression: incrementLevel,
|
|
Decorator: incrementLevel,
|
|
'FunctionDeclaration:exit': decrementLevel,
|
|
'FunctionExpression:exit': decrementLevel,
|
|
'ArrowFunctionExpression:exit': decrementLevel,
|
|
'BlockStatement:exit': decrementLevel,
|
|
'ObjectExpression:exit': decrementLevel,
|
|
'Decorator:exit': decrementLevel
|
|
};
|
|
}
|
|
};
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25ld2xpbmUtYWZ0ZXItaW1wb3J0LmpzIl0sIm5hbWVzIjpbImxvZyIsImNvbnRhaW5zTm9kZU9yRXF1YWwiLCJvdXRlck5vZGUiLCJpbm5lck5vZGUiLCJyYW5nZSIsImdldFNjb3BlQm9keSIsInNjb3BlIiwiYmxvY2siLCJ0eXBlIiwiYm9keSIsImZpbmROb2RlSW5kZXhJblNjb3BlQm9keSIsIm5vZGVUb0ZpbmQiLCJmaW5kSW5kZXgiLCJub2RlIiwiZ2V0TGluZURpZmZlcmVuY2UiLCJuZXh0Tm9kZSIsImxvYyIsInN0YXJ0IiwibGluZSIsImVuZCIsImlzQ2xhc3NXaXRoRGVjb3JhdG9yIiwiZGVjb3JhdG9ycyIsImxlbmd0aCIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwiZG9jcyIsInNjaGVtYSIsImZpeGFibGUiLCJjcmVhdGUiLCJjb250ZXh0IiwibGV2ZWwiLCJyZXF1aXJlQ2FsbHMiLCJjaGVja0Zvck5ld0xpbmUiLCJvcHRpb25zIiwiY291bnQiLCJsaW5lRGlm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iAgICAgICAgICBmaXg6IGZpeGVyID0+IGZpeGVyLmluc2VydFRleHRBZnRlcihcbiAgICAgICAgICAgIG5vZGUsXG4gICAgICAgICAgICAnXFxuJy5yZXBlYXQoRVhQRUNURURfTElORV9ESUZGRVJFTkNFIC0gbGluZURpZmZlcmVuY2UpXG4gICAgICAgICAgKSxcbiAgICAgICAgfSlcbiAgICAgIH1cbiAgICB9XG5cbiAgICBmdW5jdGlvbiBpbmNyZW1lbnRMZXZlbCgpIHtcbiAgICAgIGxldmVsKytcbiAgICB9XG4gICAgZnVuY3Rpb24gZGVjcmVtZW50TGV2ZWwoKSB7XG4gICAgICBsZXZlbC0tXG4gICAgfVxuXG4gICAgcmV0dXJuIHtcbiAgICAgIEltcG9ydERlY2xhcmF0aW9uOiBmdW5jdGlvbiAobm9kZSkge1xuICAgICAgICBjb25zdCB7IHBhcmVudCB9ID0gbm9kZVxuICAgICAgICBjb25zdCBub2RlUG9zaXRpb24gPSBwYXJlbnQuYm9keS5pbmRleE9mKG5vZGUpXG4gICAgICAgIGNvbnN0IG5leHROb2RlID0gcGFyZW50LmJvZHlbbm9kZVBvc2l0aW9uICsgMV1cblxuICAgICAgICBpZiAobmV4dE5vZGUgJiYgbmV4dE5vZGUudHlwZSAhPT0gJ0ltcG9ydERlY2xhcmF0aW9uJykge1xuICAgICAgICAgIGNoZWNrRm9yTmV3TGluZShub2RlLCBuZXh0Tm9kZSwgJ2ltcG9ydCcpXG4gICAgICAgIH1cbiAgICAgIH0sXG4gICAgICBDYWxsRXhwcmVzc2lvbjogZnVuY3Rpb24obm9kZSkge1xuICAgICAgICBpZiAoaXNTdGF0aWNSZXF1aXJlKG5vZGUpICYmIGxldmVsID09PSAwKSB7XG4gICAgICAgICAgcmVxdWlyZUNhbGxzLnB1c2gobm9kZSlcbiAgICAgICAgfVxuICAgICAgfSxcbiAgICAgICdQcm9ncmFtOmV4aXQnOiBmdW5jdGlvbiAoKSB7XG4gICAgICAgIGxvZygnZXhpdCBwcm9j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