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.

70 lines
2.0 KiB

  1. # import/first
  2. This rule reports any imports that come after non-import
  3. statements.
  4. ## Rule Details
  5. ```js
  6. import foo from './foo'
  7. // some module-level initializer
  8. initWith(foo)
  9. import bar from './bar' // <- reported
  10. ```
  11. Providing `absolute-first` as an option will report any absolute imports (i.e.
  12. packages) that come after any relative imports:
  13. ```js
  14. import foo from 'foo'
  15. import bar from './bar'
  16. import * as _ from 'lodash' // <- reported
  17. ```
  18. If you really want import type ordering, check out [`import/order`].
  19. Notably, `import`s are hoisted, which means the imported modules will be evaluated
  20. before any of the statements interspersed between them. Keeping all `import`s together
  21. at the top of the file may prevent surprises resulting from this part of the spec.
  22. ### On directives
  23. Directives are allowed as long as they occur strictly before any `import` declarations,
  24. as follows:
  25. ```js
  26. 'use super-mega-strict'
  27. import { suchFoo } from 'lame-fake-module-name' // no report here
  28. ```
  29. A directive in this case is assumed to be a single statement that contains only
  30. a literal string-valued expression.
  31. `'use strict'` would be a good example, except that [modules are always in strict
  32. mode](http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code) so it would be surprising to see a `'use strict'` sharing a file with `import`s and
  33. `export`s.
  34. Given that, see [#255] for the reasoning.
  35. ### With Fixer
  36. This rule contains a fixer to reorder in-body import to top, the following criteria applied:
  37. 1. Never re-order relative to each other, even if `absolute-first` is set.
  38. 2. If an import creates an identifier, and that identifier is referenced at module level *before* the import itself, that won't be re-ordered.
  39. ## When Not To Use It
  40. If you don't mind imports being sprinkled throughout, you may not want to
  41. enable this rule.
  42. ## Further Reading
  43. - [`import/order`]: a major step up from `absolute-first`
  44. - Issue [#255]
  45. [`import/order`]: ./order.md
  46. [#255]: https://github.com/benmosher/eslint-plugin-import/issues/255