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.

117 lines
2.3 KiB

  1. # import/group-exports
  2. Reports when named exports are not grouped together in a single `export` declaration or when multiple assignments to CommonJS `module.exports` or `exports` object are present in a single file.
  3. **Rationale:** An `export` declaration or `module.exports` assignment can appear anywhere in the code. By requiring a single export declaration all your exports will remain at one place, making it easier to see what exports a module provides.
  4. ## Rule Details
  5. This rule warns whenever a single file contains multiple named export declarations or multiple assignments to `module.exports` (or `exports`).
  6. ### Valid
  7. ```js
  8. // A single named export declaration -> ok
  9. export const valid = true
  10. ```
  11. ```js
  12. const first = true
  13. const second = true
  14. // A single named export declaration -> ok
  15. export {
  16. first,
  17. second,
  18. }
  19. ```
  20. ```js
  21. // Aggregating exports -> ok
  22. export { default as module1 } from 'module-1'
  23. export { default as module2 } from 'module-2'
  24. ```
  25. ```js
  26. // A single exports assignment -> ok
  27. module.exports = {
  28. first: true,
  29. second: true
  30. }
  31. ```
  32. ```js
  33. const first = true
  34. const second = true
  35. // A single exports assignment -> ok
  36. module.exports = {
  37. first,
  38. second,
  39. }
  40. ```
  41. ```js
  42. function test() {}
  43. test.property = true
  44. test.another = true
  45. // A single exports assignment -> ok
  46. module.exports = test
  47. ```
  48. ```flow js
  49. const first = true;
  50. type firstType = boolean
  51. // A single named export declaration (type exports handled separately) -> ok
  52. export {first}
  53. export type {firstType}
  54. ```
  55. ### Invalid
  56. ```js
  57. // Multiple named export statements -> not ok!
  58. export const first = true
  59. export const second = true
  60. ```
  61. ```js
  62. // Aggregating exports from the same module -> not ok!
  63. export { module1 } from 'module-1'
  64. export { module2 } from 'module-1'
  65. ```
  66. ```js
  67. // Multiple exports assignments -> not ok!
  68. exports.first = true
  69. exports.second = true
  70. ```
  71. ```js
  72. // Multiple exports assignments -> not ok!
  73. module.exports = {}
  74. module.exports.first = true
  75. ```
  76. ```js
  77. // Multiple exports assignments -> not ok!
  78. module.exports = () => {}
  79. module.exports.first = true
  80. module.exports.second = true
  81. ```
  82. ```flow js
  83. type firstType = boolean
  84. type secondType = any
  85. // Multiple named type export statements -> not ok!
  86. export type {firstType}
  87. export type {secondType}
  88. ```
  89. ## When Not To Use It
  90. If you do not mind having your exports spread across the file, you can safely turn this rule off.