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.

79 lines
2.3 KiB

  1. # import/no-useless-path-segments
  2. Use this rule to prevent unnecessary path segments in import and require statements.
  3. ## Rule Details
  4. Given the following folder structure:
  5. ```
  6. my-project
  7. ├── app.js
  8. ├── footer.js
  9. ├── header.js
  10. └── helpers.js
  11. └── helpers
  12. └── index.js
  13. └── pages
  14. ├── about.js
  15. ├── contact.js
  16. └── index.js
  17. ```
  18. The following patterns are considered problems:
  19. ```js
  20. /**
  21. * in my-project/app.js
  22. */
  23. import "./../pages/about.js"; // should be "./pages/about.js"
  24. import "./../pages/about"; // should be "./pages/about"
  25. import "../pages/about.js"; // should be "./pages/about.js"
  26. import "../pages/about"; // should be "./pages/about"
  27. import "./pages//about"; // should be "./pages/about"
  28. import "./pages/"; // should be "./pages"
  29. import "./pages/index"; // should be "./pages" (except if there is a ./pages.js file)
  30. import "./pages/index.js"; // should be "./pages" (except if there is a ./pages.js file)
  31. ```
  32. The following patterns are NOT considered problems:
  33. ```js
  34. /**
  35. * in my-project/app.js
  36. */
  37. import "./header.js";
  38. import "./pages";
  39. import "./pages/about";
  40. import ".";
  41. import "..";
  42. import fs from "fs";
  43. ```
  44. ## Options
  45. ### noUselessIndex
  46. If you want to detect unnecessary `/index` or `/index.js` (depending on the specified file extensions, see below) imports in your paths, you can enable the option `noUselessIndex`. By default it is set to `false`:
  47. ```js
  48. "import/no-useless-path-segments": ["error", {
  49. noUselessIndex: true,
  50. }]
  51. ```
  52. Additionally to the patterns described above, the following imports are considered problems if `noUselessIndex` is enabled:
  53. ```js
  54. // in my-project/app.js
  55. import "./helpers/index"; // should be "./helpers/" (not auto-fixable to `./helpers` because this would lead to an ambiguous import of `./helpers.js` and `./helpers/index.js`)
  56. import "./pages/index"; // should be "./pages" (auto-fixable)
  57. import "./pages/index.js"; // should be "./pages" (auto-fixable)
  58. ```
  59. Note: `noUselessIndex` only avoids ambiguous imports for `.js` files if you haven't specified other resolved file extensions. See [Settings: import/extensions](https://github.com/benmosher/eslint-plugin-import#importextensions) for details.
  60. ### commonjs
  61. When set to `true`, this rule checks CommonJS imports. Default to `false`.