11const { eslintRulesExtra } = require ( "./official-eslint-rules" )
22const { pluginImportRulesExtra, pluginImportTypeScriptRulesExtra } = require ( "./plugin-import-rules" )
33const { 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+ }
415
516const pluginTypeScriptRulesExtra = {
617 "@typescript-eslint/no-unused-vars" : [
@@ -23,32 +34,37 @@ const pluginTypeScriptRulesExtra = {
2334 "@typescript-eslint/no-shadow" : "error" ,
2435 "@typescript-eslint/no-dynamic-delete" : "error" ,
2536 "@typescript-eslint/no-extraneous-class" : "error" ,
26- "@typescript-eslint/no-floating-promises" : "error" ,
2737 "@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" ,
3138 // "@typescript-eslint/no-unnecessary-type-arguments": "error",
3239 "@typescript-eslint/no-unnecessary-type-constraint" : "error" ,
33- "@typescript-eslint/no-unsafe-argument" : "error" ,
3440 // "@typescript-eslint/prefer-function-type": "error",
35- "@typescript-eslint/prefer-includes" : "error" ,
3641 // "@typescript-eslint/prefer-literal-enum-member": "error",
37- "@typescript-eslint/prefer-nullish-coalescing" : "error" ,
3842 "@typescript-eslint/prefer-optional-chain" : "error" ,
39- "@typescript-eslint/prefer-reduce-type-parameter" : "error" ,
4043 // "@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" ,
4444}
4545
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+
4662exports . tsConfig = {
4763 // TypeScript files
48- files : [ "**/*.ts " , "**/*.tsx " ] ,
64+ files : [ "**/*.tsx " , "**/*.ts " ] ,
4965 parser : "@typescript-eslint/parser" ,
5066 parserOptions : {
51- project : [ "./**/tsconfig.json" , "!./**/node_modules/**/tsconfig.json" ] ,
67+ project,
5268 createDefaultProgram : true , // otherwise Eslint will error if a ts file is not covered by one of the tsconfig.json files
5369 } ,
5470 plugins : [ "@typescript-eslint" , "node" , "import" , "only-warn" ] ,
@@ -63,6 +79,7 @@ exports.tsConfig = {
6379 rules : {
6480 ...eslintRulesExtra ,
6581 ...pluginTypeScriptRulesExtra ,
82+ ...pluginTypeScriptProjectRules ,
6683 ...pluginNodeRules ,
6784 ...pluginImportRulesExtra ,
6885 ...pluginImportTypeScriptRulesExtra ,
0 commit comments