-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts.js
131 lines (109 loc) · 4.47 KB
/
ts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/** @type {import("eslint").Linter.Config} */
const config = {
parserOptions: {
warnOnUnsupportedTypeScriptVersion: false,
},
plugins: ["@typescript-eslint"],
extends: [
"./js.js",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/strict-type-checked",
"./ts-extensions.js",
],
overrides: [
{
files: ["*.ts", "*.tsx"],
extends: ["biome"],
},
],
rules: {
// Allows explicitating implicit types, like `const a: number = 10`
"@typescript-eslint/no-inferrable-types": "off",
// Else would complain about // @ts-ignore in .js files. If I didn't need this ts-comment, this could be removed
"@typescript-eslint/ban-ts-comment": "off",
// Warn if using a Promise without await/then/catch. Good to avoid running stuff in background non intentionally.
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md
"@typescript-eslint/no-floating-promises": "warn",
// This wasn't allowing different data types in `templates string`. Why the fuck not?
"@typescript-eslint/restrict-template-expressions": "off",
// Wasn't simply allowing `const a = x.y.functionA`.
"@typescript-eslint/unbound-method": "off",
// [1.1.0] Allows to use `const a = require('...')`. This is specially useful for `const pkg = require('../package.json')`,
// as TS will complain about importing a file outside rootDir (defined in tsconfig)
"@typescript-eslint/no-var-requires": "off",
// Allow having a `function a(callback: () => void) {...}` to be called with a(async () => {...})`
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: false,
},
],
// Allow 'aString'.match('a').
// https://github.com/typescript-eslint/typescript-eslint/blob/v4.28.3/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md
"@typescript-eslint/prefer-regexp-exec": "off",
/** Disable it to allow empty catch blocks. */
"@typescript-eslint/no-empty-function": "off",
/**
* This is kinda useless. It's more of a pain, actually:
* If you are writting a function like f({}: Props) to later fill the object with the desired props,
* it will mark it as an error.
* https://eslint.org/docs/rules/no-empty-pattern
*/
"no-empty-pattern": "off",
/** https://typescript-eslint.io/rules/no-unnecessary-condition/ */
"@typescript-eslint/no-unnecessary-condition": [
"warn",
{
allowConstantLoopConditions: true, // Allow `while (true)`
},
],
/**
* =========== Unsafe ===========
* === Be responsible and careful! ====
*/
// Allows using `a!.b`. Not safe, but sometimes we really know it is valid.
// Let us have our empty stuff!
"@typescript-eslint/no-empty-interface": "off",
/** [2022-02-03] It's bugging often, so I disabled it. */
"@typescript-eslint/restrict-plus-operands": "off",
/**
* Remove unnecessary boolean literal conditionals`.
* https://typescript-eslint.io/rules/no-unnecessary-boolean-literal-compare
*/
"@typescript-eslint/no-unnecessary-boolean-literal-compare": [
"warn",
{
allowComparingNullableBooleansToTrue: false,
},
],
/**
* TS handles this, it raised false-positives sometimes.
* https://github.com/Chatie/eslint-config/issues/45#issuecomment-1003990077
*/
"no-undef": "off",
/** -=-=-=- Disallow dangerous stuff, converts recommended warn to error -=-=-=- */
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-return": "error",
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/no-non-null-assertion": "error",
/**
* Prefer Array<string> instead of string[]. Faster to read and to change.
*
* https://typescript-eslint.io/rules/array-type/
*/
"@typescript-eslint/array-type": ["warn", { default: "generic" }],
/**
* https://typescript-eslint.io/rules/prefer-string-starts-ends-with/
*/
"@typescript-eslint/prefer-string-starts-ends-with": "warn",
/**
* Requires all the switch's possibilities to be defined.
*
* https://typescript-eslint.io/rules/switch-exhaustiveness-check/
*/
"@typescript-eslint/switch-exhaustiveness-check": "warn",
},
}
module.exports = config