no-self-import.js 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. description: 'Forbid a module from importing itself',
  20. recommended: true,
  21. url: (0, _docsUrl2['default'])('no-self-import') },
  22. schema: [] },
  23. create: function () {function create(context) {
  24. return (0, _moduleVisitor2['default'])(function (source, node) {
  25. isImportingSelf(context, node, source.value);
  26. }, { commonjs: true });
  27. }return create;}() };
  28. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1zZWxmLWltcG9ydC5qcyJdLCJuYW1lcyI6WyJpc0ltcG9ydGluZ1NlbGYiLCJjb250ZXh0Iiwibm9kZSIsInJlcXVpcmVOYW1lIiwiZmlsZVBhdGgiLCJnZXRQaHlzaWNhbEZpbGVuYW1lIiwiZ2V0RmlsZW5hbWUiLCJyZXBvcnQiLCJtZXNzYWdlIiwibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsImRlc2NyaXB0aW9uIiwicmVjb21tZW5kZWQiLCJ1cmwiLCJz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