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.

91 lines
3.5 KiB

  1. # import/no-unresolved
  2. Ensures an imported module can be resolved to a module on the local filesystem,
  3. as defined by standard Node `require.resolve` behavior.
  4. See [settings](../../README.md#settings) for customization options for the resolution (i.e.
  5. additional filetypes, `NODE_PATH`, etc.)
  6. This rule can also optionally report on unresolved modules in CommonJS `require('./foo')` calls and AMD `require(['./foo'], function (foo){...})` and `define(['./foo'], function (foo){...})`.
  7. To enable this, send `{ commonjs: true/false, amd: true/false }` as a rule option.
  8. Both are disabled by default.
  9. If you are using Webpack, see the section on [resolvers](../../README.md#resolvers).
  10. ## Rule Details
  11. ### Options
  12. By default, only ES6 imports will be resolved:
  13. ```js
  14. /*eslint import/no-unresolved: 2*/
  15. import x from './foo' // reports if './foo' cannot be resolved on the filesystem
  16. ```
  17. If `{commonjs: true}` is provided, single-argument `require` calls will be resolved:
  18. ```js
  19. /*eslint import/no-unresolved: [2, { commonjs: true }]*/
  20. const { default: x } = require('./foo') // reported if './foo' is not found
  21. require(0) // ignored
  22. require(['x', 'y'], function (x, y) { /*...*/ }) // ignored
  23. ```
  24. Similarly, if `{ amd: true }` is provided, dependency paths for `define` and `require`
  25. calls will be resolved:
  26. ```js
  27. /*eslint import/no-unresolved: [2, { amd: true }]*/
  28. define(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
  29. require(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
  30. const { default: x } = require('./foo') // ignored
  31. ```
  32. Both may be provided, too:
  33. ```js
  34. /*eslint import/no-unresolved: [2, { commonjs: true, amd: true }]*/
  35. const { default: x } = require('./foo') // reported if './foo' is not found
  36. define(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
  37. require(['./foo'], function (foo) { /*...*/ }) // reported if './foo' is not found
  38. ```
  39. #### `ignore`
  40. This rule has its own ignore list, separate from [`import/ignore`]. This is because you may want to know whether a module can be located, regardless of whether it can be parsed for exports: `node_modules`, CoffeeScript files, etc. are all good to resolve properly, but will not be parsed if configured as such via [`import/ignore`].
  41. To suppress errors from files that may not be properly resolved by your [resolver settings](../../README.md#resolver-plugins), you may add an `ignore` key with an array of `RegExp` pattern strings:
  42. ```js
  43. /*eslint import/no-unresolved: [2, { ignore: ['\.img$'] }]*/
  44. import { x } from './mod' // may be reported, if not resolved to a module
  45. import coolImg from '../../img/coolImg.img' // will not be reported, even if not found
  46. ```
  47. #### `caseSensitive`
  48. By default, this rule will report paths whose case do not match the underlying filesystem path, if the FS is not case-sensitive. To disable this behavior, set the `caseSensitive` option to `false`.
  49. ```js
  50. /*eslint import/no-unresolved: [2, { caseSensitive: true (default) | false }]*/
  51. const { default: x } = require('./foo') // reported if './foo' is actually './Foo' and caseSensitive: true
  52. ```
  53. ## When Not To Use It
  54. If you're using a module bundler other than Node or Webpack, you may end up with
  55. a lot of false positive reports of missing dependencies.
  56. ## Further Reading
  57. - [Resolver plugins](../../README.md#resolver-plugins)
  58. - [Node resolver](https://npmjs.com/package/eslint-import-resolver-node) (default)
  59. - [Webpack resolver](https://npmjs.com/package/eslint-import-resolver-webpack)
  60. - [`import/ignore`] global setting
  61. [`import/ignore`]: ../../README.md#importignore