1
1
const { eslintRulesExtra } = require ( "./official-eslint-rules" )
2
2
const { pluginImportRulesExtra, pluginImportTypeScriptRulesExtra } = require ( "./plugin-import-rules" )
3
3
const { pluginNodeRules } = require ( "./plugin-node-rules" )
4
+ const glob = require ( "fast-glob" )
5
+
6
+ const project = [ "./**/tsconfig.json" , "!./**/node_modules/**/tsconfig.json" ]
7
+
8
+ const projectedBasedRules = glob . sync ( project , { onlyFiles : true , suppressErrors : true } ) . length !== 0
9
+ if ( ! projectedBasedRules ) {
10
+ console . warn (
11
+ "\x1b[33m%s\x1b[0m" ,
12
+ "No tsconfig.json found, disabling the project-based rules. To enable them, include all the **/*.ts(x)? files in the includes of the tsconfig.json files and run eslint again."
13
+ )
14
+ }
4
15
5
16
const pluginTypeScriptRulesExtra = {
6
17
"@typescript-eslint/no-unused-vars" : [
@@ -23,32 +34,37 @@ const pluginTypeScriptRulesExtra = {
23
34
"@typescript-eslint/no-shadow" : "error" ,
24
35
"@typescript-eslint/no-dynamic-delete" : "error" ,
25
36
"@typescript-eslint/no-extraneous-class" : "error" ,
26
- "@typescript-eslint/no-floating-promises" : "error" ,
27
37
"@typescript-eslint/no-parameter-properties" : "error" ,
28
- "@typescript-eslint/no-unnecessary-boolean-literal-compare" : "error" ,
29
- "@typescript-eslint/no-unnecessary-condition" : "error" ,
30
- "@typescript-eslint/no-unnecessary-qualifier" : "error" ,
31
38
// "@typescript-eslint/no-unnecessary-type-arguments": "error",
32
39
"@typescript-eslint/no-unnecessary-type-constraint" : "error" ,
33
- "@typescript-eslint/no-unsafe-argument" : "error" ,
34
40
// "@typescript-eslint/prefer-function-type": "error",
35
- "@typescript-eslint/prefer-includes" : "error" ,
36
41
// "@typescript-eslint/prefer-literal-enum-member": "error",
37
- "@typescript-eslint/prefer-nullish-coalescing" : "error" ,
38
42
"@typescript-eslint/prefer-optional-chain" : "error" ,
39
- "@typescript-eslint/prefer-reduce-type-parameter" : "error" ,
40
43
// "@typescript-eslint/prefer-string-starts-ends-with": "error",
41
- "@typescript-eslint/require-array-sort-compare" : "error" ,
42
- "@typescript-eslint/strict-boolean-expressions" : "error" ,
43
- "@typescript-eslint/switch-exhaustiveness-check" : "warn" ,
44
44
}
45
45
46
+ const pluginTypeScriptProjectRules = projectedBasedRules
47
+ ? {
48
+ "@typescript-eslint/no-floating-promises" : "error" ,
49
+ "@typescript-eslint/no-unnecessary-boolean-literal-compare" : "error" ,
50
+ "@typescript-eslint/no-unnecessary-condition" : "error" ,
51
+ "@typescript-eslint/no-unnecessary-qualifier" : "error" ,
52
+ "@typescript-eslint/no-unsafe-argument" : "error" ,
53
+ "@typescript-eslint/prefer-includes" : "error" ,
54
+ "@typescript-eslint/prefer-nullish-coalescing" : "error" ,
55
+ "@typescript-eslint/prefer-reduce-type-parameter" : "error" ,
56
+ "@typescript-eslint/require-array-sort-compare" : "error" ,
57
+ "@typescript-eslint/strict-boolean-expressions" : "error" ,
58
+ "@typescript-eslint/switch-exhaustiveness-check" : "warn" ,
59
+ }
60
+ : { }
61
+
46
62
exports . tsConfig = {
47
63
// TypeScript files
48
- files : [ "**/*.ts " , "**/*.tsx " ] ,
64
+ files : [ "**/*.tsx " , "**/*.ts " ] ,
49
65
parser : "@typescript-eslint/parser" ,
50
66
parserOptions : {
51
- project : [ "./**/tsconfig.json" , "!./**/node_modules/**/tsconfig.json" ] ,
67
+ project,
52
68
createDefaultProgram : true , // otherwise Eslint will error if a ts file is not covered by one of the tsconfig.json files
53
69
} ,
54
70
plugins : [ "@typescript-eslint" , "node" , "import" , "only-warn" ] ,
@@ -63,6 +79,7 @@ exports.tsConfig = {
63
79
rules : {
64
80
...eslintRulesExtra ,
65
81
...pluginTypeScriptRulesExtra ,
82
+ ...pluginTypeScriptProjectRules ,
66
83
...pluginNodeRules ,
67
84
...pluginImportRulesExtra ,
68
85
...pluginImportTypeScriptRulesExtra ,
0 commit comments