no-self-import.js 3.8 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. const filePath = 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,
  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 (context) {
  24. return (0, _moduleVisitor2.default)((source, node) => {
  25. isImportingSelf(context, node, source.value);
  26. }, { commonjs: true });
  27. } };
  28. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1zZWxmLWltcG9ydC5qcyJdLCJuYW1lcyI6WyJpc0ltcG9ydGluZ1NlbGYiLCJjb250ZXh0Iiwibm9kZSIsInJlcXVpcmVOYW1lIiwiZmlsZVBhdGgiLCJnZXRGaWxlbmFtZSIsInJlcG9ydCIsIm1lc3NhZ2UiLCJtb2R1bGUiLCJleHBvcnRzIiwibWV0YSIsInR5cGUiLCJkb2NzIiwiZGVzY3JpcHRpb24iLCJyZWNvbW1lbmRlZCIsInVybCIsInNjaGVtYSIsImNyZWF0ZSIsInNvdXJjZSIsInZhbHVlIiwiY29tbW9uanMiXSwibWFwcGluZ3MiOiI7Ozs7O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