mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
128 lines
15 KiB
JavaScript
128 lines
15 KiB
JavaScript
'use strict';var _path = require('path');var _path2 = _interopRequireDefault(_path);
|
|
|
|
var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
|
|
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
|
|
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 };}
|
|
|
|
var containsPath = function containsPath(filepath, target) {
|
|
var relative = _path2['default'].relative(target, filepath);
|
|
return relative === '' || !relative.startsWith('..');
|
|
};
|
|
|
|
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 () {function noRestrictedPaths(context) {
|
|
var options = context.options[0] || {};
|
|
var restrictedPaths = options.zones || [];
|
|
var basePath = options.basePath || process.cwd();
|
|
var currentFilename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
|
|
var matchingZones = restrictedPaths.filter(function (zone) {
|
|
var targetPath = _path2['default'].resolve(basePath, zone.target);
|
|
|
|
return containsPath(currentFilename, targetPath);
|
|
});
|
|
|
|
function isValidExceptionPath(absoluteFromPath, absoluteExceptionPath) {
|
|
var relativeExceptionPath = _path2['default'].relative(absoluteFromPath, absoluteExceptionPath);
|
|
|
|
return (0, _importType2['default'])(relativeExceptionPath, context) !== 'parent';
|
|
}
|
|
|
|
function reportInvalidExceptionPath(node) {
|
|
context.report({
|
|
node: node,
|
|
message: 'Restricted path exceptions must be descendants of the configured `from` path for that zone.' });
|
|
|
|
}
|
|
|
|
var zoneExceptions = matchingZones.map(function (zone) {
|
|
var exceptionPaths = zone.except || [];
|
|
var absoluteFrom = _path2['default'].resolve(basePath, zone.from);
|
|
var absoluteExceptionPaths = exceptionPaths.map(function (exceptionPath) {return _path2['default'].resolve(absoluteFrom, exceptionPath);});
|
|
var hasValidExceptionPaths = absoluteExceptionPaths.
|
|
every(function (absoluteExceptionPath) {return isValidExceptionPath(absoluteFrom, absoluteExceptionPath);});
|
|
|
|
return {
|
|
absoluteExceptionPaths: absoluteExceptionPaths,
|
|
hasValidExceptionPaths: hasValidExceptionPaths };
|
|
|
|
});
|
|
|
|
function checkForRestrictedImportPath(importPath, node) {
|
|
var absoluteImportPath = (0, _resolve2['default'])(importPath, context);
|
|
|
|
if (!absoluteImportPath) {
|
|
return;
|
|
}
|
|
|
|
matchingZones.forEach(function (zone, index) {
|
|
var absoluteFrom = _path2['default'].resolve(basePath, zone.from);
|
|
|
|
if (!containsPath(absoluteImportPath, absoluteFrom)) {
|
|
return;
|
|
}var _zoneExceptions$index =
|
|
|
|
zoneExceptions[index],hasValidExceptionPaths = _zoneExceptions$index.hasValidExceptionPaths,absoluteExceptionPaths = _zoneExceptions$index.absoluteExceptionPaths;
|
|
|
|
if (!hasValidExceptionPaths) {
|
|
reportInvalidExceptionPath(node);
|
|
return;
|
|
}
|
|
|
|
var pathIsExcepted = absoluteExceptionPaths.
|
|
some(function (absoluteExceptionPath) {return containsPath(absoluteImportPath, absoluteExceptionPath);});
|
|
|
|
if (pathIsExcepted) {
|
|
return;
|
|
}
|
|
|
|
context.report({
|
|
node: node,
|
|
message: 'Unexpected path "{{importPath}}" imported in restricted zone.' + (zone.message ? ' ' + String(zone.message) : ''),
|
|
data: { importPath: importPath } });
|
|
|
|
});
|
|
}
|
|
|
|
return (0, _moduleVisitor2['default'])(function (source) {
|
|
checkForRestrictedImportPath(source.value, source);
|
|
}, { commonjs: true });
|
|
}return noRestrictedPaths;}() };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZXN0cmljdGVkLXBhdGhzLmpzIl0sIm5hbWVzIjpbImNvbnRhaW5zUGF0aCIsImZpbGVwYXRoIiwidGFyZ2V0IiwicmVsYXRpdmUiLCJwYXRoIiwic3RhcnRzV2l0aCIsIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aWVzIiwiem9uZXMiLCJtaW5JdGVtcyIsIml0ZW1zIiwiZnJvbSIsImV4Y2VwdCIsInVuaXF1ZUl0ZW1zIiwibWVzc2FnZSIsImFkZGl0aW9uYWxQcm9wZXJ0aWVzIiwiYmFzZVBhdGgiLCJjcmVhdGUiLCJub1Jlc3RyaWN0ZWRQYXRocyIsImNvbnRleHQiLCJvcHRpb25zIiwicmVzdHJpY3RlZFBhdGhzIiwicHJvY2VzcyIsImN3ZCIsImN1cnJlbnRGaWxlbmFtZSIsImdldFBoeXNpY2FsRmlsZW5hbWUiLCJnZXRGaWxlbmFtZSIsIm1hdGNoaW5nWm9uZXMiLCJmaWx0ZXIiLCJ6b25lIiwidGFyZ2V0UGF0aCIsInJlc29sdmUiLCJpc1ZhbGlkRXhjZXB0aW9uUGF0aCIsImFic29sdXRlRnJvbVBhdGgiLCJhYnNvbHV0ZUV4Y2VwdGlvblBhdGgiLCJyZWxhdGl2ZUV4Y2VwdGlvblBhdGgiLCJyZXBvcnRJb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hcmdldDogeyB0eXBlOiAnc3RyaW5nJyB9LFxuICAgICAgICAgICAgICAgIGZyb206IHsgdHlwZTogJ3N0cmluZycgfSxcbiAgICAgICAgICAgICAgICBleGNlcHQ6IHtcbiAgICAgICAgICAgICAgICAgIHR5cGU6ICdhcnJheScsXG4gICAgICAgICAgICAgICAgICBpdGVtczoge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiAnc3RyaW5nJyxcbiAgICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAgICB1bmlxdWVJdGVtczogdHJ1ZSxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgICAgIG1lc3NhZ2U6IHsgdHlwZTogJ3N0cmluZycgfSxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgYWRkaXRpb25hbFByb3BlcnRpZXM6IGZhbHNlLFxuICAgICAgICAgICAgfSxcbiAgICAgICAgICB9LFxuICAgICAgICAgIGJhc2VQYXRoOiB7IHR5cGU6ICdzdHJpbmcnIH0sXG4gICAgICAgIH0sXG4gICAgICAgIGFkZGl0aW9uYWxQcm9wZXJ0aWVzOiBmYWxzZSxcbiAgICAgIH0sXG4gICAgXSxcbiAgfSxcblxuICBjcmVhdGU6IGZ1bmN0aW9uIG5vUmVzdHJpY3RlZFBhdGhzKGNvbnRleHQpIHtcbiAgICBjb25zdCBvcHRpb25zID0gY29udGV4dC5vcHRpb25zWzBdIHx8IHt9O1xuICAgIGNvbnN0IHJlc3RyaWN0ZWRQYXRocyA9IG9wdGlvbnMuem9uZXMgfHwgW107XG4gICAgY29uc3QgYmFzZVBhdGggPSBvcHRpb25zLmJhc2VQYXRoIHx8IHByb2Nlc3MuY3dkKCk7XG4gICAgY29uc3QgY3VycmVudEZpbGVuYW1lID0gY29udGV4dC5nZXRQaHlzaWNhbEZpbGVuYW1lID8gY29udGV4dC5nZXRQaHlzaWNhbEZpbGVuYW1lKCkgOiBjb250ZXh0LmdldEZpbGVuYW1lKCk7XG4gICAgY29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