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.

341 lines
10 KiB

  1. {
  2. "env": {
  3. "es6": true
  4. },
  5. "extends": [
  6. "eslint:recommended",
  7. "plugin:@typescript-eslint/strict-type-checked",
  8. "plugin:import/recommended",
  9. "plugin:import/typescript",
  10. "prettier"
  11. ],
  12. "parser": "@typescript-eslint/parser",
  13. "parserOptions": {
  14. "ecmaVersion": 2022,
  15. "sourceType": "module",
  16. "ecmaFeatures": {
  17. "impliedStrict": true
  18. },
  19. "project": true
  20. },
  21. "plugins": ["anti-trojan-source", "import", "@typescript-eslint"],
  22. "reportUnusedDisableDirectives": true,
  23. "root": true,
  24. "rules": {
  25. "anti-trojan-source/no-bidi": "error",
  26. "no-constant-condition": ["warn", { "checkLoops": false }],
  27. "no-constant-binary-expression": "error",
  28. "no-caller": "error",
  29. "no-debugger": "off",
  30. "no-else-return": "warn",
  31. "no-empty": ["warn", { "allowEmptyCatch": true }],
  32. "no-eval": "error",
  33. "no-ex-assign": "warn",
  34. "no-extend-native": "error",
  35. "no-extra-bind": "error",
  36. "no-extra-semi": "off",
  37. "no-floating-decimal": "error",
  38. "no-implicit-coercion": "error",
  39. "no-implied-eval": "error",
  40. "no-inner-declarations": "off",
  41. "no-lone-blocks": "error",
  42. "no-lonely-if": "error",
  43. "no-loop-func": "error",
  44. "no-mixed-spaces-and-tabs": "off",
  45. "no-restricted-globals": ["error", "process"],
  46. "no-restricted-imports": [
  47. "error",
  48. {
  49. "paths": [
  50. // Disallow node imports below
  51. "assert",
  52. "buffer",
  53. "child_process",
  54. "cluster",
  55. "crypto",
  56. "dgram",
  57. "dns",
  58. "domain",
  59. "events",
  60. "freelist",
  61. "fs",
  62. "http",
  63. "https",
  64. "module",
  65. "net",
  66. "os",
  67. "path",
  68. "process",
  69. "punycode",
  70. "querystring",
  71. "readline",
  72. "repl",
  73. "smalloc",
  74. "stream",
  75. "string_decoder",
  76. "sys",
  77. "timers",
  78. "tls",
  79. "tracing",
  80. "tty",
  81. "url",
  82. "util",
  83. "vm",
  84. "zlib"
  85. ],
  86. "patterns": [
  87. {
  88. "group": ["**/env/**/*"],
  89. "message": "Use @env/ instead"
  90. },
  91. {
  92. "group": ["src/*"],
  93. "message": "Use relative paths instead"
  94. },
  95. {
  96. "group": ["react-dom"],
  97. "importNames": ["Container"],
  98. "message": "Use our Container instead"
  99. },
  100. {
  101. "group": ["vscode"],
  102. "importNames": ["CancellationError"],
  103. "message": "Use our CancellationError instead"
  104. }
  105. ]
  106. }
  107. ],
  108. "no-return-assign": "error",
  109. "no-return-await": "warn",
  110. "no-self-compare": "error",
  111. "no-sequences": "error",
  112. "no-template-curly-in-string": "warn",
  113. "no-throw-literal": "error",
  114. "no-unmodified-loop-condition": "warn",
  115. "no-unneeded-ternary": "error",
  116. "no-unused-expressions": "error",
  117. "no-use-before-define": "off",
  118. "no-useless-call": "error",
  119. "no-useless-catch": "error",
  120. "no-useless-computed-key": "error",
  121. "no-useless-concat": "error",
  122. "no-useless-rename": "error",
  123. "no-useless-return": "error",
  124. "no-var": "error",
  125. "no-with": "error",
  126. "object-shorthand": ["error", "never"],
  127. "one-var": ["error", "never"],
  128. "prefer-arrow-callback": "error",
  129. "prefer-const": [
  130. "error",
  131. {
  132. "destructuring": "all",
  133. "ignoreReadBeforeAssign": true
  134. }
  135. ],
  136. "prefer-numeric-literals": "error",
  137. "prefer-object-spread": "error",
  138. "prefer-promise-reject-errors": ["error", { "allowEmptyReject": true }],
  139. "prefer-rest-params": "error",
  140. "prefer-spread": "error",
  141. "prefer-template": "error",
  142. "require-atomic-updates": "off",
  143. "sort-imports": [
  144. "error",
  145. {
  146. "ignoreCase": true,
  147. "ignoreDeclarationSort": true,
  148. "ignoreMemberSort": false,
  149. "memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
  150. }
  151. ],
  152. "yoda": "error",
  153. "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
  154. "import/extensions": "off",
  155. "import/newline-after-import": "warn",
  156. "import/no-absolute-path": "error",
  157. "import/no-cycle": "off",
  158. "import/no-default-export": "error",
  159. "import/no-duplicates": ["error", { "prefer-inline": false }],
  160. "import/no-dynamic-require": "error",
  161. "import/no-self-import": "error",
  162. "import/no-unresolved": ["warn", { "ignore": ["vscode", "@env"] }],
  163. "import/no-useless-path-segments": "error",
  164. "import/order": [
  165. "warn",
  166. {
  167. "alphabetize": {
  168. "order": "asc",
  169. "orderImportKind": "asc",
  170. "caseInsensitive": true
  171. },
  172. "groups": ["builtin", "external", "internal", "parent", "sibling", "index"],
  173. "newlines-between": "never"
  174. }
  175. ],
  176. "@typescript-eslint/ban-types": [
  177. "error",
  178. {
  179. "extendDefaults": false,
  180. "types": {
  181. "String": {
  182. "message": "Use string instead",
  183. "fixWith": "string"
  184. },
  185. "Boolean": {
  186. "message": "Use boolean instead",
  187. "fixWith": "boolean"
  188. },
  189. "Number": {
  190. "message": "Use number instead",
  191. "fixWith": "number"
  192. },
  193. "Symbol": {
  194. "message": "Use symbol instead",
  195. "fixWith": "symbol"
  196. },
  197. // "Function": {
  198. // "message": "The `Function` type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with `new`.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape."
  199. // },
  200. "Object": {
  201. "message": "The `Object` type actually means \"any non-nullish value\", so it is marginally better than `unknown`.\n- If you want a type meaning \"any object\", you probably want `Record<string, unknown>` instead.\n- If you want a type meaning \"any value\", you probably want `unknown` instead."
  202. },
  203. "{}": {
  204. "message": "`{}` actually means \"any non-nullish value\".\n- If you want a type meaning \"any object\", you probably want `object` or `Record<string, unknown>` instead.\n- If you want a type meaning \"any value\", you probably want `unknown` instead.",
  205. "fixWith": "object"
  206. }
  207. // "object": {
  208. // "message": "The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).\nConsider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys."
  209. // }
  210. }
  211. }
  212. ],
  213. "@typescript-eslint/consistent-type-assertions": [
  214. "error",
  215. {
  216. "assertionStyle": "as",
  217. "objectLiteralTypeAssertions": "allow-as-parameter"
  218. }
  219. ],
  220. "@typescript-eslint/consistent-type-imports": ["error", { "disallowTypeAnnotations": false }],
  221. "@typescript-eslint/naming-convention": [
  222. "error",
  223. {
  224. "selector": "variable",
  225. "format": ["camelCase", "PascalCase"],
  226. "leadingUnderscore": "allow",
  227. "filter": {
  228. "regex": "^_$",
  229. "match": false
  230. }
  231. },
  232. {
  233. "selector": "variableLike",
  234. "format": ["camelCase"],
  235. "leadingUnderscore": "allow",
  236. "filter": {
  237. "regex": "^_$",
  238. "match": false
  239. }
  240. },
  241. {
  242. "selector": "memberLike",
  243. "modifiers": ["private"],
  244. "format": ["camelCase"],
  245. "leadingUnderscore": "allow"
  246. },
  247. {
  248. "selector": "memberLike",
  249. "modifiers": ["private", "readonly"],
  250. "format": ["camelCase", "PascalCase"],
  251. "leadingUnderscore": "allow"
  252. },
  253. {
  254. "selector": "memberLike",
  255. "modifiers": ["static", "readonly"],
  256. "format": ["camelCase", "PascalCase"]
  257. },
  258. {
  259. "selector": "interface",
  260. "format": ["PascalCase"],
  261. "custom": {
  262. "regex": "^I[A-Z]",
  263. "match": false
  264. }
  265. }
  266. ],
  267. "@typescript-eslint/no-confusing-void-expression": [
  268. "error",
  269. { "ignoreArrowShorthand": true, "ignoreVoidOperator": true }
  270. ],
  271. "@typescript-eslint/no-explicit-any": "off",
  272. "@typescript-eslint/no-inferrable-types": ["warn", { "ignoreParameters": true, "ignoreProperties": true }],
  273. "@typescript-eslint/no-invalid-void-type": "off", // Seems to error on `void` return types
  274. "@typescript-eslint/no-misused-promises": ["error", { "checksVoidReturn": false }],
  275. "@typescript-eslint/no-non-null-assertion": "off",
  276. "@typescript-eslint/no-redundant-type-constituents": "off",
  277. "@typescript-eslint/no-unnecessary-condition": "off",
  278. "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
  279. "@typescript-eslint/no-unsafe-argument": "off",
  280. "@typescript-eslint/no-unsafe-assignment": "off",
  281. "@typescript-eslint/no-unsafe-call": "off",
  282. "@typescript-eslint/no-unsafe-enum-comparison": "off",
  283. "@typescript-eslint/no-unsafe-member-access": "off",
  284. "@typescript-eslint/no-unused-expressions": ["warn", { "allowShortCircuit": true }],
  285. "@typescript-eslint/no-unused-vars": [
  286. "warn",
  287. {
  288. "args": "after-used",
  289. "argsIgnorePattern": "^_",
  290. "ignoreRestSiblings": true,
  291. "varsIgnorePattern": "^_$"
  292. }
  293. ],
  294. "@typescript-eslint/no-use-before-define": ["error", { "functions": false, "classes": false }],
  295. "@typescript-eslint/prefer-for-of": "warn",
  296. "@typescript-eslint/prefer-includes": "warn",
  297. "@typescript-eslint/prefer-literal-enum-member": ["warn", { "allowBitwiseExpressions": true }],
  298. "@typescript-eslint/prefer-optional-chain": "warn",
  299. "@typescript-eslint/prefer-reduce-type-parameter": "warn",
  300. "@typescript-eslint/restrict-template-expressions": [
  301. "error",
  302. { "allowAny": true, "allowBoolean": true, "allowNumber": true, "allowNullish": true }
  303. ],
  304. "@typescript-eslint/unbound-method": "off", // Too many bugs right now: https://github.com/typescript-eslint/typescript-eslint/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+unbound-method
  305. "@typescript-eslint/unified-signatures": ["error", { "ignoreDifferentlyNamedParameters": true }]
  306. },
  307. "settings": {
  308. "import/parsers": {
  309. "@typescript-eslint/parser": [".ts", ".tsx"]
  310. },
  311. "import/resolver": {
  312. "typescript": {
  313. "alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
  314. }
  315. }
  316. },
  317. "ignorePatterns": ["dist/*", "out/*", "**/@types/*", "emojis.json", "tsconfig*.tsbuildinfo", "webpack.config*.js"],
  318. "overrides": [
  319. {
  320. "files": ["src/env/node/**/*"],
  321. "rules": {
  322. "no-restricted-imports": [
  323. "error",
  324. {
  325. "patterns": [
  326. {
  327. "group": ["src/*"],
  328. "message": "Use relative paths instead"
  329. },
  330. {
  331. "group": ["react-dom"],
  332. "importNames": ["Container"],
  333. "message": "Use our Container instead"
  334. }
  335. ]
  336. }
  337. ]
  338. }
  339. }
  340. ]
  341. }