Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 854620e

Browse files
authored
fix: support long running "watch" lint sessions (typescript-eslint#973)
1 parent fec73b0 commit 854620e

33 files changed

+506
-119
lines changed

.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
//
3636

3737
'comma-dangle': ['error', 'always-multiline'],
38+
'constructor-super': 'off',
3839
curly: ['error', 'all'],
3940
'no-mixed-operators': 'error',
4041
'no-console': 'error',
@@ -113,7 +114,8 @@ module.exports = {
113114
ecmaFeatures: {
114115
jsx: false,
115116
},
116-
project: './tsconfig.base.json',
117+
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
118+
tsconfigRootDir: __dirname,
117119
},
118120
overrides: [
119121
{

.gitignore

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ jspm_packages/
5757
# next.js build output
5858
.next
5959

60-
.DS_Store
61-
.idea
62-
dist
6360

6461
# Editor-specific metadata folders
6562
.vs
63+
64+
.DS_Store
65+
.idea
66+
dist
67+
*.tsbuildinfo
68+
.watchmanconfig

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
"javascript.preferences.importModuleSpecifier": "auto",
2323
"typescript.preferences.importModuleSpecifier": "auto",
2424
"javascript.preferences.quoteStyle": "single",
25-
"typescript.preferences.quoteStyle": "single"
25+
"typescript.preferences.quoteStyle": "single",
26+
"editor.defaultFormatter": "esbenp.prettier-vscode"
2627
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"pre-push": "yarn format-check",
3434
"postinstall": "lerna bootstrap && yarn build && lerna link && npm run check-clean-workspace-after-install && opencollective-postinstall",
3535
"check-clean-workspace-after-install": "git diff --quiet --exit-code",
36-
"test": "lerna run test --parallel",
36+
"test": "lerna run test --concurrency 1",
3737
"typecheck": "lerna run typecheck"
3838
},
3939
"config": {
@@ -70,7 +70,6 @@
7070
"lint-staged": "^9.2.5",
7171
"opencollective-postinstall": "^2.0.2",
7272
"prettier": "^1.18.2",
73-
"rimraf": "^3.0.0",
7473
"ts-jest": "^24.0.0",
7574
"ts-node": "^8.3.0",
7675
"tslint": "^5.19.0",

packages/eslint-plugin-tslint/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
},
2424
"license": "MIT",
2525
"scripts": {
26-
"build": "tsc -p tsconfig.build.json",
27-
"clean": "rimraf dist/",
26+
"build": "tsc -b tsconfig.build.json",
27+
"clean": "tsc -b tsconfig.build.json --clean",
2828
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
29-
"prebuild": "npm run clean",
29+
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
3030
"test": "jest --coverage",
31-
"typecheck": "tsc --noEmit"
31+
"typecheck": "tsc -p tsconfig.json --noEmit"
3232
},
3333
"dependencies": {
3434
"@typescript-eslint/experimental-utils": "2.3.3",
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4-
"outDir": "./dist"
4+
"outDir": "./dist",
5+
"rootDir": "./src",
6+
"resolveJsonModule": true
57
},
6-
"include": ["src"]
8+
"include": ["src"],
9+
"references": [
10+
{ "path": "../experimental-utils/tsconfig.build.json" },
11+
{ "path": "../parser/tsconfig.build.json" },
12+
{ "path": "../typescript-estree/tsconfig.build.json" }
13+
]
714
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"extends": "./tsconfig.build.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"noEmit": true
6+
},
37
"include": ["src", "tests"],
48
"exclude": ["tests/test-project", "tests/test-tslint-rules-directory"]
59
}

packages/eslint-plugin/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
"license": "MIT",
3030
"main": "dist/index.js",
3131
"scripts": {
32-
"build": "tsc -p tsconfig.build.json",
32+
"build": "tsc -b tsconfig.build.json",
3333
"check:docs": "../../node_modules/.bin/ts-node --files ./tools/validate-docs/index.ts",
3434
"check:configs": "../../node_modules/.bin/ts-node --files ./tools/validate-configs/index.ts",
35-
"clean": "rimraf dist/",
35+
"clean": "tsc -b tsconfig.build.json --clean",
3636
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
3737
"generate:configs": "../../node_modules/.bin/ts-node --files tools/generate-configs.ts",
38-
"prebuild": "npm run clean",
38+
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
3939
"test": "jest --coverage",
40-
"typecheck": "tsc --noEmit"
40+
"typecheck": "tsc -p tsconfig.json --noEmit"
4141
},
4242
"dependencies": {
4343
"@typescript-eslint/experimental-utils": "2.3.3",

packages/eslint-plugin/tests/RuleTester.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TSESLint, ESLintUtils } from '@typescript-eslint/experimental-utils';
2+
import { clearCaches } from '@typescript-eslint/parser';
23
import * as path from 'path';
34

45
const parser = '@typescript-eslint/parser';
@@ -74,4 +75,10 @@ function getFixturesRootDir(): string {
7475

7576
const { batchedSingleLineTests } = ESLintUtils;
7677

78+
// make sure that the parser doesn't hold onto file handles between tests
79+
// on linux (i.e. our CI env), there can be very a limited number of watch handles available
80+
afterAll(() => {
81+
clearCaches();
82+
});
83+
7784
export { RuleTester, getFixturesRootDir, batchedSingleLineTests };

packages/eslint-plugin/tsconfig.build.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"declaration": false,
66
"declarationMap": false,
77
"outDir": "./dist",
8+
"rootDir": "./src",
89
"resolveJsonModule": true
910
},
10-
"include": [
11-
"src",
12-
"typings",
13-
// include the parser's ambient typings because the parser exports them in its type defs
14-
"../parser/typings"
11+
"include": ["src", "typings"],
12+
"references": [
13+
{ "path": "../experimental-utils/tsconfig.build.json" },
14+
{ "path": "../parser/tsconfig.build.json" },
15+
{ "path": "../typescript-estree/tsconfig.build.json" }
1516
]
1617
}

packages/eslint-plugin/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"extends": "./tsconfig.build.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"noEmit": true
6+
},
37
"include": ["src", "typings", "tests", "tools"]
48
}

packages/experimental-utils/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
"main": "dist/index.js",
2929
"types": "dist/index.d.ts",
3030
"scripts": {
31-
"test": "jest --coverage",
32-
"prebuild": "npm run clean",
33-
"build": "tsc -p tsconfig.build.json",
34-
"clean": "rimraf dist/",
31+
"build": "tsc -b tsconfig.build.json",
32+
"clean": "tsc -b tsconfig.build.json --clean",
3533
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
36-
"typecheck": "tsc --noEmit"
34+
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
35+
"test": "jest --coverage",
36+
"typecheck": "tsc -p tsconfig.json --noEmit"
3737
},
3838
"dependencies": {
3939
"@types/json-schema": "^7.0.3",
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
export interface ParserOptions {
2-
loc?: boolean;
32
comment?: boolean;
4-
range?: boolean;
5-
tokens?: boolean;
6-
sourceType?: 'script' | 'module';
7-
ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019;
83
ecmaFeatures?: {
94
globalReturn?: boolean;
105
jsx?: boolean;
116
};
7+
ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019;
8+
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
9+
errorOnUnknownASTType?: boolean;
10+
extraFileExtensions?: string[];
1211
// ts-estree specific
1312
filePath?: string;
13+
loc?: boolean;
14+
noWatch?: boolean;
1415
project?: string | string[];
15-
useJSXTextNode?: boolean;
16-
errorOnUnknownASTType?: boolean;
17-
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
16+
range?: boolean;
17+
sourceType?: 'script' | 'module';
18+
tokens?: boolean;
1819
tsconfigRootDir?: string;
19-
extraFileExtensions?: string[];
20+
useJSXTextNode?: boolean;
2021
warnOnUnsupportedTypeScriptVersion?: boolean;
2122
}

packages/experimental-utils/src/ts-eslint/RuleTester.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,32 @@ interface RuleTesterConfig {
5050
parser: string;
5151
parserOptions?: ParserOptions;
5252
}
53-
declare interface RuleTester {
53+
54+
// the cast on the extends is so that we don't want to have the built type defs to attempt to import eslint
55+
class RuleTester extends (ESLintRuleTester as {
56+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
57+
new (...args: unknown[]): any;
58+
}) {
59+
constructor(config?: RuleTesterConfig) {
60+
super(config);
61+
62+
// nobody will ever need watching in tests
63+
// so we can give everyone a perf win by disabling watching
64+
if (config && config.parserOptions && config.parserOptions.project) {
65+
config.parserOptions.noWatch =
66+
typeof config.parserOptions.noWatch === 'boolean' || true;
67+
}
68+
}
69+
5470
run<TMessageIds extends string, TOptions extends Readonly<unknown[]>>(
5571
name: string,
5672
rule: RuleModule<TMessageIds, TOptions>,
5773
tests: RunTests<TMessageIds, TOptions>,
58-
): void;
74+
): void {
75+
// this method is only defined here because we lazily type the eslint import with `any`
76+
super.run(name, rule, tests);
77+
}
5978
}
60-
const RuleTester = ESLintRuleTester as {
61-
new (config?: RuleTesterConfig): RuleTester;
62-
};
6379

6480
export {
6581
InvalidTestCase,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4+
"composite": true,
45
"outDir": "./dist",
56
"rootDir": "./src",
67
"resolveJsonModule": true
78
},
8-
"include": ["src", "typings"]
9+
"include": ["src", "typings"],
10+
"references": [{ "path": "../typescript-estree/tsconfig.build.json" }]
911
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"extends": "../../tsconfig.base.json",
2+
"extends": "./tsconfig.build.json",
33
"compilerOptions": {
4-
"outDir": "./dist",
5-
"resolveJsonModule": true
4+
"rootDir": ".",
5+
"noEmit": true
66
},
77
"include": ["src", "typings", "tests", "tools"]
88
}

packages/parser/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
"eslint"
3232
],
3333
"scripts": {
34-
"build": "tsc -p tsconfig.build.json",
35-
"clean": "rimraf dist/",
34+
"build": "tsc -b tsconfig.build.json",
35+
"clean": "tsc -b tsconfig.build.json --clean",
3636
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
37-
"prebuild": "npm run clean",
37+
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
3838
"test": "jest --coverage",
39-
"typecheck": "tsc --noEmit"
39+
"typecheck": "tsc -p tsconfig.json --noEmit"
4040
},
4141
"peerDependencies": {
4242
"eslint": "^5.0.0 || ^6.0.0"

packages/parser/src/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ export function parseForESLint(
115115
}
116116

117117
export { ParserServices, ParserOptions };
118+
export { clearCaches } from '@typescript-eslint/typescript-estree';

packages/parser/tests/lib/jsx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import filesWithKnownIssues from '@typescript-eslint/shared-fixtures/jsx-known-issues';
12
import fs from 'fs';
23
import glob from 'glob';
3-
import filesWithKnownIssues from '../../../shared-fixtures/jsx-known-issues';
44
import {
55
createScopeSnapshotTestBlock,
66
formatSnapshotName,

packages/parser/tsconfig.build.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4-
"declaration": true,
5-
"outDir": "./dist"
4+
"composite": true,
5+
"outDir": "./dist",
6+
"rootDir": "./src",
7+
"resolveJsonModule": true
68
},
7-
"include": ["src"]
9+
"include": ["src"],
10+
"references": [
11+
{ "path": "../experimental-utils/tsconfig.build.json" },
12+
{ "path": "../typescript-estree/tsconfig.build.json" }
13+
]
814
}

packages/parser/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"extends": "./tsconfig.build.json",
3+
"compilerOptions": {
4+
"rootDir": ".",
5+
"noEmit": true
6+
},
37
"include": ["src", "tests", "tools"],
48
"exclude": ["tests/fixtures"]
59
}

packages/typescript-estree/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@
3131
"syntax"
3232
],
3333
"scripts": {
34-
"ast-alignment-tests": "jest spec.ts",
35-
"build": "tsc -p tsconfig.build.json",
36-
"clean": "rimraf dist/",
34+
"build": "tsc -b tsconfig.build.json",
35+
"clean": "tsc -b tsconfig.build.json --clean",
3736
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
38-
"prebuild": "npm run clean",
37+
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
3938
"test": "jest --coverage",
40-
"typecheck": "tsc --noEmit",
41-
"unit-tests": "jest \"./tests/lib/.*\""
39+
"typecheck": "tsc -p tsconfig.json --noEmit"
4240
},
4341
"dependencies": {
42+
"chokidar": "^3.0.2",
4443
"glob": "^7.1.4",
4544
"is-glob": "^4.0.1",
4645
"lodash.unescape": "4.0.1",
@@ -56,10 +55,12 @@
5655
"@types/lodash.isplainobject": "^4.0.4",
5756
"@types/lodash.unescape": "^4.0.4",
5857
"@types/semver": "^6.0.1",
58+
"@types/tmp": "^0.1.0",
5959
"@typescript-eslint/shared-fixtures": "2.3.3",
6060
"babel-code-frame": "^6.26.0",
6161
"glob": "^7.1.4",
6262
"lodash.isplainobject": "4.0.6",
63+
"tmp": "^0.1.0",
6364
"typescript": "*"
6465
}
6566
}

0 commit comments

Comments
 (0)