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

Skip to content

Commit d0b75a5

Browse files
committed
Merge branch 'master' into tsx-test
# Conflicts: # .gitignore
2 parents dae2acd + 854620e commit d0b75a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+603
-135
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +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
6668
.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
}

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@
1313

1414
<br>
1515

16+
## Table of Contents
17+
18+
- [Getting Started](#getting-started)
19+
- [What are ESLint and TypeScript, and how do they compare?](#what-are-eslint-and-typescript-and-how-do-they-compare)
20+
- [Why does this project exist?](#why-does-this-project-exist)
21+
- [What about TSLint?](#what-about-tslint)
22+
- [How does typescript-eslint work and why do you have multiple packages?](#how-does-typescript-eslint-work-and-why-do-you-have-multiple-packages)
23+
- [Can I use all of the existing ESLint plugins and rules without any changes?](#can-i-use-all-of-the-existing-eslint-plugins-and-rules-without-any-changes)
24+
- [Can we write rules which leverage type information?](#can-we-write-rules-which-leverage-type-information)
25+
- [What about Babel and babel-eslint?](#what-about-babel-and-babel-eslint)
26+
- [How can I help?](#how-can-i-help)
27+
- [How do I configure my project to use typescript-eslint?](#how-do-i-configure-my-project-to-use-typescript-eslint)
28+
- [Package Versions](#package-versions)
29+
- [Supported TypeScript Version](#supported-typescript-version)
30+
- [Supported ESLint version](#supported-eslint-version)
31+
- [License](#license)
32+
- [Contributors](#contributors)
33+
- [Contributing Guide](#contributing-guide)
34+
1635
## Getting Started
1736

1837
The following sections will give you an overview of what this project is, why it exists and how it works at a high level.
@@ -228,6 +247,10 @@ If you use a non-supported version of TypeScript, the parser will log a warning
228247

229248
<br>
230249

250+
## Supported ESLint version
251+
252+
See the value of `eslint` declared in `@typescript-eslint/eslint-plugin`'s [package.json](./packages/eslint-plugin/package.json).
253+
231254
## License
232255

233256
TypeScript ESLint inherits from the the original TypeScript ESLint Parser license, as the majority of the work began there. It is licensed under a permissive BSD 2-clause license.

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/docs/rules/promise-function-async.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Ensures that each function is only capable of:
66
- returning a rejected promise, or
77
- throwing an Error object.
88

9-
In contrast, non-`async` `Promise`-returning functions are technically capable of either.
9+
In contrast, non-`async` `Promise` - returning functions are technically capable of either.
1010
Code that handles the results of those functions will often need to handle both cases, which can get complex.
1111
This rule's practice removes a requirement for creating code to handle both cases.
1212

@@ -17,18 +17,18 @@ Examples of **incorrect** code for this rule
1717
```ts
1818
const arrowFunctionReturnsPromise = () => Promise.resolve('value');
1919

20-
function functionDeturnsPromise() {
21-
return Math.random() > 0.5 ? Promise.resolve('value') : false;
20+
function functionReturnsPromise() {
21+
return Promise.resolve('value');
2222
}
2323
```
2424

2525
Examples of **correct** code for this rule
2626

2727
```ts
28-
const arrowFunctionReturnsPromise = async () => 'value';
28+
const arrowFunctionReturnsPromise = async () => Promise.resolve('value');
2929

30-
async function functionDeturnsPromise() {
31-
return Math.random() > 0.5 ? 'value' : false;
30+
async function functionReturnsPromise() {
31+
return Promise.resolve('value');
3232
}
3333
```
3434

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/src/rules/indent-new-do-not-use/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ const KNOWN_NODES = new Set([
9292
AST_NODE_TYPES.WithStatement,
9393
AST_NODE_TYPES.YieldExpression,
9494
AST_NODE_TYPES.JSXIdentifier,
95-
AST_NODE_TYPES.JSXNamespacedName,
9695
AST_NODE_TYPES.JSXMemberExpression,
9796
AST_NODE_TYPES.JSXEmptyExpression,
9897
AST_NODE_TYPES.JSXExpressionContainer,
@@ -164,7 +163,7 @@ const KNOWN_NODES = new Set([
164163
'TSPlusToken',
165164
AST_NODE_TYPES.TSPropertySignature,
166165
AST_NODE_TYPES.TSQualifiedName,
167-
AST_NODE_TYPES.TSQuestionToken,
166+
'TSQuestionToken',
168167
AST_NODE_TYPES.TSRestType,
169168
AST_NODE_TYPES.TSThisType,
170169
AST_NODE_TYPES.TSTupleType,

packages/eslint-plugin/src/rules/indent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const KNOWN_NODES = new Set([
6969
'TSPlusToken',
7070
AST_NODE_TYPES.TSPropertySignature,
7171
AST_NODE_TYPES.TSQualifiedName,
72-
AST_NODE_TYPES.TSQuestionToken,
72+
'TSQuestionToken',
7373
AST_NODE_TYPES.TSRestType,
7474
AST_NODE_TYPES.TSThisType,
7575
AST_NODE_TYPES.TSTupleType,

packages/eslint-plugin/src/rules/promise-function-async.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ export default util.createRule<Options, MessageIds>({
9898
const returnType = checker.getReturnTypeOfSignature(signatures[0]);
9999

100100
if (
101-
!util.containsTypeByName(returnType, allowAny!, allAllowedPromiseNames)
101+
!util.containsAllTypesByName(
102+
returnType,
103+
allowAny!,
104+
allAllowedPromiseNames,
105+
)
102106
) {
103107
return;
104108
}

packages/eslint-plugin/src/util/types.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import ts from 'typescript';
88
/**
99
* @param type Type being checked by name.
1010
* @param allowedNames Symbol names checking on the type.
11-
* @returns Whether the type is, extends, or contains any of the allowed names.
11+
* @returns Whether the type is, extends, or contains all of the allowed names.
1212
*/
13-
export function containsTypeByName(
13+
export function containsAllTypesByName(
1414
type: ts.Type,
1515
allowAny: boolean,
1616
allowedNames: Set<string>,
@@ -31,13 +31,16 @@ export function containsTypeByName(
3131
}
3232

3333
if (isUnionOrIntersectionType(type)) {
34-
return type.types.some(t => containsTypeByName(t, allowAny, allowedNames));
34+
return type.types.every(t =>
35+
containsAllTypesByName(t, allowAny, allowedNames),
36+
);
3537
}
3638

3739
const bases = type.getBaseTypes();
3840
return (
3941
typeof bases !== 'undefined' &&
40-
bases.some(t => containsTypeByName(t, allowAny, allowedNames))
42+
bases.length > 0 &&
43+
bases.every(t => containsAllTypesByName(t, allowAny, allowedNames))
4144
);
4245
}
4346

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';
@@ -72,4 +73,10 @@ function getFixturesRootDir(): string {
7273

7374
const { batchedSingleLineTests } = ESLintUtils;
7475

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

packages/eslint-plugin/tests/eslint-rules/no-restricted-globals.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export default class Test {
2424
`,
2525
options: ['status'],
2626
},
27+
{
28+
code: `
29+
type Handler = (event: string) => any
30+
`,
31+
options: ['event'],
32+
},
2733
],
2834
invalid: [],
2935
});

packages/eslint-plugin/tests/rules/promise-function-async.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ function returnsUnknown(): unknown {
106106
},
107107
],
108108
},
109+
{
110+
code: `
111+
interface ReadableStream {}
112+
interface Options {
113+
stream: ReadableStream;
114+
}
115+
116+
type Return = ReadableStream | Promise<void>;
117+
const foo = (options: Options): Return => {
118+
return options.stream ? asStream(options) : asPromise(options);
119+
}
120+
`,
121+
},
122+
{
123+
code: `
124+
function foo(): Promise<string> | boolean {
125+
return Math.random() > 0.5 ? Promise.resolve('value') : false;
126+
}
127+
`,
128+
},
109129
],
110130
invalid: [
111131
{
@@ -379,5 +399,24 @@ const returnAllowedType = () => new PromiseType();
379399
},
380400
],
381401
},
402+
{
403+
code: `
404+
interface SPromise<T> extends Promise<T> {}
405+
function foo(): Promise<string> | SPromise<boolean> {
406+
return Math.random() > 0.5 ? Promise.resolve('value') : Promise.resolve(false);
407+
}
408+
`,
409+
options: [
410+
{
411+
allowedPromiseNames: ['SPromise'],
412+
},
413+
],
414+
errors: [
415+
{
416+
line: 3,
417+
messageId,
418+
},
419+
],
420+
},
382421
],
383422
});

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",

0 commit comments

Comments
 (0)