bigint-crypto-utils/node_modules/eslint-plugin-import/lib/rules/no-self-import.js

56 lines
4.4 KiB
JavaScript
Raw Normal View History

'use strict';
var _resolve = require('eslint-module-utils/resolve');
var _resolve2 = _interopRequireDefault(_resolve);
var _staticRequire = require('../core/staticRequire');
var _staticRequire2 = _interopRequireDefault(_staticRequire);
var _docsUrl = require('../docsUrl');
var _docsUrl2 = _interopRequireDefault(_docsUrl);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isImportingSelf(context, node, requireName) {
const filePath = context.getFilename();
// If the input is from stdin, this test can't fail
if (filePath !== '<text>' && filePath === (0, _resolve2.default)(requireName, context)) {
context.report({
node,
message: 'Module imports itself.'
});
}
} /**
* @fileOverview Forbids a module from importing itself
* @author Gio d'Amelio
*/
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Forbid a module from importing itself',
recommended: true,
url: (0, _docsUrl2.default)('no-self-import')
},
schema: []
},
create: function (context) {
return {
ImportDeclaration(node) {
isImportingSelf(context, node, node.source.value);
},
CallExpression(node) {
if ((0, _staticRequire2.default)(node)) {
isImportingSelf(context, node, node.arguments[0].value);
}
}
};
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1zZWxmLWltcG9ydC5qcyJdLCJuYW1lcyI6WyJpc0ltcG9ydGluZ1NlbGYiLCJjb250ZXh0Iiwibm9kZSIsInJlcXVpcmVOYW1lIiwiZmlsZVBhdGgiLCJnZXRGaWxlbmFtZSIsInJlcG9ydCIsIm1lc3NhZ2UiLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwiZGVzY3JpcHRpb24iLCJyZWNvbW1lbmRlZCIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsIkltcG9ydERlY2xhcmF0aW9uIiwic291cmNlIiwidmFsdWUiLCJDYWxsRXhwcmVzc2lvbiIsImFyZ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