mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
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')
|
|
},
|
|
fixable: 'whitespace',
|
|
schema: [{
|
|
'type': 'object',
|
|
'properties': {
|
|
'count': {
|
|
'type': 'integer',
|
|
'minimum': 1
|
|
}
|
|
},
|
|
'additionalProperties': false
|
|
}]
|
|
},
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uZXdsaW5lLWFmdGVyLWltcG9ydC5qcyJdLCJuYW1lcyI6WyJsb2ciLCJjb250YWluc05vZGVPckVxdWFsIiwib3V0ZXJOb2RlIiwiaW5uZXJOb2RlIiwicmFuZ2UiLCJnZXRTY29wZUJvZHkiLCJzY29wZSIsImJsb2NrIiwidHlwZSIsImJvZHkiLCJmaW5kTm9kZUluZGV4SW5TY29wZUJvZHkiLCJub2RlVG9GaW5kIiwiZmluZEluZGV4Iiwibm9kZSIsImdldExpbmVEaWZmZXJlbmNlIiwibmV4dE5vZGUiLCJsb2MiLCJzdGFydCIsImxpbmUiLCJlbmQiLCJpc0NsYXNzV2l0aERlY29yYXRvciIsImRlY29yYXRvcnMiLCJsZW5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