webhook-action/node_modules/eslint-plugin-import/lib/rules/no-restricted-paths.js

125 lines
14 KiB
JavaScript
Raw Normal View History

'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 },
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 (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.${zone.message ? ` ${zone.message}` : ''}`,
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZXN0cmljdGVkLXBhdGhzLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aWVzIiwiem9uZXMiLCJt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