123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- '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: {
- category: 'Static analysis',
- description: 'Forbid importing the submodules of other modules.',
- url: (0, _docsUrl2['default'])('no-internal-modules') },
- schema: [
- {
- anyOf: [
- {
- type: 'object',
- properties: {
- allow: {
- type: 'array',
- items: {
- type: 'string' } } },
- additionalProperties: false },
- {
- type: 'object',
- properties: {
- forbid: {
- type: 'array',
- items: {
- type: 'string' } } },
- additionalProperties: false }] }] },
- create: function () {function noReachingInside(context) {
- var options = context.options[0] || {};
- var allowRegexps = (options.allow || []).map(function (p) {return _minimatch2['default'].makeRe(p);});
- var forbidRegexps = (options.forbid || []).map(function (p) {return _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('/').
- filter(function (step) {return step && step !== '.';}).
- reduce(function (acc, step) {
- if (step === '..') {
- return acc.slice(0, -1);
- }
- return acc.concat(step);
- }, []);
- }
- // test if reaching to this destination is allowed
- function reachingAllowed(importPath) {
- return allowRegexps.some(function (re) {return re.test(importPath);});
- }
- // test if reaching to this destination is forbidden
- function reachingForbidden(importPath) {
- return forbidRegexps.some(function (re) {return re.test(importPath);});
- }
- function isAllowViolation(importPath) {
- var steps = toSteps(importPath);
- var nonScopeSteps = steps.filter(function (step) {return 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
- var justSteps = steps.join('/');
- if (reachingAllowed(justSteps) || reachingAllowed('/' + String(justSteps))) {return false;}
- // if the import statement doesn't match directly, try to match the
- // resolved path if the import is resolvable
- var 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) {
- var steps = toSteps(importPath);
- // before trying to resolve, see if the raw import (with relative
- // segments resolved) matches a forbidden pattern
- var justSteps = steps.join('/');
- if (reachingForbidden(justSteps) || reachingForbidden('/' + String(justSteps))) {return true;}
- // if the import statement doesn't match directly, try to match the
- // resolved path if the import is resolvable
- var 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
- var isReachViolation = options.forbid ? isForbidViolation : isAllowViolation;
- function checkImportForReaching(importPath, node) {
- var potentialViolationTypes = ['parent', 'index', 'sibling', 'external', 'internal'];
- if (
- potentialViolationTypes.indexOf((0, _importType2['default'])(importPath, context)) !== -1 &&
- isReachViolation(importPath))
- {
- context.report({
- node: node,
- message: 'Reaching to "' + String(importPath) + '" is not allowed.' });
- }
- }
- return (0, _moduleVisitor2['default'])(
- function (source) {
- checkImportForReaching(source.value, source);
- },
- { commonjs: true });
- }return noReachingInside;}() };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1pbnRlcm5hbC1tb2R1bGVzLmpzIl0sIm5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ltcG9ydCBkb2NzVXJsIGZyb20gJy4uL2RvY3NVcmwnO1xuXG5tb2R1bGUuZXhwb3J0cyA9IHtcbiAgbWV0YToge1xuICAgIHR5cGU6ICdzdWdnZXN0aW9uJyxcbiAgICBkb2NzOiB7XG4gICAgICBjYXRlZ29yeTogJ1N0YXRpYyBhbmFseXNpcycsXG4gICAgICBkZXNjcmlwdGlvbjogJ0ZvcmJpZCBpbXBvcnRpbmcgdGhlIHN1Ym1vZHVsZXMgb2Ygb3RoZXIgbW9kdWxlcy4nLFxuICAgICAgdXJsOiBkb2NzVXJsKCduby1pbnRlcm5hbC1tb2R1bGVzJyksXG4gICAgfSxcblxuICAgIHNjaGVtYTogW1xuICAgICAge1xuICAgICAgICBhbnlPZjogW1xuICAgICAgICAgIHtcbiAgICAgICAgICAgIHR5cGU6ICdvYmplY3QnLFxuICAgICAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgICAgICBhbGxvdzoge1xuICAgICAgICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgICAgICAgaXRlbXM6IHtcbiAgICAgICAgICAgICAgICAgIHR5cGU6ICdzdHJpbmcnLFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgYWRkaXRpb25hbFByb3BlcnRpZXM6IGZhbHNlLFxuICAgICAgICAgIH0sXG4gICAgICAgICAge1xuICAgICAgICAgICAgdHlwZTogJ29iamVjdCcsXG4gICAgICAgICAgICBwcm9wZXJ0aWVzOiB7XG4gICAgICAgICAgICAgIGZvcmJpZDoge1xuICAgICAgICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgICAgICAgaXRlbXM6IHtcbiAgICAgICAgICAgICAgICAgIHR5cGU6ICdzdHJpbmcnLFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgYWRkaXRpb25hbFByb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