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.

80 lines
2.6 KiB

  1. # import/no-restricted-paths: Restrict which files can be imported in a given folder
  2. Some projects contain files which are not always meant to be executed in the same environment.
  3. For example consider a web application that contains specific code for the server and some specific code for the browser/client. In this case you don’t want to import server-only files in your client code.
  4. In order to prevent such scenarios this rule allows you to define restricted zones where you can forbid files from imported if they match a specific path.
  5. ## Rule Details
  6. This rule has one option. The option is an object containing the definition of all restricted `zones` and the optional `basePath` which is used to resolve relative paths within.
  7. The default value for `basePath` is the current working directory.
  8. Each zone consists of the `target` path and a `from` path. The `target` is the path where the restricted imports should be applied. The `from` path defines the folder that is not allowed to be used in an import. An optional `except` may be defined for a zone, allowing exception paths that would otherwise violate the related `from`. Note that `except` is relative to `from` and cannot backtrack to a parent directory.
  9. You may also specify an optional `message` for a zone, which will be displayed in case of the rule violation.
  10. ### Examples
  11. Given the following folder structure:
  12. ```
  13. my-project
  14. ├── client
  15. │ └── foo.js
  16. │ └── baz.js
  17. └── server
  18. └── bar.js
  19. ```
  20. and the current file being linted is `my-project/client/foo.js`.
  21. The following patterns are considered problems when configuration set to `{ "zones": [ { "target": "./client", "from": "./server" } ] }`:
  22. ```js
  23. import bar from '../server/bar';
  24. ```
  25. The following patterns are not considered problems when configuration set to `{ "zones": [ { "target": "./client", "from": "./server" } ] }`:
  26. ```js
  27. import baz from '../client/baz';
  28. ```
  29. ---------------
  30. Given the following folder structure:
  31. ```
  32. my-project
  33. ├── client
  34. │ └── foo.js
  35. │ └── baz.js
  36. └── server
  37. ├── one
  38. │ └── a.js
  39. │ └── b.js
  40. └── two
  41. ```
  42. and the current file being linted is `my-project/server/one/a.js`.
  43. and the current configuration is set to:
  44. ```
  45. { "zones": [ {
  46. "target": "./tests/files/restricted-paths/server/one",
  47. "from": "./tests/files/restricted-paths/server",
  48. "except": ["./one"]
  49. } ] }
  50. ```
  51. The following pattern is considered a problem:
  52. ```js
  53. import a from '../two/a'
  54. ```
  55. The following pattern is not considered a problem:
  56. ```js
  57. import b from './b'
  58. ```