Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

eslint.config.mjs 7.5KB

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