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

328 行
9.8 KiB

  1. {
  2. "env": {
  3. "es6": true
  4. },
  5. "extends": [
  6. "eslint:recommended",
  7. "plugin:@typescript-eslint/recommended",
  8. "plugin:@typescript-eslint/recommended-requiring-type-checking",
  9. "plugin:import/recommended",
  10. "plugin:import/typescript",
  11. "prettier"
  12. ],
  13. "parser": "@typescript-eslint/parser",
  14. "parserOptions": {
  15. "ecmaVersion": 2019,
  16. "sourceType": "module",
  17. "ecmaFeatures": {
  18. "impliedStrict": true
  19. }
  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. "arrow-parens": ["off"],
  27. "brace-style": ["off", "stroustrup"],
  28. "consistent-return": "off",
  29. "curly": ["error", "multi-line", "consistent"],
  30. "eol-last": "error",
  31. "linebreak-style": ["error", "unix"],
  32. "new-parens": "error",
  33. "no-console": "off",
  34. "no-constant-condition": ["warn", { "checkLoops": false }],
  35. "no-constant-binary-expression": "error",
  36. "no-caller": "error",
  37. "no-debugger": "off",
  38. "no-dupe-class-members": "off",
  39. "no-else-return": "warn",
  40. "no-empty": ["warn", { "allowEmptyCatch": true }],
  41. "no-eval": "error",
  42. "no-ex-assign": "warn",
  43. "no-extend-native": "error",
  44. "no-extra-bind": "error",
  45. "no-floating-decimal": "error",
  46. "no-implicit-coercion": "error",
  47. "no-implied-eval": "error",
  48. // Turn off until fix for: https://github.com/typescript-eslint/typescript-eslint/issues/239
  49. "no-inner-declarations": "off",
  50. "no-lone-blocks": "error",
  51. "no-lonely-if": "error",
  52. "no-loop-func": "error",
  53. "no-multi-spaces": "error",
  54. "no-restricted-imports": [
  55. "error",
  56. {
  57. "paths": [
  58. "lodash",
  59. "lodash-es",
  60. // Disallow node imports below
  61. "assert",
  62. "buffer",
  63. "child_process",
  64. "cluster",
  65. "crypto",
  66. "dgram",
  67. "dns",
  68. "domain",
  69. "events",
  70. "freelist",
  71. "fs",
  72. "http",
  73. "https",
  74. "module",
  75. "net",
  76. "os",
  77. "path",
  78. "punycode",
  79. "querystring",
  80. "readline",
  81. "repl",
  82. "smalloc",
  83. "stream",
  84. "string_decoder",
  85. "sys",
  86. "timers",
  87. "tls",
  88. "tracing",
  89. "tty",
  90. "url",
  91. "util",
  92. "vm",
  93. "zlib"
  94. ],
  95. "patterns": [
  96. {
  97. "group": ["**/env/**/*"],
  98. "message": "Use @env/ instead"
  99. }
  100. ]
  101. }
  102. ],
  103. "no-return-assign": "error",
  104. "no-return-await": "warn",
  105. "no-self-compare": "error",
  106. "no-sequences": "error",
  107. "no-template-curly-in-string": "warn",
  108. "no-throw-literal": "error",
  109. "no-unmodified-loop-condition": "warn",
  110. "no-unneeded-ternary": "error",
  111. "no-use-before-define": "off",
  112. "no-useless-call": "error",
  113. "no-useless-catch": "error",
  114. "no-useless-computed-key": "error",
  115. "no-useless-concat": "error",
  116. "no-useless-rename": "error",
  117. "no-useless-return": "error",
  118. "no-var": "error",
  119. "no-with": "error",
  120. "object-shorthand": ["error", "never"],
  121. "one-var": ["error", "never"],
  122. "prefer-arrow-callback": "error",
  123. "prefer-const": [
  124. "error",
  125. {
  126. "destructuring": "all",
  127. "ignoreReadBeforeAssign": false
  128. }
  129. ],
  130. "prefer-numeric-literals": "error",
  131. "prefer-object-spread": "error",
  132. "prefer-rest-params": "error",
  133. "prefer-spread": "error",
  134. "prefer-template": "error",
  135. "quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
  136. // Turn off until fix for: https://github.com/eslint/eslint/issues/11899
  137. "require-atomic-updates": "off",
  138. "semi": ["error", "always"],
  139. "semi-style": ["error", "last"],
  140. "sort-imports": [
  141. "error",
  142. {
  143. "ignoreCase": true,
  144. "ignoreDeclarationSort": true,
  145. "ignoreMemberSort": false,
  146. "memberSyntaxSortOrder": ["none", "all", "multiple", "single"]
  147. }
  148. ],
  149. "yoda": "error",
  150. "import/export": "off",
  151. "import/extensions": ["error", "never"],
  152. "import/named": "off",
  153. "import/namespace": "off",
  154. "import/newline-after-import": "warn",
  155. "import/no-cycle": "off",
  156. "import/no-dynamic-require": "error",
  157. "import/no-default-export": "error",
  158. "import/no-self-import": "error",
  159. "import/no-unresolved": ["warn", { "ignore": ["vscode", "@env"] }],
  160. "import/order": [
  161. "warn",
  162. {
  163. "alphabetize": { "order": "asc", "caseInsensitive": true },
  164. "groups": ["builtin", "external", "internal", ["parent", "sibling", "index"]],
  165. // "groups": ["builtin", "external", "internal", ["index", "sibling", "parent"]],
  166. "newlines-between": "never"
  167. }
  168. ],
  169. "@typescript-eslint/ban-types": [
  170. "error",
  171. {
  172. "extendDefaults": false,
  173. "types": {
  174. "String": {
  175. "message": "Use string instead",
  176. "fixWith": "string"
  177. },
  178. "Boolean": {
  179. "message": "Use boolean instead",
  180. "fixWith": "boolean"
  181. },
  182. "Number": {
  183. "message": "Use number instead",
  184. "fixWith": "number"
  185. },
  186. "Symbol": {
  187. "message": "Use symbol instead",
  188. "fixWith": "symbol"
  189. },
  190. // "Function": {
  191. // "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."
  192. // },
  193. "Object": {
  194. "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."
  195. },
  196. "{}": {
  197. "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.",
  198. "fixWith": "object"
  199. }
  200. // "object": {
  201. // "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."
  202. // }
  203. }
  204. }
  205. ],
  206. "@typescript-eslint/consistent-type-assertions": [
  207. "error",
  208. {
  209. "assertionStyle": "as",
  210. "objectLiteralTypeAssertions": "allow-as-parameter"
  211. }
  212. ],
  213. "@typescript-eslint/explicit-function-return-type": "off",
  214. "@typescript-eslint/explicit-member-accessibility": "off",
  215. "@typescript-eslint/explicit-module-boundary-types": "off", // TODO@eamodio revisit
  216. "@typescript-eslint/naming-convention": [
  217. "error",
  218. {
  219. "selector": "variable",
  220. "format": ["camelCase", "PascalCase"],
  221. "leadingUnderscore": "allow",
  222. "filter": {
  223. "regex": "^_$",
  224. "match": false
  225. }
  226. },
  227. {
  228. "selector": "variableLike",
  229. "format": ["camelCase"],
  230. "leadingUnderscore": "allow",
  231. "filter": {
  232. "regex": "^_$",
  233. "match": false
  234. }
  235. },
  236. {
  237. "selector": "memberLike",
  238. "modifiers": ["private"],
  239. "format": ["camelCase"],
  240. "leadingUnderscore": "allow"
  241. },
  242. {
  243. "selector": "memberLike",
  244. "modifiers": ["private", "readonly"],
  245. "format": ["camelCase", "PascalCase"],
  246. "leadingUnderscore": "allow"
  247. },
  248. {
  249. "selector": "memberLike",
  250. "modifiers": ["static", "readonly"],
  251. "format": ["camelCase", "PascalCase"]
  252. },
  253. {
  254. "selector": "interface",
  255. "format": ["PascalCase"],
  256. "custom": {
  257. "regex": "^I[A-Z]",
  258. "match": false
  259. }
  260. }
  261. ],
  262. "@typescript-eslint/no-duplicate-imports": "error",
  263. "@typescript-eslint/no-empty-function": "off",
  264. "@typescript-eslint/no-empty-interface": "error",
  265. "@typescript-eslint/no-explicit-any": "off",
  266. "@typescript-eslint/no-floating-promises": "error",
  267. "@typescript-eslint/no-inferrable-types": ["warn", { "ignoreParameters": true, "ignoreProperties": true }],
  268. "@typescript-eslint/no-misused-promises": ["error", { "checksVoidReturn": false }],
  269. "@typescript-eslint/no-namespace": "off",
  270. "@typescript-eslint/no-non-null-assertion": "off",
  271. "@typescript-eslint/no-parameter-properties": "off",
  272. "@typescript-eslint/no-unnecessary-condition": "off",
  273. "@typescript-eslint/no-unsafe-argument": "off",
  274. "@typescript-eslint/no-unsafe-assignment": "off",
  275. "@typescript-eslint/no-unsafe-call": "off",
  276. "@typescript-eslint/no-unsafe-member-access": "off",
  277. "@typescript-eslint/no-unsafe-return": "off",
  278. "@typescript-eslint/no-unused-expressions": ["warn", { "allowShortCircuit": true }],
  279. "@typescript-eslint/no-unused-vars": [
  280. "warn",
  281. {
  282. "args": "after-used",
  283. "argsIgnorePattern": "^_",
  284. "ignoreRestSiblings": true,
  285. "varsIgnorePattern": "^_$"
  286. }
  287. ],
  288. "@typescript-eslint/no-use-before-define": "off",
  289. "@typescript-eslint/prefer-nullish-coalescing": "off",
  290. "@typescript-eslint/prefer-optional-chain": "warn",
  291. "@typescript-eslint/restrict-template-expressions": [
  292. "error",
  293. { "allowAny": true, "allowBoolean": true, "allowNumber": true, "allowNullish": true }
  294. ],
  295. "@typescript-eslint/strict-boolean-expressions": [
  296. "warn",
  297. {
  298. "allowString": true,
  299. "allowNumber": true,
  300. "allowNullableObject": false,
  301. "allowNullableBoolean": true,
  302. "allowNullableNumber": true,
  303. "allowNullableString": true,
  304. "allowAny": false
  305. }
  306. ],
  307. "@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
  308. },
  309. "settings": {
  310. "import/parsers": {
  311. "@typescript-eslint/parser": [".ts", ".tsx"]
  312. },
  313. "import/resolver": {
  314. "typescript": {
  315. "alwaysTryTypes": true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
  316. }
  317. }
  318. },
  319. "ignorePatterns": ["dist/*", "out/*", "**/@types/*", "emojis.json", "tsconfig*.tsbuildinfo", "webpack.config*.js"],
  320. "overrides": [
  321. {
  322. "files": ["src/env/node/**/*"],
  323. "rules": {
  324. "no-restricted-imports": "off"
  325. }
  326. }
  327. ]
  328. }