mirror of
https://github.com/joelwmale/webhook-action.git
synced 2024-12-02 04:15:23 +01:00
140 lines
No EOL
16 KiB
JavaScript
140 lines
No EOL
16 KiB
JavaScript
'use strict';var _minimatch = require('minimatch');var _minimatch2 = _interopRequireDefault(_minimatch);
|
|
|
|
var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
|
|
var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType);
|
|
var _moduleVisitor = require('eslint-module-utils/moduleVisitor');var _moduleVisitor2 = _interopRequireDefault(_moduleVisitor);
|
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2['default'])('no-internal-modules') },
|
|
|
|
|
|
schema: [
|
|
{
|
|
oneOf: [
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
allow: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'string' } } },
|
|
|
|
|
|
|
|
additionalProperties: false },
|
|
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
forbid: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'string' } } },
|
|
|
|
|
|
|
|
additionalProperties: false }] }] },
|
|
|
|
|
|
|
|
|
|
|
|
|
|
create: function () {function noReachingInside(context) {
|
|
var options = context.options[0] || {};
|
|
var allowRegexps = (options.allow || []).map(function (p) {return _minimatch2['default'].makeRe(p);});
|
|
var forbidRegexps = (options.forbid || []).map(function (p) {return _minimatch2['default'].makeRe(p);});
|
|
|
|
// minimatch patterns are expected to use / path separators, like import
|
|
// statements, so normalize paths to use the same
|
|
function normalizeSep(somePath) {
|
|
return somePath.split('\\').join('/');
|
|
}
|
|
|
|
function toSteps(somePath) {
|
|
return normalizeSep(somePath).
|
|
split('/').
|
|
reduce(function (acc, step) {
|
|
if (!step || step === '.') {
|
|
return acc;
|
|
} else if (step === '..') {
|
|
return acc.slice(0, -1);
|
|
} else {
|
|
return acc.concat(step);
|
|
}
|
|
}, []);
|
|
}
|
|
|
|
// test if reaching to this destination is allowed
|
|
function reachingAllowed(importPath) {
|
|
return allowRegexps.some(function (re) {return re.test(importPath);});
|
|
}
|
|
|
|
// test if reaching to this destination is forbidden
|
|
function reachingForbidden(importPath) {
|
|
return forbidRegexps.some(function (re) {return re.test(importPath);});
|
|
}
|
|
|
|
function isAllowViolation(importPath) {
|
|
var steps = toSteps(importPath);
|
|
|
|
var nonScopeSteps = steps.filter(function (step) {return step.indexOf('@') !== 0;});
|
|
if (nonScopeSteps.length <= 1) return false;
|
|
|
|
// before trying to resolve, see if the raw import (with relative
|
|
// segments resolved) matches an allowed pattern
|
|
var justSteps = steps.join('/');
|
|
if (reachingAllowed(justSteps) || reachingAllowed('/' + String(justSteps))) return false;
|
|
|
|
// if the import statement doesn't match directly, try to match the
|
|
// resolved path if the import is resolvable
|
|
var resolved = (0, _resolve2['default'])(importPath, context);
|
|
if (!resolved || reachingAllowed(normalizeSep(resolved))) return false;
|
|
|
|
// this import was not allowed by the allowed paths, and reaches
|
|
// so it is a violation
|
|
return true;
|
|
}
|
|
|
|
function isForbidViolation(importPath) {
|
|
var steps = toSteps(importPath);
|
|
|
|
// before trying to resolve, see if the raw import (with relative
|
|
// segments resolved) matches a forbidden pattern
|
|
var justSteps = steps.join('/');
|
|
|
|
if (reachingForbidden(justSteps) || reachingForbidden('/' + String(justSteps))) return true;
|
|
|
|
// if the import statement doesn't match directly, try to match the
|
|
// resolved path if the import is resolvable
|
|
var resolved = (0, _resolve2['default'])(importPath, context);
|
|
if (resolved && reachingForbidden(normalizeSep(resolved))) return true;
|
|
|
|
// this import was not forbidden by the forbidden paths so it is not a violation
|
|
return false;
|
|
}
|
|
|
|
// find a directory that is being reached into, but which shouldn't be
|
|
var isReachViolation = options.forbid ? isForbidViolation : isAllowViolation;
|
|
|
|
function checkImportForReaching(importPath, node) {
|
|
var potentialViolationTypes = ['parent', 'index', 'sibling', 'external', 'internal'];
|
|
if (potentialViolationTypes.indexOf((0, _importType2['default'])(importPath, context)) !== -1 &&
|
|
isReachViolation(importPath))
|
|
{
|
|
context.report({
|
|
node: node,
|
|
message: 'Reaching to "' + String(importPath) + '" is not allowed.' });
|
|
|
|
}
|
|
}
|
|
|
|
return (0, _moduleVisitor2['default'])(function (source) {
|
|
checkImportForReaching(source.value, source);
|
|
}, { commonjs: true });
|
|
}return noReachingInside;}() };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1pbnRlcm5hbC1tb2R1bGVzLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJvbmVPZiIsInByb3BlcnRpZXMiLCJhbGxvdyIsIml0ZW1zIiwiYWRkaXRpb25hbFByb3BlcnRpZXMiLCJmb3JiaWQiLCJjcmVhdGUiLCJub1JlYWNoaW5nSW5zaWRlIiwiY29udGV4dCIsIm9wdGlvbnMiLCJhbGxvd1JlZ2V4cHMiLCJtYXAiLCJtaW5pbWF0Y2giLCJtYWtlUmUiLCJwIiwiZm9yYmlkUmVnZXhwcyIsIm5vcm1hbGl6ZVNlcCIsInNvbWVQYXRoIiwic3BsaXQiLCJqb2luIiwidG9TdGVwcyIsInJlZHVjZSIsImFjYyIsInN0ZXAiLCJzbGljZSIsImNvbmNhdCIsInJlYWNoaW5nQWxsb3dlZCIsImltcG9ydFBhdGgiLCJzb21lIiwicmUiLCJ0ZXN0IiwicmVhY2hpbmdGb3JiaWRkZW4iLCJpc0FsbG93VmlvbGF0aW9uIiwic3RlcHMiLCJub25TY29wZVN0ZXBzIiwiZmlsdGVyIiwiaW5kZXhPZiIsImxlbmd0aCIsImp1c3RTdGVwcyIsInJlc29sdmVkIiwiaXNGb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c7XG5cbmltcG9ydCByZXNvbHZlIGZyb20gJ2VzbGludC1tb2R1bGUtdXRpbHMvcmVzb2x2ZSc7XG5pbXBvcnQgaW1wb3J0VHlwZSBmcm9tICcuLi9jb3JlL2ltcG9ydFR5cGUnO1xuaW1wb3J0IG1vZHVsZVZpc2l0b3IgZnJvbSAnZXNsaW50LW1vZHVsZS11dGlscy9tb2R1bGVWaXNpdG9yJztcbmltcG9ydCBkb2NzVXJsIGZyb20gJy4uL2RvY3NVcmwnO1xuXG5tb2R1bGUuZXhwb3J0cyA9IHtcbiAgbWV0YToge1xuICAgIHR5cGU6ICdzdWdnZXN0aW9uJyxcbiAgICBkb2NzOiB7XG4gICAgICB1cmw6IGRvY3NVcmwoJ25vLWludGVybmFsLW1vZHVsZXMnKSxcbiAgICB9LFxuXG4gICAgc2NoZW1hOiBbXG4gICAgICB7XG4gICAgICAgIG9uZU9mOiBbXG4gICAgICAgICAge1xuICAgICAgICAgICAgdHlwZTogJ29iamVjdCcsXG4gICAgICAgICAgICBwcm9wZXJ0aWVzOiB7XG4gICAgICAgICAgICAgIGFsbG93OiB7XG4gICAgICAgICAgICAgICAgdHlwZTogJ2FycmF5JyxcbiAgICAgICAgICAgICAgICBpdGVtczoge1xuICAgICAgICAgICAgICAgICAgdHlwZTogJ3N0cmluZycsXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgICBhZGRpdGlvbmFsUHJvcGVydGllczogZmFsc2UsXG4gICAgICAgICAgfSxcbiAgICAgICAgICB7XG4gICAgICAgICAgICB0eXBlOiAnb2JqZWN0JyxcbiAgICAgICAgICAgIHByb3BlcnRpZXM6IHtcbiAgICAgICAgICAgICAgZm9yYmlkOiB7XG4gICAgICAgICAgICAgICAgdHlwZTogJ2FycmF5JyxcbiAgICAgICAgICAgICAgICBpdGVtczoge1xuICAgICAgICAgICAgICAgICAgdHlwZTogJ3N0cmluZycsXG4gICAgICAgICAg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