123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- 'use strict';var _minimatch = require('minimatch');var _minimatch2 = _interopRequireDefault(_minimatch);
- var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
- var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType);
- 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 };}
- module.exports = {
- meta: {
- type: 'suggestion',
- docs: {
- url: (0, _docsUrl2.default)('no-internal-modules') },
- schema: [
- {
- oneOf: [
- {
- type: 'object',
- properties: {
- allow: {
- type: 'array',
- items: {
- type: 'string' } } },
- additionalProperties: false },
- {
- type: 'object',
- properties: {
- forbid: {
- type: 'array',
- items: {
- type: 'string' } } },
- additionalProperties: false }] }] },
- create: function noReachingInside(context) {
- const options = context.options[0] || {};
- const allowRegexps = (options.allow || []).map(p => _minimatch2.default.makeRe(p));
- const forbidRegexps = (options.forbid || []).map(p => _minimatch2.default.makeRe(p));
- // minimatch patterns are expected to use / path separators, like import
- // statements, so normalize paths to use the same
- function normalizeSep(somePath) {
- return somePath.split('\\').join('/');
- }
- function toSteps(somePath) {
- return normalizeSep(somePath).
- split('/').
- reduce((acc, step) => {
- if (!step || step === '.') {
- return acc;
- } else if (step === '..') {
- return acc.slice(0, -1);
- } else {
- return acc.concat(step);
- }
- }, []);
- }
- // test if reaching to this destination is allowed
- function reachingAllowed(importPath) {
- return allowRegexps.some(re => re.test(importPath));
- }
- // test if reaching to this destination is forbidden
- function reachingForbidden(importPath) {
- return forbidRegexps.some(re => re.test(importPath));
- }
- function isAllowViolation(importPath) {
- const steps = toSteps(importPath);
- const nonScopeSteps = steps.filter(step => step.indexOf('@') !== 0);
- if (nonScopeSteps.length <= 1) return false;
- // before trying to resolve, see if the raw import (with relative
- // segments resolved) matches an allowed pattern
- const justSteps = steps.join('/');
- if (reachingAllowed(justSteps) || reachingAllowed(`/${justSteps}`)) return false;
- // if the import statement doesn't match directly, try to match the
- // resolved path if the import is resolvable
- const resolved = (0, _resolve2.default)(importPath, context);
- if (!resolved || reachingAllowed(normalizeSep(resolved))) return false;
- // this import was not allowed by the allowed paths, and reaches
- // so it is a violation
- return true;
- }
- function isForbidViolation(importPath) {
- const steps = toSteps(importPath);
- // before trying to resolve, see if the raw import (with relative
- // segments resolved) matches a forbidden pattern
- const justSteps = steps.join('/');
- if (reachingForbidden(justSteps) || reachingForbidden(`/${justSteps}`)) return true;
- // if the import statement doesn't match directly, try to match the
- // resolved path if the import is resolvable
- const resolved = (0, _resolve2.default)(importPath, context);
- if (resolved && reachingForbidden(normalizeSep(resolved))) return true;
- // this import was not forbidden by the forbidden paths so it is not a violation
- return false;
- }
- // find a directory that is being reached into, but which shouldn't be
- const isReachViolation = options.forbid ? isForbidViolation : isAllowViolation;
- function checkImportForReaching(importPath, node) {
- const potentialViolationTypes = ['parent', 'index', 'sibling', 'external', 'internal'];
- if (potentialViolationTypes.indexOf((0, _importType2.default)(importPath, context)) !== -1 &&
- isReachViolation(importPath))
- {
- context.report({
- node,
- message: `Reaching to "${importPath}" is not allowed.` });
- }
- }
- return (0, _moduleVisitor2.default)(source => {
- checkImportForReaching(source.value, source);
- }, { commonjs: true });
- } };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1pbnRlcm5hbC1tb2R1bGVzLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJvbmVPZiIsInByb3BlcnRpZXMiL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AgICAgICAgICAgICAgYWxsb3c6IHtcbiAgICAgICAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgICAgICAgIGl0ZW1zOiB7XG4gICAgICAgICAgICAgICAgICB0eXBlOiAnc3RyaW5nJyxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGFkZGl0aW9uYWxQcm9wZXJ0aWVzOiBmYWxzZSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIHtcbiAgICAgICAgICAgIHR5cGU6ICdvYmplY3QnLFxuICAgICAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgICAgICBmb3JiaWQ6IHtcbiAgICAgICAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgICAgICAgIGl0ZW1zOiB7XG4gICAgICAgICAgICAgICAgICB0eXBlOiAnc3RyaW5nJyxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGFkZGl0aW9uYWxQcm9wZXJ0aWVzOiBmYWxzZSxcbiAgICAgICAgICB9LFxuICAgICAgICBdLFxuICAgICAgfSxcbiAgICBdLFxuICB9LFxuXG4gIGNyZWF0ZTogZnVuY3Rpb24gbm9SZWFjaGluZ0luc2lkZShjb250ZXh0KSB7XG4gICAgY29uc3Qgb3B0aW9ucyA9IGNvbnRleHQub3B0aW9uc1swXSB8fCB7fTtcbiAgICBjb25zdCBhbGxvd1JlZ2V4cHMgPSAob3B0aW9ucy5hbGxvdyB8fCBbXSkubWFwKHAgPT4gbWluaW1hdGNoLm1ha2VSZShwKSk7XG4gICAgY29uc3QgZm9yYmlkUmVnZXhwcyA9IChvcHRpb25zLmZvcmJpZCB8fCBbXSkubWFwKHAgPT4gbWluaW1hdGNoLm1ha2VSZShwKSk7XG5cbiAgICAvLyBtaW5pbWF0Y2ggcGF0dGVybnMgYXJlIGV4cGVjdGVkIH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