eslint.config.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import eslintConfigPrettier from 'eslint-config-prettier';
  2. import importPlugin from 'eslint-plugin-import';
  3. import jsdocPlugin from 'eslint-plugin-jsdoc';
  4. import preferArrowPlugin from 'eslint-plugin-prefer-arrow';
  5. import globals from 'globals';
  6. import tseslint from 'typescript-eslint';
  7. export default tseslint.config(
  8. // Ignores (equivalent to ignorePatterns)
  9. {
  10. ignores: [
  11. '**/node_modules/**',
  12. '**/dist/**',
  13. '**/generated*',
  14. '**/*.js',
  15. '**/*.d.ts',
  16. '/packages/ui-devkit/scaffold/**/*',
  17. '/packages/dev-server/load-testing/**/*',
  18. '/docs/layouts/**/*',
  19. ],
  20. },
  21. // Base config for all TS files
  22. {
  23. files: ['**/*.ts', '**/*.tsx'],
  24. extends: [...tseslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked],
  25. languageOptions: {
  26. parser: tseslint.parser,
  27. parserOptions: {
  28. project: true,
  29. sourceType: 'module',
  30. },
  31. globals: {
  32. ...globals.node,
  33. ...globals.es2021,
  34. },
  35. },
  36. plugins: {
  37. import: importPlugin,
  38. jsdoc: jsdocPlugin,
  39. 'prefer-arrow': preferArrowPlugin,
  40. },
  41. rules: {
  42. '@typescript-eslint/adjacent-overload-signatures': 'error',
  43. '@typescript-eslint/array-type': [
  44. 'error',
  45. {
  46. default: 'array-simple',
  47. },
  48. ],
  49. '@typescript-eslint/await-thenable': 'error',
  50. '@typescript-eslint/ban-ts-comment': 'off',
  51. // ban-types was removed in v8, replaced with:
  52. '@typescript-eslint/no-wrapper-object-types': 'error', // Bans Number, String, Boolean, etc.
  53. '@typescript-eslint/no-unsafe-function-type': 'error', // Bans Function type
  54. '@typescript-eslint/consistent-type-assertions': 'error',
  55. '@typescript-eslint/consistent-type-definitions': 'off',
  56. '@typescript-eslint/dot-notation': 'error',
  57. '@typescript-eslint/explicit-function-return-type': 'off',
  58. '@typescript-eslint/explicit-member-accessibility': [
  59. 'off',
  60. {
  61. accessibility: 'explicit',
  62. },
  63. ],
  64. '@typescript-eslint/explicit-module-boundary-types': 'off',
  65. '@typescript-eslint/indent': 'off',
  66. '@typescript-eslint/member-ordering': 'off',
  67. '@typescript-eslint/naming-convention': [
  68. 'off',
  69. {
  70. selector: 'variable',
  71. format: ['camelCase', 'UPPER_CASE'],
  72. leadingUnderscore: 'forbid',
  73. trailingUnderscore: 'forbid',
  74. },
  75. ],
  76. '@typescript-eslint/no-array-constructor': 'error',
  77. '@typescript-eslint/no-empty-function': 'error',
  78. '@typescript-eslint/no-empty-interface': 'off',
  79. '@typescript-eslint/no-explicit-any': 'off',
  80. '@typescript-eslint/no-extra-non-null-assertion': 'error',
  81. '@typescript-eslint/no-extra-semi': 'error',
  82. '@typescript-eslint/no-floating-promises': 'error',
  83. '@typescript-eslint/no-for-in-array': 'error',
  84. '@typescript-eslint/no-implied-eval': 'error',
  85. '@typescript-eslint/no-inferrable-types': [
  86. 'error',
  87. {
  88. ignoreParameters: true,
  89. },
  90. ],
  91. '@typescript-eslint/no-loss-of-precision': 'error',
  92. '@typescript-eslint/no-misused-new': 'error',
  93. '@typescript-eslint/no-misused-promises': 'warn',
  94. '@typescript-eslint/no-namespace': 'error',
  95. '@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
  96. '@typescript-eslint/no-non-null-assertion': 'error',
  97. '@typescript-eslint/no-parameter-properties': 'off',
  98. '@typescript-eslint/no-shadow': [
  99. 'error',
  100. {
  101. hoist: 'all',
  102. },
  103. ],
  104. '@typescript-eslint/no-this-alias': 'error',
  105. '@typescript-eslint/no-unnecessary-type-assertion': 'error',
  106. '@typescript-eslint/no-unnecessary-type-constraint': 'error',
  107. '@typescript-eslint/no-unsafe-argument': 'off',
  108. '@typescript-eslint/no-unsafe-assignment': 'off',
  109. '@typescript-eslint/no-unsafe-call': 'off',
  110. '@typescript-eslint/no-unsafe-member-access': 'off',
  111. '@typescript-eslint/no-unsafe-return': 'off',
  112. '@typescript-eslint/no-unused-expressions': 'error',
  113. '@typescript-eslint/no-unused-vars': 'off',
  114. '@typescript-eslint/no-use-before-define': 'off',
  115. '@typescript-eslint/no-var-requires': 'error',
  116. '@typescript-eslint/prefer-as-const': 'error',
  117. '@typescript-eslint/prefer-for-of': 'error',
  118. '@typescript-eslint/prefer-function-type': 'error',
  119. '@typescript-eslint/prefer-namespace-keyword': 'error',
  120. '@typescript-eslint/quotes': 'off',
  121. '@typescript-eslint/require-await': 'warn',
  122. '@typescript-eslint/restrict-plus-operands': 'error',
  123. '@typescript-eslint/restrict-template-expressions': 'error',
  124. '@typescript-eslint/triple-slash-reference': [
  125. 'error',
  126. {
  127. path: 'always',
  128. types: 'prefer-import',
  129. lib: 'always',
  130. },
  131. ],
  132. '@typescript-eslint/typedef': 'off',
  133. '@typescript-eslint/unbound-method': 'error',
  134. '@typescript-eslint/unified-signatures': 'error',
  135. 'arrow-parens': ['off', 'always'],
  136. complexity: 'off',
  137. 'constructor-super': 'error',
  138. 'dot-notation': 'off',
  139. eqeqeq: ['error', 'smart'],
  140. 'guard-for-in': 'error',
  141. 'id-denylist': 'off',
  142. 'id-match': 'off',
  143. 'import/order': [
  144. 'warn',
  145. {
  146. alphabetize: {
  147. caseInsensitive: true,
  148. order: 'asc',
  149. },
  150. 'newlines-between': 'always',
  151. groups: [
  152. ['builtin', 'external', 'internal', 'unknown', 'object', 'type'],
  153. 'parent',
  154. ['sibling', 'index'],
  155. ],
  156. distinctGroup: false,
  157. pathGroupsExcludedImportTypes: [],
  158. pathGroups: [
  159. {
  160. pattern: './',
  161. patternOptions: {
  162. nocomment: true,
  163. dot: true,
  164. },
  165. group: 'sibling',
  166. position: 'before',
  167. },
  168. {
  169. pattern: '.',
  170. patternOptions: {
  171. nocomment: true,
  172. dot: true,
  173. },
  174. group: 'sibling',
  175. position: 'before',
  176. },
  177. {
  178. pattern: '..',
  179. patternOptions: {
  180. nocomment: true,
  181. dot: true,
  182. },
  183. group: 'parent',
  184. position: 'before',
  185. },
  186. {
  187. pattern: '../',
  188. patternOptions: {
  189. nocomment: true,
  190. dot: true,
  191. },
  192. group: 'parent',
  193. position: 'before',
  194. },
  195. ],
  196. },
  197. ],
  198. indent: 'off',
  199. 'jsdoc/check-alignment': 'off',
  200. 'jsdoc/check-indentation': 'off',
  201. 'jsdoc/newline-after-description': 'off',
  202. 'max-classes-per-file': 'off',
  203. 'max-len': [
  204. 'error',
  205. {
  206. code: 170,
  207. },
  208. ],
  209. 'new-parens': 'error',
  210. 'no-array-constructor': 'off',
  211. 'no-bitwise': 'error',
  212. 'no-caller': 'error',
  213. 'no-cond-assign': 'error',
  214. 'no-console': 'error',
  215. 'no-debugger': 'error',
  216. 'no-empty': 'error',
  217. 'no-empty-function': 'off',
  218. 'no-eval': 'error',
  219. 'no-extra-semi': 'off',
  220. 'no-fallthrough': 'error',
  221. 'no-implied-eval': 'off',
  222. 'no-invalid-this': 'off',
  223. 'no-loss-of-precision': 'off',
  224. 'no-new-wrappers': 'error',
  225. 'no-shadow': 'off',
  226. 'no-throw-literal': 'error',
  227. 'no-trailing-spaces': 'error',
  228. 'no-undef-init': 'error',
  229. 'no-underscore-dangle': 'off',
  230. 'no-unsafe-finally': 'error',
  231. 'no-unused-expressions': 'off',
  232. 'no-unused-labels': 'error',
  233. 'no-unused-vars': 'off',
  234. 'no-use-before-define': 'off',
  235. 'no-var': 'error',
  236. 'object-shorthand': 'error',
  237. 'one-var': ['error', 'never'],
  238. 'prefer-arrow/prefer-arrow-functions': 'off',
  239. 'prefer-const': 'error',
  240. quotes: 'off',
  241. radix: 'error',
  242. 'require-await': 'off',
  243. 'spaced-comment': [
  244. 'error',
  245. 'always',
  246. {
  247. markers: ['/'],
  248. },
  249. ],
  250. 'use-isnan': 'error',
  251. 'valid-typeof': 'off',
  252. },
  253. },
  254. // Override for ui-devkit client
  255. {
  256. files: ['packages/ui-devkit/src/client/**/*'],
  257. languageOptions: {
  258. parserOptions: {
  259. project: './packages/ui-devkit/tsconfig.json',
  260. sourceType: 'module',
  261. },
  262. },
  263. },
  264. // Override for ui-devkit compiler
  265. {
  266. files: ['packages/ui-devkit/src/compiler/**/*'],
  267. languageOptions: {
  268. parserOptions: {
  269. project: './packages/ui-devkit/tsconfig.compiler.json',
  270. sourceType: 'module',
  271. },
  272. },
  273. },
  274. // Prettier config (must be last)
  275. eslintConfigPrettier,
  276. );