mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-29 03:45:15 +00:00
184 lines
21 KiB
JavaScript
184 lines
21 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 };}
|
|
var 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;
|
|
}var
|
|
|
|
body = scope.block.body;
|
|
if (body && body.type === 'BlockStatement') {
|
|
return body.body;
|
|
}
|
|
|
|
return body;
|
|
}
|
|
|
|
function findNodeIndexInScopeBody(body, nodeToFind) {
|
|
return body.findIndex(function (node) {return 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;
|
|
}
|
|
|
|
function isExportDefaultClass(node) {
|
|
return node.type === 'ExportDefaultDeclaration' && node.declaration.type === 'ClassDeclaration';
|
|
}
|
|
|
|
function isExportNameClass(node) {
|
|
|
|
return node.type === 'ExportNamedDeclaration' && node.declaration && node.declaration.type === 'ClassDeclaration';
|
|
}
|
|
|
|
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 () {function create(context) {
|
|
var level = 0;
|
|
var requireCalls = [];
|
|
|
|
function checkForNewLine(node, nextNode, type) {
|
|
if (isExportDefaultClass(nextNode) || isExportNameClass(nextNode)) {
|
|
var classNode = nextNode.declaration;
|
|
|
|
if (isClassWithDecorator(classNode)) {
|
|
nextNode = classNode.decorators[0];
|
|
}
|
|
} else if (isClassWithDecorator(nextNode)) {
|
|
nextNode = nextNode.decorators[0];
|
|
}
|
|
|
|
var options = context.options[0] || { count: 1 };
|
|
var lineDifference = getLineDifference(node, nextNode);
|
|
var EXPECTED_LINE_DIFFERENCE = options.count + 1;
|
|
|
|
if (lineDifference < EXPECTED_LINE_DIFFERENCE) {
|
|
var 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: column },
|
|
|
|
message: 'Expected ' + String(options.count) + ' empty line' + (options.count > 1 ? 's' : '') + ' after ' + String(
|
|
type) + ' statement not followed by another ' + String(type) + '.',
|
|
fix: function () {function fix(fixer) {return fixer.insertTextAfter(
|
|
node,
|
|
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference));}return fix;}() });
|
|
|
|
|
|
}
|
|
}
|
|
|
|
function incrementLevel() {
|
|
level++;
|
|
}
|
|
function decrementLevel() {
|
|
level--;
|
|
}
|
|
|
|
function checkImport(node) {var
|
|
parent = node.parent;
|
|
var nodePosition = parent.body.indexOf(node);
|
|
var nextNode = parent.body[nodePosition + 1];
|
|
|
|
// skip "export import"s
|
|
if (node.type === 'TSImportEqualsDeclaration' && node.isExport) {
|
|
return;
|
|
}
|
|
|
|
if (nextNode && nextNode.type !== 'ImportDeclaration' && (nextNode.type !== 'TSImportEqualsDeclaration' || nextNode.isExport)) {
|
|
checkForNewLine(node, nextNode, 'import');
|
|
}
|
|
}
|
|
|
|
return {
|
|
ImportDeclaration: checkImport,
|
|
TSImportEqualsDeclaration: checkImport,
|
|
CallExpression: function () {function CallExpression(node) {
|
|
if ((0, _staticRequire2['default'])(node) && level === 0) {
|
|
requireCalls.push(node);
|
|
}
|
|
}return CallExpression;}(),
|
|
'Program:exit': function () {function ProgramExit() {
|
|
log('exit processing for', context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename());
|
|
var scopeBody = getScopeBody(context.getScope());
|
|
log('got scope:', scopeBody);
|
|
|
|
requireCalls.forEach(function (node, index) {
|
|
var nodePosition = findNodeIndexInScopeBody(scopeBody, node);
|
|
log('node position in scope:', nodePosition);
|
|
|
|
var statementWithRequireCall = scopeBody[nodePosition];
|
|
var nextStatement = scopeBody[nodePosition + 1];
|
|
var nextRequireCall = requireCalls[index + 1];
|
|
|
|
if (nextRequireCall && containsNodeOrEqual(statementWithRequireCall, nextRequireCall)) {
|
|
return;
|
|
}
|
|
|
|
if (nextStatement && (
|
|
!nextRequireCall || !containsNodeOrEqual(nextStatement, nextRequireCall))) {
|
|
|
|
checkForNewLine(statementWithRequireCall, nextStatement, 'require');
|
|
}
|
|
});
|
|
}return ProgramExit;}(),
|
|
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': decrement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