102 lines
9.0 KiB
JavaScript
102 lines
9.0 KiB
JavaScript
|
'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);
|
||
|
|
||
|
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' }
|
||
|
},
|
||
|
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 checkForRestrictedImportPath(importPath, node) {
|
||
|
const absoluteImportPath = (0, _resolve2.default)(importPath, context);
|
||
|
|
||
|
if (!absoluteImportPath) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
matchingZones.forEach(zone => {
|
||
|
const absoluteFrom = _path2.default.resolve(basePath, zone.from);
|
||
|
|
||
|
if ((0, _containsPath2.default)(absoluteImportPath, absoluteFrom)) {
|
||
|
context.report({
|
||
|
node,
|
||
|
message: `Unexpected path "${importPath}" imported in restricted zone.`
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZXN0cmljdGVkLXBhdGhzLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1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G4gICAgfSxcblxuICAgIHNjaGVtYTogW1xuICAgICAge1xuICAgICAgICB0eXBlOiAnb2JqZWN0JyxcbiAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgIHpvbmVzOiB7XG4gICAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgICAgbWluSXRlbXM6IDEsXG4gICAgICAgICAgICBpdGVtczoge1xuICAgICAgICAgICAgICB0eXBlOiAnb2JqZWN0JyxcbiAgICAgICAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgICAgICAgIHRhcmdldDogeyB0eXBlOiAnc3RyaW5nJyB9LFxuICAgICAgICAgICAgICAgIGZyb206IHsgdHlwZTogJ3N0cmluZycgfSxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgYWRkaXRpb25hbFByb3BlcnRpZXM6IGZhbHNlLFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIGJhc2VQYXRoOiB7IHR5cGU6ICdzdHJpbmcnIH0sXG4gICAgICAgIH0sXG4gICAgICAgIGFkZGl0aW9uYWxQcm9wZXJ0aWVzOiBmYWxzZSxcbiAgICAgIH0sXG4gICAgXSxcbiA
|