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,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInJ1bGVzL25vLXJlc3RyaWN0ZWQtcGF0aHMuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJkb2NzIiwidXJsIiwic2NoZW1hIiwidHlwZSIsInByb3BlcnRpZX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Anb2JqZWN0JyxcbiAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgIHpvbmVzOiB7XG4gICAgICAgICAgICB0eXBlOiAnYXJyYXknLFxuICAgICAgICAgICAgbWluSXRlbXM6IDEsXG4gICAgICAgICAgICBpdGVtczoge1xuICAgICAgICAgICAgICB0eXBlOiAnb2JqZWN0JyxcbiAgICAgICAgICAgICAgcHJvcGVydGllczoge1xuICAgICAgICAgICAgICAgIHRhcmdldDogeyB0eXBlOiAnc3RyaW5nJyB9LFxuICAgICAgICAgICAgICAgIGZyb206IHsgdHlwZTogJ3N0cmluZycgfSxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgYWRkaXRpb25hbFByb3BlcnRpZXM6IGZhbHNlLFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIGJhc2VQYXRoOiB7IHR5cGU6ICdzdHJpbmcnIH0sXG4gICAgICAgIH0sXG4gICAgICAgIGFkZGl0aW9uYWxQcm9wZXJ0aWVzOiBmYWxzZSxcbiAgICAgIH0sXG4gICAgXSxcbiAgfSxcblxuICBjcmVhdGU6IGZ1bmN0aW9uIG5vUmVzdHJpY3RlZFBhdGh
|