170 lines
17 KiB
JavaScript
170 lines
17 KiB
JavaScript
'use strict';
|
|
|
|
var _staticRequire = require('../core/staticRequire');
|
|
|
|
var _staticRequire2 = _interopRequireDefault(_staticRequire);
|
|
|
|
var _docsUrl = require('../docsUrl');
|
|
|
|
var _docsUrl2 = _interopRequireDefault(_docsUrl);
|
|
|
|
var _debug = require('debug');
|
|
|
|
var _debug2 = _interopRequireDefault(_debug);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
const log = (0, _debug2.default)('eslint-plugin-import:rules:newline-after-import');
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Rule Definition
|
|
//------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @fileoverview Rule to enforce new line after import not followed by another import.
|
|
* @author Radek Benkel
|
|
*/
|
|
|
|
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: {
|
|
type: 'layout',
|
|
docs: {
|
|
url: (0, _docsUrl2.default)('newline-after-import')
|
|
},
|
|
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 ${options.count} empty line${options.count > 1 ? 's' : ''} \
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uZXdsaW5lLWFmdGVyLWltcG9ydC5qcyJdLCJuYW1lcyI6WyJsb2ciLCJjb250YWluc05vZGVPckVxdWFsIiwib3V0ZXJOb2RlIiwiaW5uZXJOb2RlIiwicmFuZ2UiLCJnZXRTY29wZUJvZHkiLCJzY29wZSIsImJsb2NrIiwidHlwZSIsImJvZHkiLCJmaW5kTm9kZUluZGV4SW5TY29wZUJvZHkiLCJub2RlVG9GaW5kIiwiZmluZEluZGV4Iiwibm9kZSIsImdldExpbmVEaWZmZXJlbmNlIiwibmV4dE5vZGUiLCJsb2MiLCJzdGFydCIsImxpbmUiLCJlbmQiLCJpc0NsYXNzV2l0aERlY29yYXRvciIsImRlY29yYXRvcnMiLCJsZW5ndGgiLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsImRvY3MiLCJ1c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V9ESUZGRVJFTkNFKSB7XG4gICAgICAgIGxldCBjb2x1bW4gPSBub2RlLmxvYy5zdGFydC5jb2x1bW5cblxuICAgICAgICBpZiAobm9kZS5sb2Muc3RhcnQubGluZSAhPT0gbm9kZS5sb2MuZW5kLmxpbmUpIHtcbiAgICAgICAgICBjb2x1bW4gPSAwXG4gICAgICAgIH1cblxuICAgICAgICBjb250ZXh0LnJlcG9ydCh7XG4gICAgICAgICAgbG9jOiB7XG4gICAgICAgICAgICBsaW5lOiBub2RlLmxvYy5lbmQubGluZSxcbiAgICAgICAgICAgIGNvbHVtbixcbiAgICAgICAgICB9LFxuICAgICAgICAgIG1lc3NhZ2U6IGBFeHBlY3RlZCAke29wdGlvbnMuY291bnR9IGVtcHR5IGxpbmUke29wdGlvbnMuY291bnQgPiAxID8gJ3MnIDogJyd9IFxcXG5hZnRlciAke3R5cGV9IHN0YXRlbWVudCBub3QgZm9sbG93ZWQgYnkgYW5vdGhlciAke3R5cGV9LmAsXG4gICAgICAgICAgZml4OiBmaXhlciA9PiBmaXhlci5pbnNlcnRUZXh0QWZ0ZXIoXG4gICAgICAgICAgICBub2RlLFxuICAgICAgICAgICAgJ1xcbicucmVwZWF0KEVYUEVDVEVEX0xJTkVfRElGRkVSRU5DRSAtIGxpbmVEaWZmZXJlbmNlKVxuICAgICAgICAgICksXG4gICAgICAgIH0pXG4gICAgICB9XG4gICAgfVxuXG4gICAgZnVuY3Rpb24gaW5jcmVtZW50TGV2ZWwoKSB7XG4gICAgICBsZXZlbCsrXG4gICAgfVxuICAgIGZ1bmN0aW9uIGRlY3JlbWVudExldmVsKCkge1xuICAgICAgbGV2ZWwtLVxuICAgIH1cblxuICAgIHJldHVybiB7XG4gICAgICBJbXBvcnREZWNsYXJhdGlvbjogZnVuY3Rpb24gKG5vZGUpIHtcbiAgICAgICAgY29uc3QgeyBwYXJlbnQgfSA9IG5vZGVcbiAgICAgICAgY29uc3Qgbm9kZVBvc2l0aW9uID0gcGFyZW50LmJvZHk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