From 043462ef4d8f3aa16c10efb84fea25a193deefac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Tue, 24 Aug 2021 19:40:40 +0200 Subject: [PATCH 1/9] chore: update NX (#3785) --- package.json | 6 ++--- yarn.lock | 64 ++++++++++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 0fe544880b6b..3939cc2d63a1 100644 --- a/package.json +++ b/package.json @@ -77,10 +77,10 @@ "@commitlint/cli": "^13.1.0", "@commitlint/config-conventional": "^13.1.0", "@commitlint/config-lerna-scopes": "^13.1.0", - "@nrwl/cli": "12.7.1", + "@nrwl/cli": "12.7.2", "@nrwl/nx-cloud": "12.3.10", - "@nrwl/tao": "12.7.1", - "@nrwl/workspace": "12.7.1", + "@nrwl/tao": "12.7.2", + "@nrwl/workspace": "12.7.2", "@types/babel__code-frame": "^7.0.2", "@types/debug": "^4.1.5", "@types/eslint-visitor-keys": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index fcc05284ae5a..95a2b43532c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1761,37 +1761,37 @@ "@nodelib/fs.scandir" "2.1.3" fastq "^1.6.0" -"@nrwl/cli@12.7.1": - version "12.7.1" - resolved "https://registry.yarnpkg.com/@nrwl/cli/-/cli-12.7.1.tgz#cd781731c0396975ce44edb6c80b8fccbba4b23e" - integrity sha512-Rjv9Pwv2Bdgztkr0GnKuE/W7DmSTQI/bvdtKOqcOJIsL4i5xJCZDxVDbhmfPoa4NXPIYHeW3EqfFAP4PH1rCKg== +"@nrwl/cli@12.7.2": + version "12.7.2" + resolved "https://registry.yarnpkg.com/@nrwl/cli/-/cli-12.7.2.tgz#7a7f0dae1959431763e3c37b54fa368141e549ba" + integrity sha512-MYzHFk/vfgFi6LVbKlBymBIA5fHm72ES9+FvNdYacwiyWlInuBVLAb6McX2zfY6gioxyUOUBPXuBvGxbGtb6qQ== dependencies: - "@nrwl/tao" "12.7.1" + "@nrwl/tao" "12.7.2" chalk "4.1.0" v8-compile-cache "2.3.0" yargs "15.4.1" yargs-parser "20.0.0" -"@nrwl/devkit@12.7.1": - version "12.7.1" - resolved "https://registry.yarnpkg.com/@nrwl/devkit/-/devkit-12.7.1.tgz#aea0d8db1663fed44b5189452beae87bf432c60f" - integrity sha512-g88SWsXbiZDvL+4PWCBFlhzsg0niEJCxGDJ1EV+dLexAM3iD1aBn3EK2ygaF1sgabBNlJnUgbpU14/N5SexZuA== +"@nrwl/devkit@12.7.2": + version "12.7.2" + resolved "https://registry.yarnpkg.com/@nrwl/devkit/-/devkit-12.7.2.tgz#3ea39590dc29d6aa6cf970bc195c99641ae0b0ec" + integrity sha512-Uk0DOkQ35sAMSMQPWNo+n4muDAueX651Seb66GSVbeHrFGNGPOM4X1iElYqocXevnMta1Q3xwragudXSdAnHkw== dependencies: - "@nrwl/tao" "12.7.1" + "@nrwl/tao" "12.7.2" ejs "^3.1.5" ignore "^5.0.4" rxjs "^6.5.4" semver "7.3.4" tslib "^2.0.0" -"@nrwl/jest@12.7.1": - version "12.7.1" - resolved "https://registry.yarnpkg.com/@nrwl/jest/-/jest-12.7.1.tgz#1f90c3d032c10e7e5afd736bf74c328002350449" - integrity sha512-+Pg9UimjoDWAJUH2SLqHcdn+6gLvzB6uISDqh4tvzyixiHSUNcY/WMqP1X9qVFfFA4HMwr8YvA7RUFHbSCrcxA== +"@nrwl/jest@12.7.2": + version "12.7.2" + resolved "https://registry.yarnpkg.com/@nrwl/jest/-/jest-12.7.2.tgz#5aecf205a5d221c7b49dc05825db1bda7e2de3ec" + integrity sha512-kfBgCtdvobkjVqcQMN5NrkZXOVJPxspRtmSpe0o4D5eTgPPYSAAgPhcGZJ5b3RVV7PetqGG75AgNL5L1GtodHA== dependencies: "@jest/reporters" "27.0.6" "@jest/test-result" "27.0.6" - "@nrwl/devkit" "12.7.1" + "@nrwl/devkit" "12.7.2" chalk "4.1.0" identity-obj-proxy "3.0.0" jest-config "27.0.6" @@ -1800,12 +1800,12 @@ rxjs "^6.5.4" tslib "^2.0.0" -"@nrwl/linter@12.7.1": - version "12.7.1" - resolved "https://registry.yarnpkg.com/@nrwl/linter/-/linter-12.7.1.tgz#c5ccd17ade2b3d3f6410d18a4fd0ce8b2d3e5111" - integrity sha512-FUPaUhqDcXUjRW3hKYnkQ9c569TGr+zS3YDoNKSbOFBrr6MCRRPIJMRo6bDS38aMMIpOZ4tSwuvxuoVfOfW1Fg== +"@nrwl/linter@12.7.2": + version "12.7.2" + resolved "https://registry.yarnpkg.com/@nrwl/linter/-/linter-12.7.2.tgz#db22b83ee74c6ed4bf953d0b833c5a28b20c6d63" + integrity sha512-dHuzxiOML8DvK5ed3o9P2vqyjFnRs+9+oyIC/ODGEupvDEKxDRemybTjuEAM30vMmDIJdHI/NOlEd/nxbW+6JA== dependencies: - "@nrwl/devkit" "12.7.1" + "@nrwl/devkit" "12.7.2" glob "7.1.4" minimatch "3.0.4" tmp "~0.2.1" @@ -1823,10 +1823,10 @@ strip-json-comments "^3.1.1" tar "5.0.7" -"@nrwl/tao@12.7.1": - version "12.7.1" - resolved "https://registry.yarnpkg.com/@nrwl/tao/-/tao-12.7.1.tgz#467b5b56f8e503d4a6acbd6eecd4ad51042d8d27" - integrity sha512-cQvrFwA+mEAiY3HwIuTjsO/yxgGEoffdUcsH6Oak3dcypkmTf4mVxqmuyzvJ5smt8cggg8qb7BEWowWs31folw== +"@nrwl/tao@12.7.2": + version "12.7.2" + resolved "https://registry.yarnpkg.com/@nrwl/tao/-/tao-12.7.2.tgz#73dd6a0bc7f64d9a823560c8aede0953c0a15dd5" + integrity sha512-LnylUSOznJ+EDmJWu7vvQTnAERPTjKRHznShTe6eMoaJUH0ds3WSGMBxLUulzN2P5dWqO9u26GWMZpInYWwkfA== dependencies: chalk "4.1.0" enquirer "~2.3.6" @@ -1839,15 +1839,15 @@ tslib "^2.0.0" yargs-parser "20.0.0" -"@nrwl/workspace@12.7.1": - version "12.7.1" - resolved "https://registry.yarnpkg.com/@nrwl/workspace/-/workspace-12.7.1.tgz#b140311473a2a45776674665bffb5eb001ce3465" - integrity sha512-84XRqtRc4pfO8agQqEX984w5HUyN+xWhz3EZv88w8QQfHdIooARj8wRb2lyKu7wHdaKaYNzx0pG9LLuVQYq6GQ== +"@nrwl/workspace@12.7.2": + version "12.7.2" + resolved "https://registry.yarnpkg.com/@nrwl/workspace/-/workspace-12.7.2.tgz#a1a7af9748db8d5bd4da89746d9ab1314426b246" + integrity sha512-aPlPHG1AmKHP8HiD9VHvkIEUsFZlFmqdm0JwJlv4935C3A8/TIln8thyUdFZDIYkR0jGLBd90RFQcWs2CX+Ocg== dependencies: - "@nrwl/cli" "12.7.1" - "@nrwl/devkit" "12.7.1" - "@nrwl/jest" "12.7.1" - "@nrwl/linter" "12.7.1" + "@nrwl/cli" "12.7.2" + "@nrwl/devkit" "12.7.2" + "@nrwl/jest" "12.7.2" + "@nrwl/linter" "12.7.2" chalk "4.1.0" chokidar "^3.5.1" cosmiconfig "^4.0.0" From f81831bd279a32da6dbab0f1c061053ea43965f6 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sat, 28 Aug 2021 10:37:05 +0900 Subject: [PATCH 2/9] feat(typescript-estree): add support for class static blocks (#3730) --- README.md | 2 +- package.json | 4 +- packages/ast-spec/src/ast-node-types.ts | 1 + .../ast-spec/src/element/StaticBlock/spec.ts | 8 + packages/ast-spec/src/element/spec.ts | 1 + .../PunctuatorToken/PunctuatorTokenToText.ts | 8 +- packages/ast-spec/src/unions/ClassElement.ts | 2 + packages/ast-spec/src/unions/Node.ts | 2 + .../indent-new-do-not-use/OffsetStorage.ts | 6 +- packages/parser/tests/tools/test-utils.ts | 2 +- packages/scope-manager/tests/fixtures.test.ts | 5 +- .../basics/class-static-blocks.src.ts | 8 + packages/typescript-estree/src/convert.ts | 13 +- packages/typescript-estree/src/node-utils.ts | 6 +- packages/typescript-estree/src/parser.ts | 4 +- .../src/ts-estree/estree-to-ts-node-types.ts | 1 + .../src/ts-estree/ts-nodes.ts | 1 + .../tests/ast-alignment/parse.ts | 5 +- .../tests/ast-alignment/utils.ts | 10 + .../tests/ast-fixtures.test.ts | 5 +- .../semantic-diagnostics-enabled.test.ts.snap | 14 +- .../typescript-estree/tests/lib/parse.test.ts | 10 +- ...invalid-mismatched-closing-tag.src.js.shot | 4 +- ...nvalid-mismatched-dot-tag-name.src.js.shot | 4 +- ...valid-mismatched-namespace-tag.src.js.shot | 4 +- .../basics/class-static-blocks.src.ts.shot | 702 ++++++++++++++++++ .../typescript-estree/tools/test-utils.ts | 2 +- packages/visitor-keys/src/visitor-keys.ts | 1 + yarn.lock | 8 +- 29 files changed, 805 insertions(+), 38 deletions(-) create mode 100644 packages/ast-spec/src/element/StaticBlock/spec.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/class-static-blocks.src.ts create mode 100644 packages/typescript-estree/tests/snapshots/typescript/basics/class-static-blocks.src.ts.shot diff --git a/README.md b/README.md index 25a1a58f3eda..2443ba50a162 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ The latest version under the `canary` tag **(latest commit to master)** is: ## Supported TypeScript Version -**The version range of TypeScript currently supported by this parser is `>=3.3.1 <4.4.0`.** +**The version range of TypeScript currently supported by this parser is `>=3.3.1 <4.5.0`.** These versions are what we test against. diff --git a/package.json b/package.json index 3939cc2d63a1..2e42c438b868 100644 --- a/package.json +++ b/package.json @@ -121,12 +121,12 @@ "ts-jest": "^27.0.1", "ts-node": "^10.0.0", "tslint": "^6.1.3", - "typescript": ">=3.3.1 <4.4.0" + "typescript": ">=3.3.1 <4.5.0" }, "resolutions": { "@types/node": "^15.6.1", "jest-diff": "^27.0.0", "pretty-format": "^27.0.0", - "typescript": "4.3.5" + "typescript": "4.4.2" } } diff --git a/packages/ast-spec/src/ast-node-types.ts b/packages/ast-spec/src/ast-node-types.ts index 6aa0087d5eb2..90a18ba8d9ed 100644 --- a/packages/ast-spec/src/ast-node-types.ts +++ b/packages/ast-spec/src/ast-node-types.ts @@ -68,6 +68,7 @@ export enum AST_NODE_TYPES { ReturnStatement = 'ReturnStatement', SequenceExpression = 'SequenceExpression', SpreadElement = 'SpreadElement', + StaticBlock = 'StaticBlock', Super = 'Super', SwitchCase = 'SwitchCase', SwitchStatement = 'SwitchStatement', diff --git a/packages/ast-spec/src/element/StaticBlock/spec.ts b/packages/ast-spec/src/element/StaticBlock/spec.ts new file mode 100644 index 000000000000..526a5f65f6d8 --- /dev/null +++ b/packages/ast-spec/src/element/StaticBlock/spec.ts @@ -0,0 +1,8 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; +import type { Statement } from '../../unions/Statement'; + +export interface StaticBlock extends BaseNode { + type: AST_NODE_TYPES.StaticBlock; + body: Statement[]; +} diff --git a/packages/ast-spec/src/element/spec.ts b/packages/ast-spec/src/element/spec.ts index 5ee18d914024..a31caecced39 100644 --- a/packages/ast-spec/src/element/spec.ts +++ b/packages/ast-spec/src/element/spec.ts @@ -2,6 +2,7 @@ export * from './ClassProperty/spec'; export * from './MethodDefinition/spec'; export * from './Property/spec'; export * from './SpreadElement/spec'; +export * from './StaticBlock/spec'; export * from './TSAbstractClassProperty/spec'; export * from './TSAbstractMethodDefinition/spec'; export * from './TSCallSignatureDeclaration/spec'; diff --git a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts index 174e98e6c6b0..d15682a4efe7 100644 --- a/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts +++ b/packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts @@ -45,7 +45,7 @@ export interface PunctuatorTokenToText { [SyntaxKind.AtToken]: '@'; [SyntaxKind.QuestionQuestionToken]: '??'; [SyntaxKind.BacktickToken]: '`'; - // [SyntaxKind.HashToken]: '#'; // new in PunctuationSyntaxKind in TS 4.4 + [SyntaxKind.HashToken]: '#'; [SyntaxKind.EqualsToken]: '='; [SyntaxKind.PlusEqualsToken]: '+='; [SyntaxKind.MinusEqualsToken]: '-='; @@ -58,8 +58,8 @@ export interface PunctuatorTokenToText { [SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: '>>>='; [SyntaxKind.AmpersandEqualsToken]: '&='; [SyntaxKind.BarEqualsToken]: '|='; - [SyntaxKind.BarBarEqualsToken]: '||='; // included in PunctuationSyntaxKind in TS 4.4 - [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; // included in PunctuationSyntaxKind in TS 4.4 - [SyntaxKind.QuestionQuestionEqualsToken]: '??='; // included in PunctuationSyntaxKind in TS 4.4 + [SyntaxKind.BarBarEqualsToken]: '||='; + [SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; + [SyntaxKind.QuestionQuestionEqualsToken]: '??='; [SyntaxKind.CaretEqualsToken]: '^='; } diff --git a/packages/ast-spec/src/unions/ClassElement.ts b/packages/ast-spec/src/unions/ClassElement.ts index a4d986d09c73..c174c4ce6c72 100644 --- a/packages/ast-spec/src/unions/ClassElement.ts +++ b/packages/ast-spec/src/unions/ClassElement.ts @@ -1,5 +1,6 @@ import type { ClassProperty } from '../element/ClassProperty/spec'; import type { MethodDefinition } from '../element/MethodDefinition/spec'; +import type { StaticBlock } from '../element/StaticBlock/spec'; import type { TSAbstractClassProperty } from '../element/TSAbstractClassProperty/spec'; import type { TSAbstractMethodDefinition } from '../element/TSAbstractMethodDefinition/spec'; import type { TSIndexSignature } from '../element/TSIndexSignature/spec'; @@ -7,6 +8,7 @@ import type { TSIndexSignature } from '../element/TSIndexSignature/spec'; export type ClassElement = | ClassProperty | MethodDefinition + | StaticBlock | TSAbstractClassProperty | TSAbstractMethodDefinition | TSIndexSignature; diff --git a/packages/ast-spec/src/unions/Node.ts b/packages/ast-spec/src/unions/Node.ts index 61c943af566a..f0802b3b6850 100644 --- a/packages/ast-spec/src/unions/Node.ts +++ b/packages/ast-spec/src/unions/Node.ts @@ -16,6 +16,7 @@ import type { ClassProperty } from '../element/ClassProperty/spec'; import type { MethodDefinition } from '../element/MethodDefinition/spec'; import type { Property } from '../element/Property/spec'; import type { SpreadElement } from '../element/SpreadElement/spec'; +import type { StaticBlock } from '../element/StaticBlock/spec'; import type { TSAbstractClassProperty } from '../element/TSAbstractClassProperty/spec'; import type { TSAbstractMethodDefinition } from '../element/TSAbstractMethodDefinition/spec'; import type { TSCallSignatureDeclaration } from '../element/TSCallSignatureDeclaration/spec'; @@ -235,6 +236,7 @@ export type Node = | ReturnStatement | SequenceExpression | SpreadElement + | StaticBlock | Super | SwitchCase | SwitchStatement diff --git a/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts b/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts index c673a7d5af4b..6feea3d95ada 100644 --- a/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts +++ b/packages/eslint-plugin/src/rules/indent-new-do-not-use/OffsetStorage.ts @@ -179,7 +179,7 @@ export class OffsetStorage { fromToken.range[1] <= range[1]; // this has to be before the delete + insert below or else you'll get into a cycle const fromTokenDescriptor = fromTokenIsInRange - ? this.getOffsetDescriptor(fromToken!) + ? this.getOffsetDescriptor(fromToken) : null; // First, remove any existing nodes in the range from the tree. @@ -193,8 +193,8 @@ export class OffsetStorage { * even if it's in the current range. */ if (fromTokenIsInRange) { - this.tree.insert(fromToken!.range[0], fromTokenDescriptor!); - this.tree.insert(fromToken!.range[1], descriptorToInsert); + this.tree.insert(fromToken.range[0], fromTokenDescriptor!); + this.tree.insert(fromToken.range[1], descriptorToInsert); } /* diff --git a/packages/parser/tests/tools/test-utils.ts b/packages/parser/tests/tools/test-utils.ts index 575ac1dc5b73..6dd679d1fea2 100644 --- a/packages/parser/tests/tools/test-utils.ts +++ b/packages/parser/tests/tools/test-utils.ts @@ -59,7 +59,7 @@ export function createSnapshotTestBlock( * AST_NODE_TYPE, we rethrow to cause the test to fail */ if (/Unknown AST_NODE_TYPE/.exec((error as Error).message)) { - throw new Error(error); + throw error; } expect(parse).toThrowErrorMatchingSnapshot(); } diff --git a/packages/scope-manager/tests/fixtures.test.ts b/packages/scope-manager/tests/fixtures.test.ts index 69833caa7faa..af327985df3b 100644 --- a/packages/scope-manager/tests/fixtures.test.ts +++ b/packages/scope-manager/tests/fixtures.test.ts @@ -139,7 +139,10 @@ function nestDescribe( try { makeDir.sync(fixture.snapshotPath); - } catch (e) { + } catch ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + e: any + ) { if ('code' in e && e.code === 'EEXIST') { // already exists - ignored } else { diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-static-blocks.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-static-blocks.src.ts new file mode 100644 index 000000000000..21ae81c3aea1 --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-static-blocks.src.ts @@ -0,0 +1,8 @@ +class Foo { + static count = 0; + static { + if (someCondition()) { + count++; + } + } +} diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 7f8514d8bc00..8170cedad3c2 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -311,7 +311,11 @@ export class Converter { */ private convertBodyExpressions( nodes: ts.NodeArray, - parent: ts.SourceFile | ts.Block | ts.ModuleBlock, + parent: + | ts.SourceFile + | ts.Block + | ts.ModuleBlock + | ts.ClassStaticBlockDeclaration, ): TSESTree.Statement[] { let allowDirectives = canContainDirective(parent); @@ -2824,6 +2828,13 @@ export class Converter { return result; } + case SyntaxKind.ClassStaticBlockDeclaration: { + return this.createNode(node, { + type: AST_NODE_TYPES.StaticBlock, + body: this.convertBodyExpressions(node.body.statements, node), + }); + } + default: return this.deeplyCopy(node); } diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index 8c223ed650a2..82f487b864cc 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -194,7 +194,11 @@ export function getLocFor( * @returns returns true if node can contain directive */ export function canContainDirective( - node: ts.SourceFile | ts.Block | ts.ModuleBlock, + node: + | ts.SourceFile + | ts.Block + | ts.ModuleBlock + | ts.ClassStaticBlockDeclaration, ): boolean { if (node.kind === ts.SyntaxKind.Block) { switch (node.parent.kind) { diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index e61b1b69ec2b..6cb3a2d6c27b 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -30,12 +30,12 @@ const log = debug('typescript-eslint:typescript-estree:parser'); * This needs to be kept in sync with the top-level README.md in the * typescript-eslint monorepo */ -const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.3.1 <4.4.0'; +const SUPPORTED_TYPESCRIPT_VERSIONS = '>=3.3.1 <4.5.0'; /* * The semver package will ignore prerelease ranges, and we don't want to explicitly document every one * List them all separately here, so we can automatically create the full string */ -const SUPPORTED_PRERELEASE_RANGES: string[] = ['4.3.0-beta', '4.3.1-rc']; +const SUPPORTED_PRERELEASE_RANGES: string[] = ['4.4.0-beta', '4.4.1-rc']; const ACTIVE_TYPESCRIPT_VERSION = ts.version; const isRunningSupportedTypeScriptVersion = semver.satisfies( ACTIVE_TYPESCRIPT_VERSION, diff --git a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts index 0f74c42ac64f..d5daed093324 100644 --- a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts +++ b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts @@ -135,6 +135,7 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.ReturnStatement]: ts.ReturnStatement; [AST_NODE_TYPES.SequenceExpression]: ts.BinaryExpression; [AST_NODE_TYPES.SpreadElement]: ts.SpreadElement | ts.SpreadAssignment; + [AST_NODE_TYPES.StaticBlock]: ts.ClassStaticBlockDeclaration; [AST_NODE_TYPES.Super]: ts.SuperExpression; [AST_NODE_TYPES.SwitchCase]: ts.CaseClause | ts.DefaultClause; [AST_NODE_TYPES.SwitchStatement]: ts.SwitchStatement; diff --git a/packages/typescript-estree/src/ts-estree/ts-nodes.ts b/packages/typescript-estree/src/ts-estree/ts-nodes.ts index 80a7b34e0c8b..673dd6f9831c 100644 --- a/packages/typescript-estree/src/ts-estree/ts-nodes.ts +++ b/packages/typescript-estree/src/ts-estree/ts-nodes.ts @@ -43,6 +43,7 @@ export type TSNode = | ts.KeywordTypeNode // TODO: This node is bad, maybe we should report this | ts.ImportTypeNode | ts.ThisTypeNode + | ts.ClassStaticBlockDeclaration // | ts.FunctionOrConstructorTypeNodeBase -> FunctionTypeNode, ConstructorTypeNode | ts.ConstructorTypeNode | ts.FunctionTypeNode diff --git a/packages/typescript-estree/tests/ast-alignment/parse.ts b/packages/typescript-estree/tests/ast-alignment/parse.ts index 7a463d97256b..484c8ef18d1e 100644 --- a/packages/typescript-estree/tests/ast-alignment/parse.ts +++ b/packages/typescript-estree/tests/ast-alignment/parse.ts @@ -26,6 +26,7 @@ function parseWithBabelParser(text: string, jsx = true): File { const plugins: ParserPlugin[] = [ 'classProperties', 'decorators-legacy', + 'classStaticBlock', 'estree', 'typescript', ]; @@ -61,7 +62,7 @@ function parseWithTypeScriptESTree(text: string, jsx = true): parser.AST { jsx, }); return result.ast; - } catch (e) { + } catch (e: any) { throw createError(e.message, e.lineNumber, e.column); } } @@ -97,7 +98,7 @@ export function parse( 'Please provide a valid parser: either "typescript-estree" or "@babel/parser"', ); } - } catch (error) { + } catch (error: any) { const loc = error.loc as TSESTree.LineAndColumnData | undefined; if (loc) { error.codeFrame = codeFrameColumns( diff --git a/packages/typescript-estree/tests/ast-alignment/utils.ts b/packages/typescript-estree/tests/ast-alignment/utils.ts index 3cecac3f09f6..7427c1b1831d 100644 --- a/packages/typescript-estree/tests/ast-alignment/utils.ts +++ b/packages/typescript-estree/tests/ast-alignment/utils.ts @@ -250,6 +250,16 @@ export function preprocessBabylonAST(ast: BabelTypes.File): any { } } }, + /** + * Babel adds a `static` property to the StaticBlock when the + * `typescript` plugin and the `classStaticBlock` plugin are enabled. + * @see https://github.com/babel/babel/issues/13674 + */ + StaticBlock(node: any) { + if (node.static != null) { + delete node.static; + } + }, }, ); } diff --git a/packages/typescript-estree/tests/ast-fixtures.test.ts b/packages/typescript-estree/tests/ast-fixtures.test.ts index 613595e4f8aa..f3ffbabd8098 100644 --- a/packages/typescript-estree/tests/ast-fixtures.test.ts +++ b/packages/typescript-estree/tests/ast-fixtures.test.ts @@ -58,7 +58,10 @@ function nestDescribe( try { makeDir.sync(fixture.snapshotPath); - } catch (e) { + } catch ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + e: any + ) { if ('code' in e && e.code === 'EEXIST') { // already exists - ignored } else { diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap index 7a972315f315..ce8d6b5cc6ec 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap @@ -1408,8 +1408,8 @@ TSError { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-closing-tag.src 1`] = ` TSError { - "column": 3, - "index": 3, + "column": 5, + "index": 5, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a'.", } @@ -1426,8 +1426,8 @@ TSError { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-dot-tag-name.src 1`] = ` TSError { - "column": 7, - "index": 7, + "column": 9, + "index": 9, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a.b.c'.", } @@ -1435,8 +1435,8 @@ TSError { exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/jsx/invalid-mismatched-namespace-tag.src 1`] = ` TSError { - "column": 5, - "index": 5, + "column": 7, + "index": 7, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a:b'.", } @@ -1742,6 +1742,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-multi-line-keyword-declare.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-static-blocks.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-accessibility-modifiers.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-constructor-and-modifier.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/lib/parse.test.ts b/packages/typescript-estree/tests/lib/parse.test.ts index aa15fc136c1b..236dc6929ad0 100644 --- a/packages/typescript-estree/tests/lib/parse.test.ts +++ b/packages/typescript-estree/tests/lib/parse.test.ts @@ -50,7 +50,10 @@ describe('parseWithNodeMaps()', () => { it('should have correct column number when strict mode error occurs', () => { try { parser.parseWithNodeMaps('function fn(a, a) {\n}'); - } catch (err) { + } catch ( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + err: any + ) { expect(err.column).toEqual(16); } }); @@ -505,7 +508,10 @@ describe('parseAndGenerateServices', () => { /** * Aligns paths between environments, node for windows uses `\`, for linux and mac uses `/` */ - error.message = (error as Error).message.replace(/\\(?!["])/gm, '/'); + (error as Error).message = (error as Error).message.replace( + /\\(?!["])/gm, + '/', + ); throw error; } }; diff --git a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot index a35f3afd7151..a8788896feb2 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-closing-tag.src.js.shot @@ -2,8 +2,8 @@ exports[`jsx invalid-mismatched-closing-tag.src 1`] = ` TSError { - "column": 3, - "index": 3, + "column": 5, + "index": 5, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a'.", } diff --git a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot index 77d7e4187c3b..560ee71e7f77 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-dot-tag-name.src.js.shot @@ -2,8 +2,8 @@ exports[`jsx invalid-mismatched-dot-tag-name.src 1`] = ` TSError { - "column": 7, - "index": 7, + "column": 9, + "index": 9, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a.b.c'.", } diff --git a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot index 1dd65c521056..4e5bac634b93 100644 --- a/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot +++ b/packages/typescript-estree/tests/snapshots/jsx/invalid-mismatched-namespace-tag.src.js.shot @@ -2,8 +2,8 @@ exports[`jsx invalid-mismatched-namespace-tag.src 1`] = ` TSError { - "column": 5, - "index": 5, + "column": 7, + "index": 7, "lineNumber": 1, "message": "Expected corresponding JSX closing tag for 'a:b'.", } diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/class-static-blocks.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/class-static-blocks.src.ts.shot new file mode 100644 index 000000000000..e370e9e24ea1 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/class-static-blocks.src.ts.shot @@ -0,0 +1,702 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript basics class-static-blocks.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "name": "count", + "range": Array [ + 21, + 26, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 31, + ], + "readonly": undefined, + "static": true, + "type": "ClassProperty", + "value": Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 30, + ], + "raw": "0", + "type": "Literal", + "value": 0, + }, + }, + Object { + "body": Array [ + Object { + "alternate": null, + "consequent": Object { + "body": Array [ + Object { + "expression": Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "name": "count", + "range": Array [ + 76, + 81, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "operator": "++", + "prefix": false, + "range": Array [ + 76, + 83, + ], + "type": "UpdateExpression", + }, + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 76, + 84, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 25, + "line": 4, + }, + }, + "range": Array [ + 68, + 90, + ], + "type": "BlockStatement", + }, + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 47, + 90, + ], + "test": Object { + "arguments": Array [], + "callee": Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "name": "someCondition", + "range": Array [ + 51, + 64, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "optional": false, + "range": Array [ + 51, + 66, + ], + "type": "CallExpression", + }, + "type": "IfStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 34, + 94, + ], + "type": "StaticBlock", + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 96, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 96, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 97, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 20, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 26, + ], + "type": "Identifier", + "value": "count", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 30, + ], + "type": "Numeric", + "value": "0", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 31, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 34, + 40, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 4, + }, + "start": Object { + "column": 4, + "line": 4, + }, + }, + "range": Array [ + 47, + 49, + ], + "type": "Keyword", + "value": "if", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 7, + "line": 4, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 4, + }, + "start": Object { + "column": 8, + "line": 4, + }, + }, + "range": Array [ + 51, + 64, + ], + "type": "Identifier", + "value": "someCondition", + }, + Object { + "loc": Object { + "end": Object { + "column": 22, + "line": 4, + }, + "start": Object { + "column": 21, + "line": 4, + }, + }, + "range": Array [ + 64, + 65, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 22, + "line": 4, + }, + }, + "range": Array [ + 65, + 66, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 4, + }, + "start": Object { + "column": 23, + "line": 4, + }, + }, + "range": Array [ + 66, + 67, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 26, + "line": 4, + }, + "start": Object { + "column": 25, + "line": 4, + }, + }, + "range": Array [ + 68, + 69, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 5, + }, + "start": Object { + "column": 6, + "line": 5, + }, + }, + "range": Array [ + 76, + 81, + ], + "type": "Identifier", + "value": "count", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 11, + "line": 5, + }, + }, + "range": Array [ + 81, + 83, + ], + "type": "Punctuator", + "value": "++", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "range": Array [ + 83, + 84, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 89, + 90, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "range": Array [ + 93, + 94, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + "range": Array [ + 95, + 96, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tools/test-utils.ts b/packages/typescript-estree/tools/test-utils.ts index 362560bc08cc..c07ab65b831d 100644 --- a/packages/typescript-estree/tools/test-utils.ts +++ b/packages/typescript-estree/tools/test-utils.ts @@ -41,7 +41,7 @@ export function createSnapshotTestBlock( * AST_NODE_TYPE, we rethrow to cause the test to fail */ if (/Unknown AST_NODE_TYPE/.exec((error as Error).message)) { - throw new Error(error); + throw error; } expect(parse).toThrowErrorMatchingSnapshot(); } diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index 1f2363e948ec..63dcdaf5a954 100644 --- a/packages/visitor-keys/src/visitor-keys.ts +++ b/packages/visitor-keys/src/visitor-keys.ts @@ -50,6 +50,7 @@ const additionalKeys: AdditionalKeys = { ObjectPattern: ['decorators', 'properties', 'typeAnnotation'], RestElement: ['decorators', 'argument', 'typeAnnotation'], TaggedTemplateExpression: ['tag', 'typeParameters', 'quasi'], + StaticBlock: [], // JSX JSXOpeningElement: ['name', 'typeParameters', 'attributes'], diff --git a/yarn.lock b/yarn.lock index 95a2b43532c1..0b88e0d193b0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9483,10 +9483,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@*, typescript@4.3.5, "typescript@>=3.3.1 <4.4.0", typescript@^4.1.0-dev.20201026, typescript@~4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.5.tgz#4d1c37cc16e893973c45a06886b7113234f119f4" - integrity sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA== +typescript@*, typescript@4.4.2, "typescript@>=3.3.1 <4.5.0", typescript@^4.1.0-dev.20201026, typescript@~4.3.5: + version "4.4.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86" + integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ== uc.micro@^1.0.1, uc.micro@^1.0.5: version "1.0.6" From fa35e22702207baf07acb3eec11d3383721bf6b6 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Mon, 30 Aug 2021 08:28:09 +0900 Subject: [PATCH 3/9] fix(visitor-keys): add key to StaticBlock (v5) (#3812) --- packages/visitor-keys/src/visitor-keys.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index 63dcdaf5a954..efad2828a376 100644 --- a/packages/visitor-keys/src/visitor-keys.ts +++ b/packages/visitor-keys/src/visitor-keys.ts @@ -50,7 +50,7 @@ const additionalKeys: AdditionalKeys = { ObjectPattern: ['decorators', 'properties', 'typeAnnotation'], RestElement: ['decorators', 'argument', 'typeAnnotation'], TaggedTemplateExpression: ['tag', 'typeParameters', 'quasi'], - StaticBlock: [], + StaticBlock: ['body'], // JSX JSXOpeningElement: ['name', 'typeParameters', 'attributes'], From 820965c41c58be918770ff6bbae313c0cfc75d3c Mon Sep 17 00:00:00 2001 From: Minoru Takeuchi <31735614+dora1998@users.noreply.github.com> Date: Mon, 30 Aug 2021 15:18:01 +0900 Subject: [PATCH 4/9] feat(experimental-utils): add literal types to `global` option (#3634) --- packages/experimental-utils/src/ts-eslint/Linter.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/experimental-utils/src/ts-eslint/Linter.ts b/packages/experimental-utils/src/ts-eslint/Linter.ts index 56476834cc03..77c338f5a753 100644 --- a/packages/experimental-utils/src/ts-eslint/Linter.ts +++ b/packages/experimental-utils/src/ts-eslint/Linter.ts @@ -119,6 +119,8 @@ namespace Linter { export type RuleEntry = RuleLevel | RuleLevelAndOptions; export type RulesRecord = Partial>; + export type GlobalVariableOption = 'readonly' | 'writable' | 'off' | boolean; + // https://github.com/eslint/eslint/blob/v6.8.0/conf/config-schema.js interface BaseConfig { $schema?: string; @@ -133,7 +135,7 @@ namespace Linter { /** * The global variable settings. */ - globals?: { [name: string]: boolean }; + globals?: { [name: string]: GlobalVariableOption }; /** * The flag that disables directive comments. */ From 71dd27361a1bc93b5d5eb2279d805922b10002fd Mon Sep 17 00:00:00 2001 From: YeonJuan Date: Mon, 30 Aug 2021 15:22:29 +0900 Subject: [PATCH 5/9] fix(eslint-plugin): [prefer-reduce-type-parameter] handle already existing type params (#3706) --- .../src/rules/prefer-reduce-type-parameter.ts | 41 +++++++++++-------- .../prefer-reduce-type-parameter.test.ts | 17 ++++++++ 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts index 3b1af79ac6e8..8656c8d2376d 100644 --- a/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts +++ b/packages/eslint-plugin/src/rules/prefer-reduce-type-parameter.ts @@ -77,22 +77,31 @@ export default util.createRule({ context.report({ messageId: 'preferTypeParameter', node: secondArg, - fix: fixer => [ - fixer.removeRange([ - secondArg.range[0], - secondArg.expression.range[0], - ]), - fixer.removeRange([ - secondArg.expression.range[1], - secondArg.range[1], - ]), - fixer.insertTextAfter( - callee, - `<${context - .getSourceCode() - .getText(secondArg.typeAnnotation)}>`, - ), - ], + fix: fixer => { + const fixes = [ + fixer.removeRange([ + secondArg.range[0], + secondArg.expression.range[0], + ]), + fixer.removeRange([ + secondArg.expression.range[1], + secondArg.range[1], + ]), + ]; + + if (!callee.parent.typeParameters) { + fixes.push( + fixer.insertTextAfter( + callee, + `<${context + .getSourceCode() + .getText(secondArg.typeAnnotation)}>`, + ), + ); + } + + return fixes; + }, }); return; diff --git a/packages/eslint-plugin/tests/rules/prefer-reduce-type-parameter.test.ts b/packages/eslint-plugin/tests/rules/prefer-reduce-type-parameter.test.ts index a683a4ab0dc4..06613b260f74 100644 --- a/packages/eslint-plugin/tests/rules/prefer-reduce-type-parameter.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-reduce-type-parameter.test.ts @@ -39,6 +39,23 @@ ruleTester.run('prefer-reduce-type-parameter', rule, { '[1, 2, 3]?.reduce((a, s) => a.concat(s * 2), []);', ], invalid: [ + { + code: ` +declare const arr: string[]; +arr.reduce(acc => acc, arr.shift() as string); + `, + output: ` +declare const arr: string[]; +arr.reduce(acc => acc, arr.shift()); + `, + errors: [ + { + messageId: 'preferTypeParameter', + column: 32, + line: 3, + }, + ], + }, { code: '[1, 2, 3].reduce((a, s) => a.concat(s * 2), [] as number[]);', output: '[1, 2, 3].reduce((a, s) => a.concat(s * 2), []);', From c19fc6e03072ed549bc9b35ebe6961e10f8f9b43 Mon Sep 17 00:00:00 2001 From: Daniel Cassidy Date: Mon, 30 Aug 2021 07:23:35 +0100 Subject: [PATCH 6/9] fix(eslint-plugin): [dot-notation] false positive with optional chaining (#3711) closes #3510 --- .../eslint-plugin/src/rules/dot-notation.ts | 7 +++---- .../tests/rules/dot-notation.test.ts | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/src/rules/dot-notation.ts b/packages/eslint-plugin/src/rules/dot-notation.ts index d0757f55a084..becc2a92727c 100644 --- a/packages/eslint-plugin/src/rules/dot-notation.ts +++ b/packages/eslint-plugin/src/rules/dot-notation.ts @@ -110,10 +110,9 @@ export default createRule({ const objectType = typeChecker.getTypeAtLocation( esTreeNodeToTSNodeMap.get(node.object), ); - const indexType = typeChecker.getIndexTypeOfType( - objectType, - ts.IndexKind.String, - ); + const indexType = objectType + .getNonNullableType() + .getStringIndexType(); if (indexType != undefined) { return; } diff --git a/packages/eslint-plugin/tests/rules/dot-notation.test.ts b/packages/eslint-plugin/tests/rules/dot-notation.test.ts index cbdb2d523425..fe25e4de1f1d 100644 --- a/packages/eslint-plugin/tests/rules/dot-notation.test.ts +++ b/packages/eslint-plugin/tests/rules/dot-notation.test.ts @@ -99,6 +99,25 @@ x['hello'] = 3; `, options: [{ allowIndexSignaturePropertyAccess: true }], }, + { + code: ` +interface Nested { + property: string; + [key: string]: number | string; +} + +class Dingus { + nested: Nested; +} + +let dingus: Dingus | undefined; + +dingus?.nested.property; +dingus?.nested['hello']; + `, + options: [{ allowIndexSignaturePropertyAccess: true }], + parserOptions: { ecmaVersion: 2020 }, + }, ], invalid: [ { From 921cbca1d51870e33865a2a7ece068a222249c84 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Mon, 30 Aug 2021 11:54:34 +0530 Subject: [PATCH 7/9] docs(eslint-plugin): fix typo (#3725) --- packages/eslint-plugin/docs/rules/require-array-sort-compare.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/docs/rules/require-array-sort-compare.md b/packages/eslint-plugin/docs/rules/require-array-sort-compare.md index 78de19863f0c..7203452b6b59 100644 --- a/packages/eslint-plugin/docs/rules/require-array-sort-compare.md +++ b/packages/eslint-plugin/docs/rules/require-array-sort-compare.md @@ -11,7 +11,7 @@ When sorting numbers, this results in the classic "10 before 2" order: [1, 2, 3, 10, 20, 30].sort(); //→ [1, 10, 2, 20, 3, 30] ``` -This also means that `Array#sort` does not always sort consistently, as elements may have custom `#toString` implementations that are not deterministic; this trap is noted in the noted in the language specification thusly: +This also means that `Array#sort` does not always sort consistently, as elements may have custom `#toString` implementations that are not deterministic; this trap is noted in the language specification thusly: > NOTE 2: Method calls performed by the `ToString` abstract operations in steps 5 and 7 have the potential to cause `SortCompare` to not behave as a consistent comparison function.
> https://www.ecma-international.org/ecma-262/9.0/#sec-sortcompare From 569640739999d85111def13ac7ba1d16e02f10b8 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 30 Aug 2021 18:29:11 +1200 Subject: [PATCH 8/9] fix(eslint-plugin): isTypeReadonly error with , ): Readonlyness { function checkTypeArguments(arrayType: ts.TypeReference): Readonlyness { - const typeArguments = checker.getTypeArguments(arrayType); + const typeArguments = + // getTypeArguments was only added in TS3.7 + checker.getTypeArguments + ? checker.getTypeArguments(arrayType) + : arrayType.typeArguments ?? []; + // this shouldn't happen in reality as: // - tuples require at least 1 type argument // - ReadonlyArray requires at least 1 type argument From 26de6459a38389fff86351c1aa0881b11dc2a76a Mon Sep 17 00:00:00 2001 From: James Henry Date: Mon, 30 Aug 2021 17:03:16 +0000 Subject: [PATCH 9/9] chore: publish v4.30.0 --- CHANGELOG.md | 20 ++++++++++++++++++++ lerna.json | 2 +- packages/ast-spec/CHANGELOG.md | 11 +++++++++++ packages/ast-spec/package.json | 2 +- packages/eslint-plugin-internal/CHANGELOG.md | 8 ++++++++ packages/eslint-plugin-internal/package.json | 4 ++-- packages/eslint-plugin-tslint/CHANGELOG.md | 8 ++++++++ packages/eslint-plugin-tslint/package.json | 6 +++--- packages/eslint-plugin/CHANGELOG.md | 18 ++++++++++++++++++ packages/eslint-plugin/package.json | 6 +++--- packages/experimental-utils/CHANGELOG.md | 11 +++++++++++ packages/experimental-utils/package.json | 8 ++++---- packages/parser/CHANGELOG.md | 11 +++++++++++ packages/parser/package.json | 10 +++++----- packages/scope-manager/CHANGELOG.md | 11 +++++++++++ packages/scope-manager/package.json | 8 ++++---- packages/shared-fixtures/CHANGELOG.md | 11 +++++++++++ packages/shared-fixtures/package.json | 2 +- packages/types/CHANGELOG.md | 8 ++++++++ packages/types/package.json | 2 +- packages/typescript-estree/CHANGELOG.md | 11 +++++++++++ packages/typescript-estree/package.json | 8 ++++---- packages/visitor-keys/CHANGELOG.md | 16 ++++++++++++++++ packages/visitor-keys/package.json | 4 ++-- 24 files changed, 175 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d81bcf51a3fb..e844a0102464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,26 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [4.30.0](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.3...v4.30.0) (2021-08-30) + + +### Bug Fixes + +* **eslint-plugin:** [dot-notation] false positive with optional chaining ([#3711](https://github.com/typescript-eslint/typescript-eslint/issues/3711)) ([c19fc6e](https://github.com/typescript-eslint/typescript-eslint/commit/c19fc6e03072ed549bc9b35ebe6961e10f8f9b43)), closes [#3510](https://github.com/typescript-eslint/typescript-eslint/issues/3510) +* **eslint-plugin:** [prefer-reduce-type-parameter] handle already existing type params ([#3706](https://github.com/typescript-eslint/typescript-eslint/issues/3706)) ([71dd273](https://github.com/typescript-eslint/typescript-eslint/commit/71dd27361a1bc93b5d5eb2279d805922b10002fd)) +* **eslint-plugin:** isTypeReadonly error with pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy