web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
14 KiB

  1. '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);
  2. var _path = require('path');var _path2 = _interopRequireDefault(_path);
  3. var _resolve = require('eslint-module-utils/resolve');var _resolve2 = _interopRequireDefault(_resolve);
  4. var _staticRequire = require('../core/staticRequire');var _staticRequire2 = _interopRequireDefault(_staticRequire);
  5. var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);
  6. var _importType = require('../core/importType');var _importType2 = _interopRequireDefault(_importType);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
  7. module.exports = {
  8. meta: {
  9. type: 'problem',
  10. docs: {
  11. url: (0, _docsUrl2.default)('no-restricted-paths') },
  12. schema: [
  13. {
  14. type: 'object',
  15. properties: {
  16. zones: {
  17. type: 'array',
  18. minItems: 1,
  19. items: {
  20. type: 'object',
  21. properties: {
  22. target: { type: 'string' },
  23. from: { type: 'string' },
  24. except: {
  25. type: 'array',
  26. items: {
  27. type: 'string' },
  28. uniqueItems: true },
  29. message: { type: 'string' } },
  30. additionalProperties: false } },
  31. basePath: { type: 'string' } },
  32. additionalProperties: false }] },
  33. create: function noRestrictedPaths(context) {
  34. const options = context.options[0] || {};
  35. const restrictedPaths = options.zones || [];
  36. const basePath = options.basePath || process.cwd();
  37. const currentFilename = context.getFilename();
  38. const matchingZones = restrictedPaths.filter(zone => {
  39. const targetPath = _path2.default.resolve(basePath, zone.target);
  40. return (0, _containsPath2.default)(currentFilename, targetPath);
  41. });
  42. function isValidExceptionPath(absoluteFromPath, absoluteExceptionPath) {
  43. const relativeExceptionPath = _path2.default.relative(absoluteFromPath, absoluteExceptionPath);
  44. return (0, _importType2.default)(relativeExceptionPath, context) !== 'parent';
  45. }
  46. function reportInvalidExceptionPath(node) {
  47. context.report({
  48. node,
  49. message: 'Restricted path exceptions must be descendants of the configured `from` path for that zone.' });
  50. }
  51. function checkForRestrictedImportPath(importPath, node) {
  52. const absoluteImportPath = (0, _resolve2.default)(importPath, context);
  53. if (!absoluteImportPath) {
  54. return;
  55. }
  56. matchingZones.forEach(zone => {
  57. const exceptionPaths = zone.except || [];
  58. const absoluteFrom = _path2.default.resolve(basePath, zone.from);
  59. if (!(0, _containsPath2.default)(absoluteImportPath, absoluteFrom)) {
  60. return;
  61. }
  62. const absoluteExceptionPaths = exceptionPaths.map(exceptionPath =>
  63. _path2.default.resolve(absoluteFrom, exceptionPath));
  64. const hasValidExceptionPaths = absoluteExceptionPaths.
  65. every(absoluteExceptionPath => isValidExceptionPath(absoluteFrom, absoluteExceptionPath));
  66. if (!hasValidExceptionPaths) {
  67. reportInvalidExceptionPath(node);
  68. return;
  69. }
  70. const pathIsExcepted = absoluteExceptionPaths.
  71. some(absoluteExceptionPath => (0, _containsPath2.default)(absoluteImportPath, absoluteExceptionPath));
  72. if (pathIsExcepted) {
  73. return;
  74. }
  75. context.report({
  76. node,
  77. message: `Unexpected path "{{importPath}}" imported in restricted zone.${zone.message ? ` ${zone.message}` : ''}`,
  78. data: { importPath } });
  79. });
  80. }
  81. return {
  82. ImportDeclaration(node) {
  83. checkForRestrictedImportPath(node.source.value, node.source);
  84. },
  85. CallExpression(node) {
  86. if ((0, _staticRequire2.default)(node)) {var _node$arguments = _slicedToArray(
  87. node.arguments, 1);const firstArgument = _node$arguments[0];
  88. checkForRestrictedImportPath(firstArgument.value, firstArgument);
  89. }
  90. } };
  91. } };
  92. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9uby1yZXN0cmljdGVkLXBhdGhzLmpzIl0sIm5hbWVzIjpbIm1vZHVsZSIsImV4cG9ydHMiLCJtZXRhIiwidHlwZSIsImRvY3MiLCJ1cmwiLCJzY2hlbWEiLCJwcm9wZXJ0aWVzIiwiem9uZXMiLCJtaW5JdGVtcyIsIml0ZW1zIiwidGFyZ2V0IiwiZnJvbSIsImV4Y2VwdCIsInVuaXF1ZUl0ZW1zIiwibWVzc2FnZSIsImFkZGl0aW9uYWxQcm9wZXJ0aWVzIiwiYmFzZVBhdGgiLCJjcmVhdGUiLCJub1Jlc3RyaWN0ZWRQYXRocyIsImNvbnRleHQiLCJvcHRpb25zIiwicmVzdHJpY3RlZFBhdGhzIiwicHJvY2VzcyIsImN3ZCIsImN1cnJlbnRGaWxlbmFtZSIsImdldEZpbGVuYW1lIiwibWF0Y2hpbmdab25lcyIsImZpbHRlciIsInpvbmUiLCJ0YXJnZXRQYXRoIiwicGF0aCIsInJlc29sdmUiLCJpc1ZhbGlkRXhjZXB0aW9uUGF0aCIsImFic29sdXRlRnJvbVBhdGgiLCJhYnNvbHV0ZUV4Y2VwdGlvblBhdGgiLCJyZWxhdGl2ZUV4Y2VwdGlvblBhdGgiLCJyZWxhdGl2ZSIsInJlcG9ydEludmFsaWRFeGNlcHRpb25QYXRoIiwibm9kZSIsInJlcG9ydCIsImNoZWNrRm9yUmVzdHJpY3RlZEltcG9ydFBhdGgiLCJpbXBvcnRQYXRoIiwiYWJzb2x1dGVJbXBvcnRQYXRoIiwiZm9yRWFjaCIsImV4Y2VwdGlvblBhdGhzIiwiYWJzb2x1dGVGcm9tIiwiYWJzb2x1dGVFeGNlcHRpb25QYXRocyIsIm1hcCIsImV4Y2VwdGlvblBhdGgiLC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