katoikia-app/web-ui/web-react/node_modules/eslint-plugin-import/lib/rules/no-restricted-paths.js

144 lines
14 KiB
JavaScript
Raw Normal View History

2022-07-06 04:15:11 +00:00
'use strict';
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _containsPath = require('contains-path');
var _containsPath2 = _interopRequireDefault(_containsPath);
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _resolve = require('eslint-module-utils/resolve');
var _resolve2 = _interopRequireDefault(_resolve);
var _staticRequire = require('../core/staticRequire');
var _staticRequire2 = _interopRequireDefault(_staticRequire);
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 }; }
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
}
},
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 (0, _containsPath2.default)(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.'
});
}
function checkForRestrictedImportPath(importPath, node) {
const absoluteImportPath = (0, _resolve2.default)(importPath, context);
if (!absoluteImportPath) {
return;
}
matchingZones.forEach(zone => {
const exceptionPaths = zone.except || [];
const absoluteFrom = _path2.default.resolve(basePath, zone.from);
if (!(0, _containsPath2.default)(absoluteImportPath, absoluteFrom)) {
return;
}
const absoluteExceptionPaths = exceptionPaths.map(exceptionPath => _path2.default.resolve(absoluteFrom, exceptionPath));
const hasValidExceptionPaths = absoluteExceptionPaths.every(absoluteExceptionPath => isValidExceptionPath(absoluteFrom, absoluteExceptionPath));
if (!hasValidExceptionPaths) {
reportInvalidExceptionPath(node);
return;
}
const pathIsExcepted = absoluteExceptionPaths.some(absoluteExceptionPath => (0, _containsPath2.default)(absoluteImportPath, absoluteExceptionPath));
if (pathIsExcepted) {
return;
}
context.report({
node,
message: `Unexpected path "{{importPath}}" imported in restricted zone.`,
data: { importPath }
});
});
}
return {
ImportDeclaration(node) {
checkForRestrictedImportPath(node.source.value, node.source);
},
CallExpression(node) {
if ((0, _staticRequire2.default)(node)) {
var _node$arguments = _slicedToArray(node.arguments, 1);
const firstArgument = _node$arguments[0];
checkForRestrictedImportPath(firstArgument.value, firstArgument);
}
}
};
}
};
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZXN0cmljdGVkLXBhdGhzLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aW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