Skip to content

fix: support long running "watch" lint sessions #973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
//

'comma-dangle': ['error', 'always-multiline'],
'constructor-super': 'off',
curly: ['error', 'all'],
'no-mixed-operators': 'error',
'no-console': 'error',
Expand Down Expand Up @@ -113,7 +114,8 @@ module.exports = {
ecmaFeatures: {
jsx: false,
},
project: './tsconfig.base.json',
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
tsconfigRootDir: __dirname,
},
overrides: [
{
Expand Down
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ jspm_packages/
# next.js build output
.next

.DS_Store
.idea
dist

# Editor-specific metadata folders
.vs

.DS_Store
.idea
dist
*.tsbuildinfo
.watchmanconfig
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"javascript.preferences.importModuleSpecifier": "auto",
"typescript.preferences.importModuleSpecifier": "auto",
"javascript.preferences.quoteStyle": "single",
"typescript.preferences.quoteStyle": "single"
"typescript.preferences.quoteStyle": "single",
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"pre-push": "yarn format-check",
"postinstall": "lerna bootstrap && yarn build && lerna link && npm run check-clean-workspace-after-install && opencollective-postinstall",
"check-clean-workspace-after-install": "git diff --quiet --exit-code",
"test": "lerna run test --parallel",
"test": "lerna run test --concurrency 1",
"typecheck": "lerna run typecheck"
},
"config": {
Expand Down Expand Up @@ -70,7 +70,6 @@
"lint-staged": "^9.2.5",
"opencollective-postinstall": "^2.0.2",
"prettier": "^1.18.2",
"rimraf": "^3.0.0",
"ts-jest": "^24.0.0",
"ts-node": "^8.3.0",
"tslint": "^5.19.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin-tslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
},
"license": "MIT",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/",
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"prebuild": "npm run clean",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"test": "jest --coverage",
"typecheck": "tsc --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "2.3.3",
Expand Down
11 changes: 9 additions & 2 deletions packages/eslint-plugin-tslint/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./dist"
"outDir": "./dist",
"rootDir": "./src",
"resolveJsonModule": true
},
"include": ["src"]
"include": ["src"],
"references": [
{ "path": "../experimental-utils/tsconfig.build.json" },
{ "path": "../parser/tsconfig.build.json" },
{ "path": "../typescript-estree/tsconfig.build.json" }
]
}
4 changes: 4 additions & 0 deletions packages/eslint-plugin-tslint/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"include": ["src", "tests"],
"exclude": ["tests/test-project", "tests/test-tslint-rules-directory"]
}
8 changes: 4 additions & 4 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
"license": "MIT",
"main": "dist/index.js",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"build": "tsc -b tsconfig.build.json",
"check:docs": "../../node_modules/.bin/ts-node --files ./tools/validate-docs/index.ts",
"check:configs": "../../node_modules/.bin/ts-node --files ./tools/validate-configs/index.ts",
"clean": "rimraf dist/",
"clean": "tsc -b tsconfig.build.json --clean",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"generate:configs": "../../node_modules/.bin/ts-node --files tools/generate-configs.ts",
"prebuild": "npm run clean",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"test": "jest --coverage",
"typecheck": "tsc --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "2.3.3",
Expand Down
7 changes: 7 additions & 0 deletions packages/eslint-plugin/tests/RuleTester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TSESLint, ESLintUtils } from '@typescript-eslint/experimental-utils';
import { clearCaches } from '@typescript-eslint/parser';
import * as path from 'path';

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

const { batchedSingleLineTests } = ESLintUtils;

// make sure that the parser doesn't hold onto file handles between tests
// on linux (i.e. our CI env), there can be very a limited number of watch handles available
afterAll(() => {
clearCaches();
});

export { RuleTester, getFixturesRootDir, batchedSingleLineTests };
11 changes: 6 additions & 5 deletions packages/eslint-plugin/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"declaration": false,
"declarationMap": false,
"outDir": "./dist",
"rootDir": "./src",
"resolveJsonModule": true
},
"include": [
"src",
"typings",
// include the parser's ambient typings because the parser exports them in its type defs
"../parser/typings"
"include": ["src", "typings"],
"references": [
{ "path": "../experimental-utils/tsconfig.build.json" },
{ "path": "../parser/tsconfig.build.json" },
{ "path": "../typescript-estree/tsconfig.build.json" }
]
}
4 changes: 4 additions & 0 deletions packages/eslint-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"include": ["src", "typings", "tests", "tools"]
}
10 changes: 5 additions & 5 deletions packages/experimental-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "jest --coverage",
"prebuild": "npm run clean",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/",
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"typecheck": "tsc --noEmit"
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"test": "jest --coverage",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"@types/json-schema": "^7.0.3",
Expand Down
19 changes: 10 additions & 9 deletions packages/experimental-utils/src/ts-eslint/ParserOptions.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
export interface ParserOptions {
loc?: boolean;
comment?: boolean;
range?: boolean;
tokens?: boolean;
sourceType?: 'script' | 'module';
ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019;
ecmaFeatures?: {
globalReturn?: boolean;
jsx?: boolean;
};
ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 2015 | 2016 | 2017 | 2018 | 2019;
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
errorOnUnknownASTType?: boolean;
extraFileExtensions?: string[];
// ts-estree specific
filePath?: string;
loc?: boolean;
noWatch?: boolean;
project?: string | string[];
useJSXTextNode?: boolean;
errorOnUnknownASTType?: boolean;
errorOnTypeScriptSyntacticAndSemanticIssues?: boolean;
range?: boolean;
sourceType?: 'script' | 'module';
tokens?: boolean;
tsconfigRootDir?: string;
extraFileExtensions?: string[];
useJSXTextNode?: boolean;
warnOnUnsupportedTypeScriptVersion?: boolean;
}
26 changes: 21 additions & 5 deletions packages/experimental-utils/src/ts-eslint/RuleTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,32 @@ interface RuleTesterConfig {
parser: string;
parserOptions?: ParserOptions;
}
declare interface RuleTester {

// the cast on the extends is so that we don't want to have the built type defs to attempt to import eslint
class RuleTester extends (ESLintRuleTester as {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new (...args: unknown[]): any;
}) {
constructor(config?: RuleTesterConfig) {
super(config);

// nobody will ever need watching in tests
// so we can give everyone a perf win by disabling watching
if (config && config.parserOptions && config.parserOptions.project) {
config.parserOptions.noWatch =
typeof config.parserOptions.noWatch === 'boolean' || true;
}
}

run<TMessageIds extends string, TOptions extends Readonly<unknown[]>>(
name: string,
rule: RuleModule<TMessageIds, TOptions>,
tests: RunTests<TMessageIds, TOptions>,
): void;
): void {
// this method is only defined here because we lazily type the eslint import with `any`
super.run(name, rule, tests);
}
}
const RuleTester = ESLintRuleTester as {
new (config?: RuleTesterConfig): RuleTester;
};

export {
InvalidTestCase,
Expand Down
4 changes: 3 additions & 1 deletion packages/experimental-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./dist",
"rootDir": "./src",
"resolveJsonModule": true
},
"include": ["src", "typings"]
"include": ["src", "typings"],
"references": [{ "path": "../typescript-estree/tsconfig.build.json" }]
}
6 changes: 3 additions & 3 deletions packages/experimental-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "./dist",
"resolveJsonModule": true
"rootDir": ".",
"noEmit": true
},
"include": ["src", "typings", "tests", "tools"]
}
8 changes: 4 additions & 4 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
"eslint"
],
"scripts": {
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/",
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"prebuild": "npm run clean",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"test": "jest --coverage",
"typecheck": "tsc --noEmit"
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"peerDependencies": {
"eslint": "^5.0.0 || ^6.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ export function parseForESLint(
}

export { ParserServices, ParserOptions };
export { clearCaches } from '@typescript-eslint/typescript-estree';
2 changes: 1 addition & 1 deletion packages/parser/tests/lib/jsx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import filesWithKnownIssues from '@typescript-eslint/shared-fixtures/jsx-known-issues';
import fs from 'fs';
import glob from 'glob';
import filesWithKnownIssues from '../../../shared-fixtures/jsx-known-issues';
import {
createScopeSnapshotTestBlock,
formatSnapshotName,
Expand Down
12 changes: 9 additions & 3 deletions packages/parser/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"outDir": "./dist"
"composite": true,
"outDir": "./dist",
"rootDir": "./src",
"resolveJsonModule": true
},
"include": ["src"]
"include": ["src"],
"references": [
{ "path": "../experimental-utils/tsconfig.build.json" },
{ "path": "../typescript-estree/tsconfig.build.json" }
]
}
4 changes: 4 additions & 0 deletions packages/parser/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"include": ["src", "tests", "tools"],
"exclude": ["tests/fixtures"]
}
13 changes: 7 additions & 6 deletions packages/typescript-estree/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@
"syntax"
],
"scripts": {
"ast-alignment-tests": "jest spec.ts",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist/",
"build": "tsc -b tsconfig.build.json",
"clean": "tsc -b tsconfig.build.json --clean",
"format": "prettier --write \"./**/*.{ts,js,json,md}\" --ignore-path ../../.prettierignore",
"prebuild": "npm run clean",
"lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'",
"test": "jest --coverage",
"typecheck": "tsc --noEmit",
"unit-tests": "jest \"./tests/lib/.*\""
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"dependencies": {
"chokidar": "^3.0.2",
"glob": "^7.1.4",
"is-glob": "^4.0.1",
"lodash.unescape": "4.0.1",
Expand All @@ -56,10 +55,12 @@
"@types/lodash.isplainobject": "^4.0.4",
"@types/lodash.unescape": "^4.0.4",
"@types/semver": "^6.0.1",
"@types/tmp": "^0.1.0",
"@typescript-eslint/shared-fixtures": "2.3.3",
"babel-code-frame": "^6.26.0",
"glob": "^7.1.4",
"lodash.isplainobject": "4.0.6",
"tmp": "^0.1.0",
"typescript": "*"
}
}
Loading