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.

eslint.config.mjs 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. '**/*.js',
  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. // sonar
  134. {
  135. rules: {
  136. ...sonar.configs.recommended.rules,
  137. // code complexity
  138. 'sonarjs/cognitive-complexity': 'off',
  139. 'sonarjs/no-nested-functions': 'warn',
  140. 'sonarjs/no-nested-conditional': 'warn',
  141. 'sonarjs/nested-control-flow': 'warn', // 3 levels of nesting
  142. 'sonarjs/no-small-switch': 'off',
  143. 'sonarjs/no-nested-template-literals': 'warn',
  144. 'sonarjs/redundant-type-aliases': 'off',
  145. 'sonarjs/regex-complexity': 'warn',
  146. // maintainability
  147. 'sonarjs/no-ignored-exceptions': 'off',
  148. 'sonarjs/no-commented-code': 'warn',
  149. 'sonarjs/no-unused-vars': 'warn',
  150. 'sonarjs/prefer-single-boolean-return': 'warn',
  151. 'sonarjs/duplicates-in-character-class': 'off',
  152. 'sonarjs/single-char-in-character-classes': 'off',
  153. 'sonarjs/anchor-precedence': 'warn',
  154. 'sonarjs/updated-loop-counter': 'off',
  155. 'sonarjs/no-dead-store': 'error',
  156. 'sonarjs/no-duplicated-branches': 'warn',
  157. 'sonarjs/max-lines': 'warn', // max 1000 lines
  158. 'sonarjs/no-variable-usage-before-declaration': 'error',
  159. // security
  160. 'sonarjs/no-hardcoded-passwords': 'off', // detect the wrong code that is not password.
  161. 'sonarjs/no-hardcoded-secrets': 'off',
  162. 'sonarjs/pseudo-random': 'off',
  163. // performance
  164. 'sonarjs/slow-regex': 'warn',
  165. // others
  166. 'sonarjs/todo-tag': 'warn',
  167. 'sonarjs/table-header': 'off',
  168. },
  169. plugins: {
  170. sonarjs: sonar,
  171. },
  172. },
  173. // need further research
  174. {
  175. rules: {
  176. // not exist in old version
  177. 'antfu/consistent-list-newline': 'off',
  178. 'node/prefer-global/process': 'off',
  179. 'node/prefer-global/buffer': 'off',
  180. 'node/no-callback-literal': 'off',
  181. // useful, but big change
  182. 'unicorn/prefer-number-properties': 'warn',
  183. 'unicorn/no-new-array': 'warn',
  184. 'style/indent': 'off',
  185. },
  186. },
  187. // suppress error for `no-undef` rule
  188. {
  189. files: GLOB_TESTS,
  190. languageOptions: {
  191. globals: {
  192. ...globals.browser,
  193. ...globals.es2021,
  194. ...globals.node,
  195. ...globals.jest,
  196. },
  197. },
  198. },
  199. tailwind.configs['flat/recommended'],
  200. {
  201. settings: {
  202. tailwindcss: {
  203. // These are the default values but feel free to customize
  204. callees: ['classnames', 'clsx', 'ctl', 'cn', 'classNames'],
  205. config: 'tailwind.config.js', // returned from `loadConfig()` utility if not provided
  206. cssFiles: [
  207. '**/*.css',
  208. '!**/node_modules',
  209. '!**/.*',
  210. '!**/dist',
  211. '!**/build',
  212. '!**/.storybook',
  213. '!**/.next',
  214. '!**/.public',
  215. ],
  216. cssFilesRefreshRate: 5_000,
  217. removeDuplicates: true,
  218. skipClassAttribute: false,
  219. whitelist: [],
  220. tags: [], // can be set to e.g. ['tw'] for use in tw`bg-blue`
  221. classRegex: '^class(Name)?$', // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro`
  222. },
  223. },
  224. rules: {
  225. // due to 1k lines of tailwind config, these rule have performance issue
  226. 'tailwindcss/no-contradicting-classname': 'off',
  227. 'tailwindcss/enforces-shorthand': 'off',
  228. 'tailwindcss/no-custom-classname': 'off',
  229. 'tailwindcss/no-unnecessary-arbitrary-value': 'off',
  230. 'tailwindcss/no-arbitrary-value': 'off',
  231. 'tailwindcss/classnames-order': 'warn',
  232. 'tailwindcss/enforces-negative-arbitrary-values': 'warn',
  233. 'tailwindcss/migration-from-tailwind-2': 'warn',
  234. },
  235. },
  236. oxlint.configs['flat/recommended'],
  237. )