Skip to content

Commit e5fc062

Browse files
authored
Merge pull request #70 from atom-community/typescript-project-based [skip ci]
2 parents 11e25dc + a2de066 commit e5fc062

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"eslint-plugin-optimize-regex": "^1.2.1",
3838
"eslint-plugin-react": "^7.32.2",
3939
"eslint-plugin-yaml": "^0.5.0",
40+
"fast-glob": "^3.2.12",
4041
"prettier": "2.8.8",
4142
"read-pkg-up": "^7.0.1",
4243
"semver": "^7.5.1",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/typescript.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
const { eslintRulesExtra } = require("./official-eslint-rules")
22
const { pluginImportRulesExtra, pluginImportTypeScriptRulesExtra } = require("./plugin-import-rules")
33
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+
}
415

516
const 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+
4662
exports.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

Comments
 (0)