no-self-import.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
  3. var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
  4. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
  5. function isImportingSelf(context, node, requireName) {
  6. var filePath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
  7. // If the input is from stdin, this test can't fail
  8. if (filePath !== '<text>' && filePath === (0, _resolve2['default'])(requireName, context)) {
  9. context.report({
  10. node: node,
  11. message: 'Module imports itself.' });
  12. }
  13. } /**
  14. * @fileOverview Forbids a module from importing itself
  15. * @author Gio d'Amelio
  16. */module.exports = { meta: {
  17. type: 'problem',
  18. docs: {
  19. category: 'Static analysis',
  20. description: 'Forbid a module from importing itself.',
  21. recommended: true,
  22. url: (0, _docsUrl2['default'])('no-self-import') },
  23. schema: [] },
  24. create: function () {function create(context) {
  25. return (0, _moduleVisitor2['default'])(function (source, node) {
  26. isImportingSelf(context, node, source.value);
  27. }, { commonjs: true });
  28. }return create;}() };
  29. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1zZWxmLWltcG9ydC5qcyJdLCJuYW1lcyI6WyJpc0ltcG9ydGluZ1NlbGYiLCJjb250ZXh0Iiwibm9kZSIsInJlcXVpcmVOYW1lIiwiZmlsZVBhdGgiLCJnZXRQaHlzaWNhbEZpbGVuYW1lIiwiZ2V0RmlsZW5hbWUiLCJyZXBvcnQiLCJtZXNzYWdlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImNhdGVnb3J5IiwiZGVzY3JpcHRpb24iL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