101 lines
8.9 KiB
JavaScript
101 lines
8.9 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: {
|
|
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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25vLXJlc3RyaWN0ZWQtcGF0aHMuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwidHlwZSIsInByb3BlcnRpZXMiLCJ6b25lcyIsIm1pbkl0ZW1zIiwiaXRlbXMiLCJ0YXJnZXQiLCJmcm9tIiwiYWRkaXRpb25hbFByb3BlcnRpZXMiLCJiYXNlUGF0aCIsImNyZWF0ZSIsIm5vUmVzdHJpY3RlZFBhdGhzIiwiY29udGV4dCIsIm9wdGlvbnMiLCJyZXN0cmljdGVkUGF0aHMiLCJwcm9jZXN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sdXRlSW1wb3J0UGF0aCA9IHJlc29sdmUoaW1wb3J0UGF0aCwgY29udGV4dClcblxuICAgICAgICBpZiAoIWFic29sdXRlSW1wb3J0UGF0aCkge1xuICAgICAgICAgIHJldHVyblxuICAgICAgICB9XG5cbiAgICAgICAgbWF0Y2hpbmdab25lcy5mb3JFYWNoKCh6b25lKSA9PiB7XG4gICAgICAgICAgY29uc3QgYWJzb2x1dGVGcm9tID0gcGF0aC5yZXNvbHZlKGJhc2VQYXRoLCB6b25lLmZyb20pXG5cbiAgICAgICAgICBpZiAoY29udGFpbnNQYXRoKGFic29sdXRlSW1wb3J0UGF0aCwgYWJzb2x1dGVGcm9tKSkge1xuICAgICAgICAgICAgY29udGV4dC5yZXBvcnQoe1xuICAgICAgICAgICAgICBub2RlLFxuICAgICAgICAgICAgICBtZXNzYWdlOiBgVW5leHBlY3RlZCBwYXRoIFwiJHtpbXBvcnRQYXRofVwiIGltcG9ydGVkIGluIHJlc3RyaWN0ZWQgem9uZS5gLFxuICAgICAgICAgICAgfSlcbiAgICAgICAgICB9XG4gICAgICAgIH0pXG4gICAgfVxuXG4gICAgcmV0dXJuIHtcbiAgICAgIEltcG9ydERlY2xhcmF0aW9uKG5vZGUpIHtcbiAgICAgICAgY2hlY2tGb3JSZXN0cmljdGVkSW1wb3J0UGF0aChub2RlLnNvdXJjZS52YWx1ZSwgbm9kZS5zb3VyY2UpXG4gICAgICB9LFxuICAgICAgQ2FsbEV4cHJlc3Npb24obm9kZSkge1xuICAgICAgICBpZiAoaXNTdGF0aWNSZXF1aXJlKG5vZGUpKSB7XG4gICAgICAgICAgY29uc3QgWyBmaXJzdEFyZ3VtZW50IF0gPSBub2RlLmFyZ3VtZW50c1xuXG4gICAgICAgICAgY2hlY2tGb3JSZXN0cmljdGVkSW1wb3J0UGF0aChmaXJzdEFyZ3VtZW50LnZhbHVlLCBmaXJzdEFyZ3VtZW50KVxuICAgICAgICB9XG4gICAgICB9LFxuICAgIH1cbiAgfSxcbn1cbiJdfQ==
|