imports.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. module.exports = {
  2. env: {
  3. es6: true
  4. },
  5. parserOptions: {
  6. ecmaVersion: 6,
  7. sourceType: 'module'
  8. },
  9. plugins: [
  10. 'import'
  11. ],
  12. settings: {
  13. 'import/resolver': {
  14. node: {
  15. extensions: ['.mjs', '.js', '.json']
  16. }
  17. },
  18. 'import/extensions': [
  19. '.js',
  20. '.mjs',
  21. '.jsx',
  22. ],
  23. 'import/core-modules': [
  24. ],
  25. 'import/ignore': [
  26. 'node_modules',
  27. '\\.(coffee|scss|css|less|hbs|svg|json)$',
  28. ],
  29. },
  30. rules: {
  31. // Static analysis:
  32. // ensure imports point to files/modules that can be resolved
  33. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unresolved.md
  34. 'import/no-unresolved': ['error', { commonjs: true, caseSensitive: true }],
  35. // ensure named imports coupled with named exports
  36. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md#when-not-to-use-it
  37. 'import/named': 'error',
  38. // ensure default import coupled with default export
  39. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/default.md#when-not-to-use-it
  40. 'import/default': 'off',
  41. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/namespace.md
  42. 'import/namespace': 'off',
  43. // Helpful warnings:
  44. // disallow invalid exports, e.g. multiple defaults
  45. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
  46. 'import/export': 'error',
  47. // do not allow a default import name to match a named export
  48. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default.md
  49. 'import/no-named-as-default': 'error',
  50. // warn on accessing default export property names that are also named exports
  51. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md
  52. 'import/no-named-as-default-member': 'error',
  53. // disallow use of jsdoc-marked-deprecated imports
  54. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-deprecated.md
  55. 'import/no-deprecated': 'off',
  56. // Forbid the use of extraneous packages
  57. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
  58. // paths are treated both as absolute paths, and relative to process.cwd()
  59. 'import/no-extraneous-dependencies': ['error', {
  60. devDependencies: [
  61. 'test/**', // tape, common npm pattern
  62. 'tests/**', // also common npm pattern
  63. 'spec/**', // mocha, rspec-like pattern
  64. '**/__tests__/**', // jest pattern
  65. '**/__mocks__/**', // jest pattern
  66. 'test.{js,jsx}', // repos with a single test file
  67. 'test-*.{js,jsx}', // repos with multiple top-level test files
  68. '**/*{.,_}{test,spec}.{js,jsx}', // tests where the extension or filename suffix denotes that it is a test
  69. '**/jest.config.js', // jest config
  70. '**/jest.setup.js', // jest setup
  71. '**/vue.config.js', // vue-cli config
  72. '**/webpack.config.js', // webpack config
  73. '**/webpack.config.*.js', // webpack config
  74. '**/rollup.config.js', // rollup config
  75. '**/rollup.config.*.js', // rollup config
  76. '**/gulpfile.js', // gulp config
  77. '**/gulpfile.*.js', // gulp config
  78. '**/Gruntfile{,.js}', // grunt config
  79. '**/protractor.conf.js', // protractor config
  80. '**/protractor.conf.*.js', // protractor config
  81. '**/karma.conf.js', // karma config
  82. '**/.eslintrc.js' // eslint config
  83. ],
  84. optionalDependencies: false,
  85. }],
  86. // Forbid mutable exports
  87. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
  88. 'import/no-mutable-exports': 'error',
  89. // Module systems:
  90. // disallow require()
  91. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-commonjs.md
  92. 'import/no-commonjs': 'off',
  93. // disallow AMD require/define
  94. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-amd.md
  95. 'import/no-amd': 'error',
  96. // No Node.js builtin modules
  97. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-nodejs-modules.md
  98. // TODO: enable?
  99. 'import/no-nodejs-modules': 'off',
  100. // Style guide:
  101. // disallow non-import statements appearing before import statements
  102. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md
  103. 'import/first': 'error',
  104. // disallow non-import statements appearing before import statements
  105. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/imports-first.md
  106. // deprecated: use `import/first`
  107. 'import/imports-first': 'off',
  108. // disallow duplicate imports
  109. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
  110. 'import/no-duplicates': 'error',
  111. // disallow namespace imports
  112. // TODO: enable?
  113. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-namespace.md
  114. 'import/no-namespace': 'off',
  115. // Ensure consistent use of file extension within the import path
  116. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
  117. 'import/extensions': ['error', 'ignorePackages', {
  118. js: 'never',
  119. mjs: 'never',
  120. jsx: 'never',
  121. }],
  122. // ensure absolute imports are above relative imports and that unassigned imports are ignored
  123. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
  124. // TODO: enforce a stricter convention in module import order?
  125. 'import/order': ['error', { groups: [['builtin', 'external', 'internal']] }],
  126. // Require a newline after the last import/require in a group
  127. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
  128. 'import/newline-after-import': 'error',
  129. // Require modules with a single export to use a default export
  130. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
  131. 'import/prefer-default-export': 'error',
  132. // Restrict which files can be imported in a given folder
  133. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-restricted-paths.md
  134. 'import/no-restricted-paths': 'off',
  135. // Forbid modules to have too many dependencies
  136. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/max-dependencies.md
  137. 'import/max-dependencies': ['off', { max: 10 }],
  138. // Forbid import of modules using absolute paths
  139. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
  140. 'import/no-absolute-path': 'error',
  141. // Forbid require() calls with expressions
  142. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
  143. 'import/no-dynamic-require': 'error',
  144. // prevent importing the submodules of other modules
  145. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-internal-modules.md
  146. 'import/no-internal-modules': ['off', {
  147. allow: [],
  148. }],
  149. // Warn if a module could be mistakenly parsed as a script by a consumer
  150. // leveraging Unambiguous JavaScript Grammar
  151. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/unambiguous.md
  152. // this should not be enabled until this proposal has at least been *presented* to TC39.
  153. // At the moment, it's not a thing.
  154. 'import/unambiguous': 'off',
  155. // Forbid Webpack loader syntax in imports
  156. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-webpack-loader-syntax.md
  157. 'import/no-webpack-loader-syntax': 'error',
  158. // Prevent unassigned imports
  159. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-unassigned-import.md
  160. // importing for side effects is perfectly acceptable, if you need side effects.
  161. 'import/no-unassigned-import': 'off',
  162. // Prevent importing the default as if it were named
  163. // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-default.md
  164. 'import/no-named-default': 'error',
  165. // Reports if a module's default export is unnamed
  166. // https://github.com/benmosher/eslint-plugin-import/blob/d9b712ac7fd1fddc391f7b234827925c160d956f/docs/rules/no-anonymous-default-export.md
  167. 'import/no-anonymous-default-export': ['off', {
  168. allowArray: false,
  169. allowArrowFunction: false,
  170. allowAnonymousClass: false,
  171. allowAnonymousFunction: false,
  172. allowLiteral: false,
  173. allowObject: false,
  174. }],
  175. // This rule enforces that all exports are declared at the bottom of the file.
  176. // https://github.com/benmosher/eslint-plugin-import/blob/98acd6afd04dcb6920b81330114e146dc8532ea4/docs/rules/exports-last.md
  177. // TODO: enable?
  178. 'import/exports-last': 'off',
  179. // Reports when named exports are not grouped together in a single export declaration
  180. // or when multiple assignments to CommonJS module.exports or exports object are present
  181. // in a single file.
  182. // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/group-exports.md
  183. 'import/group-exports': 'off',
  184. // forbid default exports. this is a terrible rule, do not use it.
  185. // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-default-export.md
  186. 'import/no-default-export': 'off',
  187. // Prohibit named exports. this is a terrible rule, do not use it.
  188. // https://github.com/benmosher/eslint-plugin-import/blob/1ec80fa35fa1819e2d35a70e68fb6a149fb57c5e/docs/rules/no-named-export.md
  189. 'import/no-named-export': 'off',
  190. // Forbid a module from importing itself
  191. // https://github.com/benmosher/eslint-plugin-import/blob/44a038c06487964394b1e15b64f3bd34e5d40cde/docs/rules/no-self-import.md
  192. 'import/no-self-import': 'error',
  193. // Forbid cyclical dependencies between modules
  194. // https://github.com/benmosher/eslint-plugin-import/blob/d81f48a2506182738409805f5272eff4d77c9348/docs/rules/no-cycle.md
  195. 'import/no-cycle': ['error', { maxDepth: '∞' }],
  196. // Ensures that there are no useless path segments
  197. // https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/no-useless-path-segments.md
  198. 'import/no-useless-path-segments': ['error', { commonjs: true }],
  199. // dynamic imports require a leading comment with a webpackChunkName
  200. // https://github.com/benmosher/eslint-plugin-import/blob/ebafcbf59ec9f653b2ac2a0156ca3bcba0a7cf57/docs/rules/dynamic-import-chunkname.md
  201. 'import/dynamic-import-chunkname': ['off', {
  202. importFunctions: [],
  203. webpackChunknameFormat: '[0-9a-zA-Z-_/.]+',
  204. }],
  205. // Use this rule to prevent imports to folders in relative parent paths.
  206. // https://github.com/benmosher/eslint-plugin-import/blob/c34f14f67f077acd5a61b3da9c0b0de298d20059/docs/rules/no-relative-parent-imports.md
  207. 'import/no-relative-parent-imports': 'off',
  208. // Reports modules without any exports, or with unused exports
  209. // https://github.com/benmosher/eslint-plugin-import/blob/f63dd261809de6883b13b6b5b960e6d7f42a7813/docs/rules/no-unused-modules.md
  210. // TODO: enable once it supports CJS
  211. 'import/no-unused-modules': ['off', {
  212. ignoreExports: [],
  213. missingExports: true,
  214. unusedExports: true,
  215. }],
  216. // Reports the use of import declarations with CommonJS exports in any module except for the main module.
  217. // https://github.com/benmosher/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-import-module-exports.md
  218. 'import/no-import-module-exports': ['error', {
  219. exceptions: [],
  220. }],
  221. // Use this rule to prevent importing packages through relative paths.
  222. // https://github.com/benmosher/eslint-plugin-import/blob/1012eb951767279ce3b540a4ec4f29236104bb5b/docs/rules/no-relative-packages.md
  223. 'import/no-relative-packages': 'error',
  224. },
  225. };