eslint.config.mjs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. },
  113. languageOptions: {
  114. globals: {
  115. ...globals.browser,
  116. ...globals.es2025,
  117. ...globals.node,
  118. React: 'readable',
  119. JSX: 'readable',
  120. },
  121. },
  122. },
  123. storybook.configs['flat/recommended'],
  124. // reactRefresh.configs.recommended,
  125. {
  126. rules: reactHooks.configs.recommended.rules,
  127. plugins: {
  128. 'react-hooks': reactHooks,
  129. },
  130. },
  131. // need futher research
  132. {
  133. rules: {
  134. // not exist in old version
  135. 'antfu/consistent-list-newline': 'off',
  136. 'node/prefer-global/process': 'off',
  137. 'node/prefer-global/buffer': 'off',
  138. 'node/no-callback-literal': 'off',
  139. // useful, but big change
  140. 'unicorn/prefer-number-properties': 'warn',
  141. 'unicorn/no-new-array': 'warn',
  142. },
  143. },
  144. // suppress error for `no-undef` rule
  145. {
  146. files: GLOB_TESTS,
  147. languageOptions: {
  148. globals: {
  149. ...globals.browser,
  150. ...globals.es2021,
  151. ...globals.node,
  152. ...globals.jest,
  153. },
  154. },
  155. },
  156. tailwind.configs['flat/recommended'],
  157. {
  158. settings: {
  159. tailwindcss: {
  160. // These are the default values but feel free to customize
  161. callees: ['classnames', 'clsx', 'ctl', 'cn'],
  162. config: 'tailwind.config.js', // returned from `loadConfig()` utility if not provided
  163. cssFiles: [
  164. '**/*.css',
  165. '!**/node_modules',
  166. '!**/.*',
  167. '!**/dist',
  168. '!**/build',
  169. '!**/.storybook',
  170. '!**/.next',
  171. '!**/.public',
  172. ],
  173. cssFilesRefreshRate: 5_000,
  174. removeDuplicates: true,
  175. skipClassAttribute: false,
  176. whitelist: [],
  177. tags: [], // can be set to e.g. ['tw'] for use in tw`bg-blue`
  178. classRegex: '^class(Name)?$', // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro`
  179. },
  180. },
  181. rules: {
  182. // due to 1k lines of tailwind config, these rule have performance issue
  183. 'tailwindcss/no-contradicting-classname': 'off',
  184. 'tailwindcss/enforces-shorthand': 'off',
  185. 'tailwindcss/no-custom-classname': 'off',
  186. 'tailwindcss/no-unnecessary-arbitrary-value': 'off',
  187. 'tailwindcss/no-arbitrary-value': 'off',
  188. 'tailwindcss/classnames-order': 'warn',
  189. 'tailwindcss/enforces-negative-arbitrary-values': 'warn',
  190. 'tailwindcss/migration-from-tailwind-2': 'warn',
  191. },
  192. },
  193. )