123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 'use strict';var _path = require('path');var _path2 = _interopRequireDefault(_path);
- var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
- var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
- var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);
- var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
- const containsPath = (filepath, target) => {
- const relative = _path2.default.relative(target, filepath);
- return relative === '' || !relative.startsWith('..');
- };
- module.exports = {
- meta: {
- type: 'problem',
- docs: {
- url: (0, _docsUrl2.default)('no-restricted-paths') },
- schema: [
- {
- type: 'object',
- properties: {
- zones: {
- type: 'array',
- minItems: 1,
- items: {
- type: 'object',
- properties: {
- target: { type: 'string' },
- from: { type: 'string' },
- except: {
- type: 'array',
- items: {
- type: 'string' },
- uniqueItems: true },
- message: { type: 'string' } },
- additionalProperties: false } },
- basePath: { type: 'string' } },
- additionalProperties: false }] },
- create: function noRestrictedPaths(context) {
- const options = context.options[0] || {};
- const restrictedPaths = options.zones || [];
- const basePath = options.basePath || process.cwd();
- const currentFilename = context.getFilename();
- const matchingZones = restrictedPaths.filter(zone => {
- const targetPath = _path2.default.resolve(basePath, zone.target);
- return containsPath(currentFilename, targetPath);
- });
- function isValidExceptionPath(absoluteFromPath, absoluteExceptionPath) {
- const relativeExceptionPath = _path2.default.relative(absoluteFromPath, absoluteExceptionPath);
- return (0, _importType2.default)(relativeExceptionPath, context) !== 'parent';
- }
- function reportInvalidExceptionPath(node) {
- context.report({
- node,
- message: 'Restricted path exceptions must be descendants of the configured `from` path for that zone.' });
- }
- const zoneExceptions = matchingZones.map(zone => {
- const exceptionPaths = zone.except || [];
- const absoluteFrom = _path2.default.resolve(basePath, zone.from);
- const absoluteExceptionPaths = exceptionPaths.map(exceptionPath => _path2.default.resolve(absoluteFrom, exceptionPath));
- const hasValidExceptionPaths = absoluteExceptionPaths.
- every(absoluteExceptionPath => isValidExceptionPath(absoluteFrom, absoluteExceptionPath));
- return {
- absoluteExceptionPaths,
- hasValidExceptionPaths };
- });
- function checkForRestrictedImportPath(importPath, node) {
- const absoluteImportPath = (0, _resolve2.default)(importPath, context);
- if (!absoluteImportPath) {
- return;
- }
- matchingZones.forEach((zone, index) => {
- const absoluteFrom = _path2.default.resolve(basePath, zone.from);
- if (!containsPath(absoluteImportPath, absoluteFrom)) {
- return;
- }var _zoneExceptions$index =
- zoneExceptions[index];const hasValidExceptionPaths = _zoneExceptions$index.hasValidExceptionPaths,absoluteExceptionPaths = _zoneExceptions$index.absoluteExceptionPaths;
- if (!hasValidExceptionPaths) {
- reportInvalidExceptionPath(node);
- return;
- }
- const pathIsExcepted = absoluteExceptionPaths.
- some(absoluteExceptionPath => containsPath(absoluteImportPath, absoluteExceptionPath));
- if (pathIsExcepted) {
- return;
- }
- context.report({
- node,
- message: `Unexpected path "{{importPath}}" imported in restricted zone.${zone.message ? ` ${zone.message}` : ''}`,
- data: { importPath } });
- });
- }
- return (0, _moduleVisitor2.default)(source => {
- checkForRestrictedImportPath(source.value, source);
- }, { commonjs: true });
- } };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZXN0cmljdGVkLXBhdGhzLmpzIl0sIm5hbWVzIjpbImNvbnRhaW5zUGF0aCIsImZpbGVwYXRoIiwidGFyZ2V0IiwicmVsYXRpdmUiLCJwYXRoIiwic3RhcnRzV2l0aCIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aWVzIiw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XBhdGhzJyksXG4gICAgfSxcblxuICAgIHNjaGVtYTogW1xuICAgICAge1xuICAgICAgICB0eXBlOiAnb2JqZWN0JyxcbiAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgIHpvbmVzOiB7XG4gICAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgICAgbWluSXRlbXM6IDEsXG4gICAgICAgICAgICBpdGVtczoge1xuICAgICAgICAgICAgICB0eXBlOiAnb2JqZWN0JyxcbiAgICAgICAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgICAgICAgIHRhcmdldDogeyB0eXBlOiAnc3RyaW5nJyB9LFxuICAgICAgICAgICAgICAgIGZyb206IHsgdHlwZTogJ3N0cmluZycgfSxcbiAgICAgICAgICAgICAgICBleGNlcHQ6IHtcbiAgICAgICAgICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgICAgICAgICBpdGVtczoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiAnc3RyaW5nJyxcbiAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICB1bmlxdWVJdGVtczogdHJ1ZSxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIG1lc3NhZ2U6IHsgdHlwZTogJ3N0cmluZycgfSxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgYWRkaXRpb25hbFByb3BlcnRpZXM6IGZhbHNlLFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIGJhc2VQYXRoOiB7IHR5cGU6ICdzdHJpbmcnIH0sXG4gICAgICAgIH0sXG4gICAgICAgIGFkZGl0aW9uYWxQcm9wZXJ0aWVzOiBmYWxzZSxcbiAgICAgIH0sXG4gICAgXSxcbiAgfSxcblxuICBjcmVhdGU6IGZ1bmN0aW9uIG5vUmVzdHJpY3RlZFBhdGhzKGNvbnRleHQpIHtcbiAgICBjb25zdCBvcHRpb25zID0gY29udGV4dC5vcHRp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