Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

eslint.config.mjs 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import {
  2. GLOB_TESTS, combine, javascript, node,
  3. stylistic, typescript, unicorn,
  4. } from '@antfu/eslint-config'
  5. import globals from 'globals'
  6. import storybook from 'eslint-plugin-storybook'
  7. // import { fixupConfigRules } from '@eslint/compat'
  8. import tailwind from 'eslint-plugin-tailwindcss'
  9. import reactHooks from 'eslint-plugin-react-hooks'
  10. // import reactRefresh from 'eslint-plugin-react-refresh'
  11. export default combine(
  12. stylistic({
  13. lessOpinionated: true,
  14. // original @antfu/eslint-config does not support jsx
  15. jsx: false,
  16. semi: false,
  17. quotes: 'single',
  18. overrides: {
  19. // original config
  20. 'style/indent': ['error', 2],
  21. 'style/quotes': ['error', 'single'],
  22. 'curly': ['error', 'multi-or-nest', 'consistent'],
  23. 'style/comma-spacing': ['error', { before: false, after: true }],
  24. 'style/quote-props': ['warn', 'consistent-as-needed'],
  25. // these options does not exist in old version
  26. // maybe useless
  27. 'style/indent-binary-ops': 'off',
  28. 'style/multiline-ternary': 'off',
  29. 'antfu/top-level-function': 'off',
  30. 'antfu/curly': 'off',
  31. 'antfu/consistent-chaining': 'off',
  32. // copy from eslint-config-antfu 0.36.0
  33. 'style/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
  34. 'style/dot-location': ['error', 'property'],
  35. 'style/object-curly-newline': ['error', { consistent: true, multiline: true }],
  36. 'style/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
  37. 'style/template-curly-spacing': ['error', 'never'],
  38. 'style/keyword-spacing': 'off',
  39. // not exist in old version, and big change
  40. 'style/member-delimiter-style': 'off',
  41. },
  42. }),
  43. javascript({
  44. overrides: {
  45. // handled by unused-imports/no-unused-vars
  46. 'no-unused-vars': 'off',
  47. },
  48. }),
  49. typescript({
  50. overrides: {
  51. // original config
  52. 'ts/consistent-type-definitions': ['warn', 'type'],
  53. // useful, but big change
  54. 'ts/no-empty-object-type': 'off',
  55. },
  56. }),
  57. unicorn(),
  58. node(),
  59. // use nextjs config will break @eslint/config-inspector
  60. // use `ESLINT_CONFIG_INSPECTOR=true pnpx @eslint/config-inspector` to check the config
  61. // ...process.env.ESLINT_CONFIG_INSPECTOR
  62. // ? []
  63. // TODO: remove this when upgrade to nextjs 15
  64. // : fixupConfigRules(compat.extends('next')),
  65. {
  66. rules: {
  67. // performance issue, and not used.
  68. '@next/next/no-html-link-for-pages': 'off',
  69. },
  70. },
  71. {
  72. ignores: [
  73. '**/node_modules/*',
  74. '**/dist/',
  75. '**/build/',
  76. '**/out/',
  77. '**/.next/',
  78. '**/public/*',
  79. '**/*.json',
  80. ],
  81. },
  82. {
  83. // orignal config
  84. rules: {
  85. // orignal ts/no-var-requires
  86. 'ts/no-require-imports': 'off',
  87. 'no-console': 'off',
  88. 'react-hooks/exhaustive-deps': 'warn',
  89. 'react/display-name': 'off',
  90. 'array-callback-return': ['error', {
  91. allowImplicit: false,
  92. checkForEach: false,
  93. }],
  94. // copy from eslint-config-antfu 0.36.0
  95. 'camelcase': 'off',
  96. 'default-case-last': 'error',
  97. // antfu use eslint-plugin-perfectionist to replace this
  98. // will cause big change, so keep the original sort-imports
  99. 'sort-imports': [
  100. 'error',
  101. {
  102. ignoreCase: false,
  103. ignoreDeclarationSort: true,
  104. ignoreMemberSort: false,
  105. memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
  106. allowSeparatedGroups: false,
  107. },
  108. ],
  109. // antfu migrate to eslint-plugin-unused-imports
  110. 'unused-imports/no-unused-vars': 'warn',
  111. 'unused-imports/no-unused-imports': 'warn',
  112. // We use `import { noop } from 'lodash-es'` across `web` project
  113. 'no-empty-function': 'error',
  114. },
  115. languageOptions: {
  116. globals: {
  117. ...globals.browser,
  118. ...globals.es2025,
  119. ...globals.node,
  120. React: 'readable',
  121. JSX: 'readable',
  122. },
  123. },
  124. },
  125. storybook.configs['flat/recommended'],
  126. // reactRefresh.configs.recommended,
  127. {
  128. rules: reactHooks.configs.recommended.rules,
  129. plugins: {
  130. 'react-hooks': reactHooks,
  131. },
  132. },
  133. // need futher research
  134. {
  135. rules: {
  136. // not exist in old version
  137. 'antfu/consistent-list-newline': 'off',
  138. 'node/prefer-global/process': 'off',
  139. 'node/prefer-global/buffer': 'off',
  140. 'node/no-callback-literal': 'off',
  141. // useful, but big change
  142. 'unicorn/prefer-number-properties': 'warn',
  143. 'unicorn/no-new-array': 'warn',
  144. },
  145. },
  146. // suppress error for `no-undef` rule
  147. {
  148. files: GLOB_TESTS,
  149. languageOptions: {
  150. globals: {
  151. ...globals.browser,
  152. ...globals.es2021,
  153. ...globals.node,
  154. ...globals.jest,
  155. },
  156. },
  157. },
  158. tailwind.configs['flat/recommended'],
  159. {
  160. settings: {
  161. tailwindcss: {
  162. // These are the default values but feel free to customize
  163. callees: ['classnames', 'clsx', 'ctl', 'cn'],
  164. config: 'tailwind.config.js', // returned from `loadConfig()` utility if not provided
  165. cssFiles: [
  166. '**/*.css',
  167. '!**/node_modules',
  168. '!**/.*',
  169. '!**/dist',
  170. '!**/build',
  171. '!**/.storybook',
  172. '!**/.next',
  173. '!**/.public',
  174. ],
  175. cssFilesRefreshRate: 5_000,
  176. removeDuplicates: true,
  177. skipClassAttribute: false,
  178. whitelist: [],
  179. tags: [], // can be set to e.g. ['tw'] for use in tw`bg-blue`
  180. classRegex: '^class(Name)?$', // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro`
  181. },
  182. },
  183. rules: {
  184. // due to 1k lines of tailwind config, these rule have performance issue
  185. 'tailwindcss/no-contradicting-classname': 'off',
  186. 'tailwindcss/enforces-shorthand': 'off',
  187. 'tailwindcss/no-custom-classname': 'off',
  188. 'tailwindcss/no-unnecessary-arbitrary-value': 'off',
  189. 'tailwindcss/no-arbitrary-value': 'off',
  190. 'tailwindcss/classnames-order': 'warn',
  191. 'tailwindcss/enforces-negative-arbitrary-values': 'warn',
  192. 'tailwindcss/migration-from-tailwind-2': 'warn',
  193. },
  194. },
  195. )