Skip to content
Permalink
Browse files

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

  • Loading branch information...
bradzacher committed Oct 12, 2019
1 parent fec73b0 commit 854620e9232d4d54e6fc89876b4c9ed38f5570f9
Showing with 506 additions and 119 deletions.
  1. +3 −1 .eslintrc.js
  2. +6 −3 .gitignore
  3. +2 −1 .vscode/settings.json
  4. +1 −2 package.json
  5. +4 −4 packages/eslint-plugin-tslint/package.json
  6. +9 −2 packages/eslint-plugin-tslint/tsconfig.build.json
  7. +4 −0 packages/eslint-plugin-tslint/tsconfig.json
  8. +4 −4 packages/eslint-plugin/package.json
  9. +7 −0 packages/eslint-plugin/tests/RuleTester.ts
  10. +6 −5 packages/eslint-plugin/tsconfig.build.json
  11. +4 −0 packages/eslint-plugin/tsconfig.json
  12. +5 −5 packages/experimental-utils/package.json
  13. +10 −9 packages/experimental-utils/src/ts-eslint/ParserOptions.ts
  14. +21 −5 packages/experimental-utils/src/ts-eslint/RuleTester.ts
  15. +3 −1 packages/experimental-utils/tsconfig.build.json
  16. +3 −3 packages/experimental-utils/tsconfig.json
  17. +4 −4 packages/parser/package.json
  18. +1 −0 packages/parser/src/parser.ts
  19. +1 −1 packages/parser/tests/lib/jsx.ts
  20. +9 −3 packages/parser/tsconfig.build.json
  21. +4 −0 packages/parser/tsconfig.json
  22. +7 −6 packages/typescript-estree/package.json
  23. +23 −21 packages/typescript-estree/src/parser-options.ts
  24. +26 −16 packages/typescript-estree/src/parser.ts
  25. +127 −14 packages/typescript-estree/src/tsconfig-parser.ts
  26. +1 −1 packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts
  27. +1 −1 packages/typescript-estree/tests/lib/jsx.ts
  28. +3 −2 packages/typescript-estree/tests/lib/parse.ts
  29. +136 −0 packages/typescript-estree/tests/lib/persistentParse.ts
  30. +3 −1 packages/typescript-estree/tsconfig.build.json
  31. +3 −2 packages/typescript-estree/tsconfig.json
  32. +4 −0 tsconfig.eslint.json
  33. +61 −2 yarn.lock
@@ -35,6 +35,7 @@ module.exports = {
//

'comma-dangle': ['error', 'always-multiline'],
'constructor-super': 'off',
curly: ['error', 'all'],
'no-mixed-operators': 'error',
'no-console': 'error',
@@ -113,7 +114,8 @@ module.exports = {
ecmaFeatures: {
jsx: false,
},
project: './tsconfig.base.json',
project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'],
tsconfigRootDir: __dirname,
},
overrides: [
{
@@ -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
@@ -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"
}
@@ -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": {
@@ -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",
@@ -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",
@@ -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" }
]
}
@@ -1,5 +1,9 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"include": ["src", "tests"],
"exclude": ["tests/test-project", "tests/test-tslint-rules-directory"]
}
@@ -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",
@@ -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';
@@ -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 };
@@ -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" }
]
}
@@ -1,4 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"include": ["src", "typings", "tests", "tools"]
}
@@ -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",
@@ -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;
}
@@ -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,
@@ -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" }]
}
@@ -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"]
}
@@ -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"
@@ -115,3 +115,4 @@ export function parseForESLint(
}

export { ParserServices, ParserOptions };
export { clearCaches } from '@typescript-eslint/typescript-estree';
@@ -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,
@@ -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" }
]
}
@@ -1,5 +1,9 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"rootDir": ".",
"noEmit": true
},
"include": ["src", "tests", "tools"],
"exclude": ["tests/fixtures"]
}
@@ -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",
@@ -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": "*"
}
}

0 comments on commit 854620e

Please sign in to comment.
You can’t perform that action at this time.