您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

eslint.config.mjs 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 sonar from 'eslint-plugin-sonarjs'
  11. import oxlint from 'eslint-plugin-oxlint'
  12. // import reactRefresh from 'eslint-plugin-react-refresh'
  13. export default combine(
  14. stylistic({
  15. lessOpinionated: true,
  16. // original @antfu/eslint-config does not support jsx
  17. jsx: false,
  18. semi: false,
  19. quotes: 'single',
  20. overrides: {
  21. // original config
  22. 'style/indent': ['error', 2],
  23. 'style/quotes': ['error', 'single'],
  24. 'curly': ['error', 'multi-or-nest', 'consistent'],
  25. 'style/comma-spacing': ['error', { before: false, after: true }],
  26. 'style/quote-props': ['warn', 'consistent-as-needed'],
  27. // these options does not exist in old version
  28. // maybe useless
  29. 'style/indent-binary-ops': 'off',
  30. 'style/multiline-ternary': 'off',
  31. 'antfu/top-level-function': 'off',
  32. 'antfu/curly': 'off',
  33. 'antfu/consistent-chaining': 'off',
  34. // copy from eslint-config-antfu 0.36.0
  35. 'style/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
  36. 'style/dot-location': ['error', 'property'],
  37. 'style/object-curly-newline': ['error', { consistent: true, multiline: true }],
  38. 'style/template-curly-spacing': ['error', 'never'],
  39. 'style/keyword-spacing': 'off',
  40. // not exist in old version, and big change
  41. 'style/member-delimiter-style': 'off',
  42. },
  43. }),
  44. javascript({
  45. overrides: {
  46. // handled by unused-imports/no-unused-vars
  47. 'no-unused-vars': 'off',
  48. },
  49. }),
  50. typescript({
  51. overrides: {
  52. // original config
  53. 'ts/consistent-type-definitions': ['warn', 'type'],
  54. // useful, but big change
  55. 'ts/no-empty-object-type': 'off',
  56. },
  57. }),
  58. unicorn(),
  59. node(),
  60. // use nextjs config will break @eslint/config-inspector
  61. // use `ESLINT_CONFIG_INSPECTOR=true pnpx @eslint/config-inspector` to check the config
  62. // ...process.env.ESLINT_CONFIG_INSPECTOR
  63. // ? []
  64. {
  65. rules: {
  66. // performance issue, and not used.
  67. '@next/next/no-html-link-for-pages': 'off',
  68. },
  69. },
  70. {
  71. ignores: [
  72. '**/node_modules/*',
  73. '**/dist/',
  74. '**/build/',
  75. '**/out/',
  76. '**/.next/',
  77. '**/public/*',
  78. '**/*.json',
  79. ],
  80. },
  81. {
  82. // orignal config
  83. rules: {
  84. // orignal ts/no-var-requires
  85. 'ts/no-require-imports': 'off',
  86. 'no-console': 'off',
  87. 'react-hooks/exhaustive-deps': 'warn',
  88. 'react/display-name': 'off',
  89. 'array-callback-return': ['error', {
  90. allowImplicit: false,
  91. checkForEach: false,
  92. }],
  93. // copy from eslint-config-antfu 0.36.0
  94. 'camelcase': 'off',
  95. 'default-case-last': 'error',
  96. // antfu use eslint-plugin-perfectionist to replace this
  97. // will cause big change, so keep the original sort-imports
  98. 'sort-imports': [
  99. 'error',
  100. {
  101. ignoreCase: false,
  102. ignoreDeclarationSort: true,
  103. ignoreMemberSort: false,
  104. memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
  105. allowSeparatedGroups: false,
  106. },
  107. ],
  108. // antfu migrate to eslint-plugin-unused-imports
  109. 'unused-imports/no-unused-vars': 'warn',
  110. 'unused-imports/no-unused-imports': 'warn',
  111. // We use `import { noop } from 'lodash-es'` across `web` project
  112. 'no-empty-function': 'error',
  113. },
  114. languageOptions: {
  115. globals: {
  116. ...globals.browser,
  117. ...globals.es2025,
  118. ...globals.node,
  119. React: 'readable',
  120. JSX: 'readable',
  121. },
  122. },
  123. },
  124. storybook.configs['flat/recommended'],
  125. // reactRefresh.configs.recommended,
  126. {
  127. rules: reactHooks.configs.recommended.rules,
  128. plugins: {
  129. 'react-hooks': reactHooks,
  130. },
  131. },
  132. // sonar
  133. {
  134. rules: {
  135. ...sonar.configs.recommended.rules,
  136. // code complexity
  137. 'sonarjs/cognitive-complexity': 'off',
  138. 'sonarjs/no-nested-functions': 'warn',
  139. 'sonarjs/no-nested-conditional': 'warn',
  140. 'sonarjs/nested-control-flow': 'warn', // 3 levels of nesting
  141. 'sonarjs/no-small-switch': 'off',
  142. 'sonarjs/no-nested-template-literals': 'warn',
  143. 'sonarjs/redundant-type-aliases': 'off',
  144. 'sonarjs/regex-complexity': 'warn',
  145. // maintainability
  146. 'sonarjs/no-ignored-exceptions': 'off',
  147. 'sonarjs/no-commented-code': 'warn',
  148. 'sonarjs/no-unused-vars': 'warn',
  149. 'sonarjs/prefer-single-boolean-return': 'warn',
  150. 'sonarjs/duplicates-in-character-class': 'off',
  151. 'sonarjs/single-char-in-character-classes': 'off',
  152. 'sonarjs/anchor-precedence': 'warn',
  153. 'sonarjs/updated-loop-counter': 'off',
  154. 'sonarjs/no-dead-store': 'warn',
  155. 'sonarjs/no-duplicated-branches': 'warn',
  156. 'sonarjs/max-lines': 'warn', // max 1000 lines
  157. 'sonarjs/no-variable-usage-before-declaration': 'error',
  158. // security
  159. 'sonarjs/no-hardcoded-passwords': 'off', // detect the wrong code that is not password.
  160. 'sonarjs/no-hardcoded-secrets': 'off',
  161. 'sonarjs/pseudo-random': 'off',
  162. // performance
  163. 'sonarjs/slow-regex': 'warn',
  164. // others
  165. 'sonarjs/todo-tag': 'warn',
  166. 'sonarjs/table-header': 'off',
  167. },
  168. plugins: {
  169. sonarjs: sonar,
  170. },
  171. },
  172. // need further research
  173. {
  174. rules: {
  175. // not exist in old version
  176. 'antfu/consistent-list-newline': 'off',
  177. 'node/prefer-global/process': 'off',
  178. 'node/prefer-global/buffer': 'off',
  179. 'node/no-callback-literal': 'off',
  180. // useful, but big change
  181. 'unicorn/prefer-number-properties': 'warn',
  182. 'unicorn/no-new-array': 'warn',
  183. 'style/indent': 'off',
  184. },
  185. },
  186. // suppress error for `no-undef` rule
  187. {
  188. files: GLOB_TESTS,
  189. languageOptions: {
  190. globals: {
  191. ...globals.browser,
  192. ...globals.es2021,
  193. ...globals.node,
  194. ...globals.jest,
  195. },
  196. },
  197. },
  198. tailwind.configs['flat/recommended'],
  199. {
  200. settings: {
  201. tailwindcss: {
  202. // These are the default values but feel free to customize
  203. callees: ['classnames', 'clsx', 'ctl', 'cn', 'classNames'],
  204. config: 'tailwind.config.js', // returned from `loadConfig()` utility if not provided
  205. cssFiles: [
  206. '**/*.css',
  207. '!**/node_modules',
  208. '!**/.*',
  209. '!**/dist',
  210. '!**/build',
  211. '!**/.storybook',
  212. '!**/.next',
  213. '!**/.public',
  214. ],
  215. cssFilesRefreshRate: 5_000,
  216. removeDuplicates: true,
  217. skipClassAttribute: false,
  218. whitelist: [],
  219. tags: [], // can be set to e.g. ['tw'] for use in tw`bg-blue`
  220. classRegex: '^class(Name)?$', // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro`
  221. },
  222. },
  223. rules: {
  224. // due to 1k lines of tailwind config, these rule have performance issue
  225. 'tailwindcss/no-contradicting-classname': 'off',
  226. 'tailwindcss/enforces-shorthand': 'off',
  227. 'tailwindcss/no-custom-classname': 'off',
  228. 'tailwindcss/no-unnecessary-arbitrary-value': 'off',
  229. 'tailwindcss/no-arbitrary-value': 'off',
  230. 'tailwindcss/classnames-order': 'warn',
  231. 'tailwindcss/enforces-negative-arbitrary-values': 'warn',
  232. 'tailwindcss/migration-from-tailwind-2': 'warn',
  233. },
  234. },
  235. oxlint.configs['flat/recommended'],
  236. )