Skip to content

Commit 2be354b

Browse files
authored
feat: support TS4.1 features (typescript-eslint#2748)
Fixes typescript-eslint#2583 - Adds AST for Key Remapping in Mapped Types and Template Literal Types - Adds visitor keys for the above - Adds scope manager support for the above (just tests were required as it all is pretty simple) - Regenerates the scope-manager lib types
1 parent 83385ac commit 2be354b

Some content is hidden

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

51 files changed

+4503
-119
lines changed

.prettierignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ CONTRIBUTORS.md
1616
# Ignore CHANGELOG.md files to avoid issues with automated release job
1717
CHANGELOG.md
1818

19-
# TODO - remove this once prettier supports labelled tuples
20-
packages/scope-manager/tests/fixtures/type-declaration/tuple-labelled.ts
21-
packages/scope-manager/tests/fixtures/type-declaration/tuple-labelled-rest.ts
19+
# TODO - remove this once prettier supports TS4.1
20+
packages/scope-manager/tests/fixtures/type-declaration/literal-type1.ts
21+
packages/scope-manager/tests/fixtures/type-declaration/literal-type2.ts
22+
packages/scope-manager/tests/fixtures/type-declaration/literal-type3.ts
23+
packages/scope-manager/tests/fixtures/type-declaration/mapped-named.ts

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"all-contributors-cli": "^6.17.2",
8787
"cspell": "^4.1.0",
8888
"cz-conventional-changelog": "^3.3.0",
89-
"downlevel-dts": "^0.6.0",
89+
"downlevel-dts": "^0.7.0",
9090
"eslint": "^7.7.0",
9191
"eslint-plugin-eslint-comments": "^3.2.0",
9292
"eslint-plugin-eslint-plugin": "^2.3.0",
@@ -106,9 +106,9 @@
106106
"ts-jest": "^26.3.0",
107107
"ts-node": "^9.0.0",
108108
"tslint": "^6.1.3",
109-
"typescript": ">=3.3.1 <4.1.0"
109+
"typescript": ">=3.3.1 <4.2.0 || 4.1.1-rc"
110110
},
111111
"resolutions": {
112-
"typescript": "4.0.2"
112+
"typescript": "4.1.1-rc"
113113
}
114114
}

packages/eslint-plugin/tests/rules/no-unused-vars.test.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import rule from '../../src/rules/no-unused-vars';
2-
import { RuleTester } from '../RuleTester';
2+
import { noFormat, RuleTester } from '../RuleTester';
33

44
const ruleTester = new RuleTester({
55
parserOptions: {
@@ -387,6 +387,17 @@ export const map: { [name in Foo]: Bar } = {
387387
a: 1,
388388
b: 2,
389389
c: 3,
390+
};
391+
`,
392+
// 4.1 remapped mapped type
393+
noFormat`
394+
type Foo = 'a' | 'b' | 'c';
395+
type Bar = number;
396+
397+
export const map: { [name in Foo as string]: Bar } = {
398+
a: 1,
399+
b: 2,
400+
c: 3,
390401
};
391402
`,
392403
`
@@ -900,6 +911,22 @@ declare function A(A: string): string;
900911
`,
901912
filename: 'foo.d.ts',
902913
},
914+
// 4.1 template literal types
915+
noFormat`
916+
type Color = 'red' | 'blue';
917+
type Quantity = 'one' | 'two';
918+
export type SeussFish = \`\${Quantity | Color} fish\`;
919+
`,
920+
noFormat`
921+
type VerticalAlignment = "top" | "middle" | "bottom";
922+
type HorizontalAlignment = "left" | "center" | "right";
923+
924+
export declare function setAlignment(value: \`\${VerticalAlignment}-\${HorizontalAlignment}\`): void;
925+
`,
926+
noFormat`
927+
type EnthusiasticGreeting<T extends string> = \`\${Uppercase<T>} - \${Lowercase<T>} - \${Capitalize<T>} - \${Uncapitalize<T>}\`;
928+
export type HELLO = EnthusiasticGreeting<"heLLo">;
929+
`,
903930
],
904931

905932
invalid: [

packages/scope-manager/src/lib/dom.iterable.ts

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ export const dom_iterable = {
125125
isValueVariable: false,
126126
name: 'Headers',
127127
},
128+
IDBDatabase: {
129+
eslintImplicitGlobalSetting: 'readonly',
130+
isTypeVariable: true,
131+
isValueVariable: false,
132+
name: 'IDBDatabase',
133+
},
128134
IDBObjectStore: {
129135
eslintImplicitGlobalSetting: 'readonly',
130136
isTypeVariable: true,

packages/scope-manager/src/lib/dom.ts

+39-57
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ export const dom = {
299299
isValueVariable: false,
300300
name: 'CredentialCreationOptions',
301301
},
302+
CredentialPropertiesOutput: {
303+
eslintImplicitGlobalSetting: 'readonly',
304+
isTypeVariable: true,
305+
isValueVariable: false,
306+
name: 'CredentialPropertiesOutput',
307+
},
302308
CredentialRequestOptions: {
303309
eslintImplicitGlobalSetting: 'readonly',
304310
isTypeVariable: true,
@@ -1745,12 +1751,6 @@ export const dom = {
17451751
isValueVariable: false,
17461752
name: 'WorkletOptions',
17471753
},
1748-
txAuthGenericArg: {
1749-
eslintImplicitGlobalSetting: 'readonly',
1750-
isTypeVariable: true,
1751-
isValueVariable: false,
1752-
name: 'txAuthGenericArg',
1753-
},
17541754
EventListener: {
17551755
eslintImplicitGlobalSetting: 'readonly',
17561756
isTypeVariable: true,
@@ -2369,12 +2369,6 @@ export const dom = {
23692369
isValueVariable: true,
23702370
name: 'ConvolverNode',
23712371
},
2372-
Coordinates: {
2373-
eslintImplicitGlobalSetting: 'readonly',
2374-
isTypeVariable: true,
2375-
isValueVariable: false,
2376-
name: 'Coordinates',
2377-
},
23782372
CountQueuingStrategy: {
23792373
eslintImplicitGlobalSetting: 'readonly',
23802374
isTypeVariable: true,
@@ -2906,9 +2900,27 @@ export const dom = {
29062900
Geolocation: {
29072901
eslintImplicitGlobalSetting: 'readonly',
29082902
isTypeVariable: true,
2909-
isValueVariable: false,
2903+
isValueVariable: true,
29102904
name: 'Geolocation',
29112905
},
2906+
GeolocationCoordinates: {
2907+
eslintImplicitGlobalSetting: 'readonly',
2908+
isTypeVariable: true,
2909+
isValueVariable: true,
2910+
name: 'GeolocationCoordinates',
2911+
},
2912+
GeolocationPosition: {
2913+
eslintImplicitGlobalSetting: 'readonly',
2914+
isTypeVariable: true,
2915+
isValueVariable: true,
2916+
name: 'GeolocationPosition',
2917+
},
2918+
GeolocationPositionError: {
2919+
eslintImplicitGlobalSetting: 'readonly',
2920+
isTypeVariable: true,
2921+
isValueVariable: true,
2922+
name: 'GeolocationPositionError',
2923+
},
29122924
GlobalEventHandlersEventMap: {
29132925
eslintImplicitGlobalSetting: 'readonly',
29142926
isTypeVariable: true,
@@ -3473,12 +3485,6 @@ export const dom = {
34733485
isValueVariable: true,
34743486
name: 'History',
34753487
},
3476-
HkdfCtrParams: {
3477-
eslintImplicitGlobalSetting: 'readonly',
3478-
isTypeVariable: true,
3479-
isValueVariable: false,
3480-
name: 'HkdfCtrParams',
3481-
},
34823488
IDBArrayKey: {
34833489
eslintImplicitGlobalSetting: 'readonly',
34843490
isTypeVariable: true,
@@ -4415,18 +4421,6 @@ export const dom = {
44154421
isValueVariable: true,
44164422
name: 'PopStateEvent',
44174423
},
4418-
Position: {
4419-
eslintImplicitGlobalSetting: 'readonly',
4420-
isTypeVariable: true,
4421-
isValueVariable: false,
4422-
name: 'Position',
4423-
},
4424-
PositionError: {
4425-
eslintImplicitGlobalSetting: 'readonly',
4426-
isTypeVariable: true,
4427-
isValueVariable: false,
4428-
name: 'PositionError',
4429-
},
44304424
ProcessingInstruction: {
44314425
eslintImplicitGlobalSetting: 'readonly',
44324426
isTypeVariable: true,
@@ -4724,7 +4718,7 @@ export const dom = {
47244718
ReadableByteStreamController: {
47254719
eslintImplicitGlobalSetting: 'readonly',
47264720
isTypeVariable: true,
4727-
isValueVariable: false,
4721+
isValueVariable: true,
47284722
name: 'ReadableByteStreamController',
47294723
},
47304724
ReadableStream: {
@@ -4736,25 +4730,25 @@ export const dom = {
47364730
ReadableStreamBYOBReader: {
47374731
eslintImplicitGlobalSetting: 'readonly',
47384732
isTypeVariable: true,
4739-
isValueVariable: false,
4733+
isValueVariable: true,
47404734
name: 'ReadableStreamBYOBReader',
47414735
},
47424736
ReadableStreamBYOBRequest: {
47434737
eslintImplicitGlobalSetting: 'readonly',
47444738
isTypeVariable: true,
4745-
isValueVariable: false,
4739+
isValueVariable: true,
47464740
name: 'ReadableStreamBYOBRequest',
47474741
},
47484742
ReadableStreamDefaultController: {
47494743
eslintImplicitGlobalSetting: 'readonly',
47504744
isTypeVariable: true,
4751-
isValueVariable: false,
4745+
isValueVariable: true,
47524746
name: 'ReadableStreamDefaultController',
47534747
},
47544748
ReadableStreamDefaultReader: {
47554749
eslintImplicitGlobalSetting: 'readonly',
47564750
isTypeVariable: true,
4757-
isValueVariable: false,
4751+
isValueVariable: true,
47584752
name: 'ReadableStreamDefaultReader',
47594753
},
47604754
ReadableStreamReader: {
@@ -5954,7 +5948,7 @@ export const dom = {
59545948
TransformStreamDefaultController: {
59555949
eslintImplicitGlobalSetting: 'readonly',
59565950
isTypeVariable: true,
5957-
isValueVariable: false,
5951+
isValueVariable: true,
59585952
name: 'TransformStreamDefaultController',
59595953
},
59605954
TransitionEvent: {
@@ -6374,13 +6368,13 @@ export const dom = {
63746368
WritableStreamDefaultController: {
63756369
eslintImplicitGlobalSetting: 'readonly',
63766370
isTypeVariable: true,
6377-
isValueVariable: false,
6371+
isValueVariable: true,
63786372
name: 'WritableStreamDefaultController',
63796373
},
63806374
WritableStreamDefaultWriter: {
63816375
eslintImplicitGlobalSetting: 'readonly',
63826376
isTypeVariable: true,
6383-
isValueVariable: false,
6377+
isValueVariable: true,
63846378
name: 'WritableStreamDefaultWriter',
63856379
},
63866380
XMLDocument: {
@@ -6851,24 +6845,6 @@ export const dom = {
68516845
isValueVariable: false,
68526846
name: 'COSEAlgorithmIdentifier',
68536847
},
6854-
AuthenticatorSelectionList: {
6855-
eslintImplicitGlobalSetting: 'readonly',
6856-
isTypeVariable: true,
6857-
isValueVariable: false,
6858-
name: 'AuthenticatorSelectionList',
6859-
},
6860-
AAGUID: {
6861-
eslintImplicitGlobalSetting: 'readonly',
6862-
isTypeVariable: true,
6863-
isValueVariable: false,
6864-
name: 'AAGUID',
6865-
},
6866-
AuthenticationExtensionsSupported: {
6867-
eslintImplicitGlobalSetting: 'readonly',
6868-
isTypeVariable: true,
6869-
isValueVariable: false,
6870-
name: 'AuthenticationExtensionsSupported',
6871-
},
68726848
UvmEntry: {
68736849
eslintImplicitGlobalSetting: 'readonly',
68746850
isTypeVariable: true,
@@ -7769,6 +7745,12 @@ export const dom = {
77697745
isValueVariable: false,
77707746
name: 'RequestRedirect',
77717747
},
7748+
ResidentKeyRequirement: {
7749+
eslintImplicitGlobalSetting: 'readonly',
7750+
isTypeVariable: true,
7751+
isValueVariable: false,
7752+
name: 'ResidentKeyRequirement',
7753+
},
77727754
ResizeQuality: {
77737755
eslintImplicitGlobalSetting: 'readonly',
77747756
isTypeVariable: true,

packages/scope-manager/src/lib/es2015.iterable.ts

-6
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ export const es2015_iterable = {
145145
isValueVariable: false,
146146
name: 'PromiseConstructor',
147147
},
148-
Reflect: {
149-
eslintImplicitGlobalSetting: 'readonly',
150-
isTypeVariable: true,
151-
isValueVariable: true,
152-
name: 'Reflect',
153-
},
154148
String: {
155149
eslintImplicitGlobalSetting: 'readonly',
156150
isTypeVariable: true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// THIS CODE WAS AUTOMATICALLY GENERATED
2+
// DO NOT EDIT THIS CODE BY HAND
3+
// YOU CAN REGENERATE IT USING yarn generate:lib
4+
5+
import { ImplicitLibVariableOptions } from '../variable';
6+
7+
export const es2020_sharedmemory = {
8+
Atomics: {
9+
eslintImplicitGlobalSetting: 'readonly',
10+
isTypeVariable: true,
11+
isValueVariable: false,
12+
name: 'Atomics',
13+
},
14+
} as Record<string, ImplicitLibVariableOptions>;

packages/scope-manager/src/lib/es2020.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ImplicitLibVariableOptions } from '../variable';
66
import { es2019 } from './es2019';
77
import { es2020_bigint } from './es2020.bigint';
88
import { es2020_promise } from './es2020.promise';
9+
import { es2020_sharedmemory } from './es2020.sharedmemory';
910
import { es2020_string } from './es2020.string';
1011
import { es2020_symbol_wellknown } from './es2020.symbol.wellknown';
1112
import { es2020_intl } from './es2020.intl';
@@ -14,6 +15,7 @@ export const es2020 = {
1415
...es2019,
1516
...es2020_bigint,
1617
...es2020_promise,
18+
...es2020_sharedmemory,
1719
...es2020_string,
1820
...es2020_symbol_wellknown,
1921
...es2020_intl,

packages/scope-manager/src/lib/es5.ts

+24
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,30 @@ export const es5 = {
419419
isValueVariable: false,
420420
name: 'InstanceType',
421421
},
422+
Uppercase: {
423+
eslintImplicitGlobalSetting: 'readonly',
424+
isTypeVariable: true,
425+
isValueVariable: false,
426+
name: 'Uppercase',
427+
},
428+
Lowercase: {
429+
eslintImplicitGlobalSetting: 'readonly',
430+
isTypeVariable: true,
431+
isValueVariable: false,
432+
name: 'Lowercase',
433+
},
434+
Capitalize: {
435+
eslintImplicitGlobalSetting: 'readonly',
436+
isTypeVariable: true,
437+
isValueVariable: false,
438+
name: 'Capitalize',
439+
},
440+
Uncapitalize: {
441+
eslintImplicitGlobalSetting: 'readonly',
442+
isTypeVariable: true,
443+
isValueVariable: false,
444+
name: 'Uncapitalize',
445+
},
422446
ThisType: {
423447
eslintImplicitGlobalSetting: 'readonly',
424448
isTypeVariable: true,

packages/scope-manager/src/lib/esnext.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import { es2020 } from './es2020';
77
import { esnext_intl } from './esnext.intl';
88
import { esnext_string } from './esnext.string';
99
import { esnext_promise } from './esnext.promise';
10+
import { esnext_weakref } from './esnext.weakref';
1011

1112
export const esnext = {
1213
...es2020,
1314
...esnext_intl,
1415
...esnext_string,
1516
...esnext_promise,
17+
...esnext_weakref,
1618
} as Record<string, ImplicitLibVariableOptions>;

0 commit comments

Comments
 (0)