odin-js-fundamentals-part-4/node_modules/eslint-plugin-import/lib/rules/no-self-import.js

39 lines
4.2 KiB
JavaScript

'use strict';
var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
function isImportingSelf(context, node, requireName) {
var filePath = context.getPhysicalFilename ? context.getPhysicalFilename() : 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: node,
message: 'Module imports itself.' });
}
} /**
* @fileOverview Forbids a module from importing itself
* @author Gio d'Amelio
*/module.exports = { meta: {
type: 'problem',
docs: {
category: 'Static analysis',
description: 'Forbid a module from importing itself.',
recommended: true,
url: (0, _docsUrl2['default'])('no-self-import') },
schema: [] },
create: function () {function create(context) {
return (0, _moduleVisitor2['default'])(function (source, node) {
isImportingSelf(context, node, source.value);
}, { commonjs: true });
}return create;}() };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1zZWxmLWltcG9ydC5qcyJdLCJuYW1lcyI6WyJpc0ltcG9ydGluZ1NlbGYiLCJjb250ZXh0Iiwibm9kZSIsInJlcXVpcmVOYW1lIiwiZmlsZVBhdGgiLCJnZXRQaHlzaWNhbEZpbGVuYW1lIiwiZ2V0RmlsZW5hbWUiLCJyZXBvcnQiLCJtZXNzYWdlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwiZGVzY3JpcHRpb24iLCJyZWNvbW1lbmRlZCIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsInNvdXJjZSIsInZhb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