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.

98 lines
2.2 KiB

  1. # import/named
  2. Verifies that all named imports are part of the set of named exports in the referenced module.
  3. For `export`, verifies that all named exports exist in the referenced module.
  4. Note: for packages, the plugin will find exported names
  5. from [`jsnext:main`], if present in `package.json`.
  6. Redux's npm module includes this key, and thereby is lintable, for example.
  7. A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported. Note that type imports and exports, as used by [Flow], are always ignored.
  8. [ignored]: ../../README.md#importignore
  9. [unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
  10. [Flow]: https://flow.org/
  11. ## Rule Details
  12. Given:
  13. ```js
  14. // ./foo.js
  15. export const foo = "I'm so foo"
  16. ```
  17. The following is considered valid:
  18. ```js
  19. // ./bar.js
  20. import { foo } from './foo'
  21. // ES7 proposal
  22. export { foo as bar } from './foo'
  23. // node_modules without jsnext:main are not analyzed by default
  24. // (import/ignore setting)
  25. import { SomeNonsenseThatDoesntExist } from 'react'
  26. ```
  27. ...and the following are reported:
  28. ```js
  29. // ./baz.js
  30. import { notFoo } from './foo'
  31. // ES7 proposal
  32. export { notFoo as defNotBar } from './foo'
  33. // will follow 'jsnext:main', if available
  34. import { dontCreateStore } from 'redux'
  35. ```
  36. ### Settings
  37. [`import/ignore`] can be provided as a setting to ignore certain modules (node_modules,
  38. CoffeeScript, CSS if using Webpack, etc.).
  39. Given:
  40. ```yaml
  41. # .eslintrc (YAML)
  42. ---
  43. settings:
  44. import/ignore:
  45. - node_modules # included by default, but replaced if explicitly configured
  46. - *.coffee$ # can't parse CoffeeScript (unless a custom polyglot parser was configured)
  47. ```
  48. and
  49. ```coffeescript
  50. # ./whatever.coffee
  51. exports.whatever = (foo) -> console.log foo
  52. ```
  53. then the following is not reported:
  54. ```js
  55. // ./foo.js
  56. // can't be analyzed, and ignored, so not reported
  57. import { notWhatever } from './whatever'
  58. ```
  59. ## When Not To Use It
  60. If you are using CommonJS and/or modifying the exported namespace of any module at
  61. runtime, you will likely see false positives with this rule.
  62. ## Further Reading
  63. - [`import/ignore`] setting
  64. - [`jsnext:main`] (Rollup)
  65. [`jsnext:main`]: https://github.com/rollup/rollup/wiki/jsnext:main
  66. [`import/ignore`]: ../../README.md#importignore