diff --git a/.all-contributorsrc b/.all-contributorsrc index 9302be7a782e..83cf734ca4ed 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -400,6 +400,13 @@ "avatar_url": "https://avatars.githubusercontent.com/u/16860535?v=4", "profile": "https://github.com/soobing", "contributions": [] + }, + { + "login": "RebeccaStevens", + "name": "Rebecca Stevens", + "avatar_url": "https://avatars.githubusercontent.com/u/7224206?v=4", + "profile": "https://github.com/RebeccaStevens", + "contributions": [] } ], "contributorsPerLine": 5 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 =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/lerna.json b/lerna.json index 637ecf6da40d..9a59e7c6919a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "4.29.3", + "version": "4.30.0", "npmClient": "yarn", "useWorkspaces": true, "stream": true diff --git a/package.json b/package.json index 0fe544880b6b..2e42c438b868 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", @@ -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/CHANGELOG.md b/packages/ast-spec/CHANGELOG.md index 5627acbec6a0..bec6a7f1f74b 100644 --- a/packages/ast-spec/CHANGELOG.md +++ b/packages/ast-spec/CHANGELOG.md @@ -3,6 +3,17 @@ 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) + + +### Features + +* **typescript-estree:** add support for class static blocks ([#3730](https://github.com/typescript-eslint/typescript-eslint/issues/3730)) ([f81831b](https://github.com/typescript-eslint/typescript-eslint/commit/f81831bd279a32da6dbab0f1c061053ea43965f6)) + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/ast-spec diff --git a/packages/ast-spec/package.json b/packages/ast-spec/package.json index aa6cf9592e0e..b0af29d0e957 100644 --- a/packages/ast-spec/package.json +++ b/packages/ast-spec/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/ast-spec", - "version": "4.29.3", + "version": "4.30.0", "description": "TypeScript-ESTree AST spec", "private": true, "keywords": [ 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-internal/CHANGELOG.md b/packages/eslint-plugin-internal/CHANGELOG.md index 92750d023fc2..a704b20f06e4 100644 --- a/packages/eslint-plugin-internal/CHANGELOG.md +++ b/packages/eslint-plugin-internal/CHANGELOG.md @@ -3,6 +3,14 @@ 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) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/eslint-plugin-internal diff --git a/packages/eslint-plugin-internal/package.json b/packages/eslint-plugin-internal/package.json index ef199d652308..2b6a5a56a690 100644 --- a/packages/eslint-plugin-internal/package.json +++ b/packages/eslint-plugin-internal/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-internal", - "version": "4.29.3", + "version": "4.30.0", "private": true, "main": "dist/index.js", "scripts": { @@ -14,7 +14,7 @@ }, "dependencies": { "@types/prettier": "*", - "@typescript-eslint/experimental-utils": "4.29.3", + "@typescript-eslint/experimental-utils": "4.30.0", "prettier": "*" } } diff --git a/packages/eslint-plugin-tslint/CHANGELOG.md b/packages/eslint-plugin-tslint/CHANGELOG.md index 0f0390e98a1c..ef836910ccfd 100644 --- a/packages/eslint-plugin-tslint/CHANGELOG.md +++ b/packages/eslint-plugin-tslint/CHANGELOG.md @@ -3,6 +3,14 @@ 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) + +**Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/eslint-plugin-tslint diff --git a/packages/eslint-plugin-tslint/package.json b/packages/eslint-plugin-tslint/package.json index 1eddf7f65397..df35db555106 100644 --- a/packages/eslint-plugin-tslint/package.json +++ b/packages/eslint-plugin-tslint/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin-tslint", - "version": "4.29.3", + "version": "4.30.0", "main": "dist/index.js", "typings": "src/index.ts", "description": "TSLint wrapper plugin for ESLint", @@ -38,7 +38,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "4.29.3", + "@typescript-eslint/experimental-utils": "4.30.0", "lodash": "^4.17.21" }, "peerDependencies": { @@ -48,6 +48,6 @@ }, "devDependencies": { "@types/lodash": "*", - "@typescript-eslint/parser": "4.29.3" + "@typescript-eslint/parser": "4.30.0" } } diff --git a/packages/eslint-plugin/CHANGELOG.md b/packages/eslint-plugin/CHANGELOG.md index 40e0e5d44b59..a433e2fc77eb 100644 --- a/packages/eslint-plugin/CHANGELOG.md +++ b/packages/eslint-plugin/CHANGELOG.md @@ -3,6 +3,24 @@ 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 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 diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index e820878dc938..9ac333083e52 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/eslint-plugin", - "version": "4.29.3", + "version": "4.30.0", "description": "TypeScript plugin for ESLint", "keywords": [ "eslint", @@ -44,8 +44,8 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/experimental-utils": "4.29.3", - "@typescript-eslint/scope-manager": "4.29.3", + "@typescript-eslint/experimental-utils": "4.30.0", + "@typescript-eslint/scope-manager": "4.30.0", "debug": "^4.3.1", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.1.0", 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/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/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/src/util/isTypeReadonly.ts b/packages/eslint-plugin/src/util/isTypeReadonly.ts index b10f00006ec5..4a42c90c1e05 100644 --- a/packages/eslint-plugin/src/util/isTypeReadonly.ts +++ b/packages/eslint-plugin/src/util/isTypeReadonly.ts @@ -23,7 +23,12 @@ function isTypeReadonlyArrayOrTuple( seenTypes: Set, ): 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 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: [ { 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), []);', diff --git a/packages/experimental-utils/CHANGELOG.md b/packages/experimental-utils/CHANGELOG.md index c342c557fbad..6c7d3f4676f0 100644 --- a/packages/experimental-utils/CHANGELOG.md +++ b/packages/experimental-utils/CHANGELOG.md @@ -3,6 +3,17 @@ 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) + + +### Features + +* **experimental-utils:** add literal types to `global` option ([#3634](https://github.com/typescript-eslint/typescript-eslint/issues/3634)) ([820965c](https://github.com/typescript-eslint/typescript-eslint/commit/820965c41c58be918770ff6bbae313c0cfc75d3c)) + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/experimental-utils diff --git a/packages/experimental-utils/package.json b/packages/experimental-utils/package.json index d803137f299b..779d7f1e61b6 100644 --- a/packages/experimental-utils/package.json +++ b/packages/experimental-utils/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/experimental-utils", - "version": "4.29.3", + "version": "4.30.0", "description": "(Experimental) Utilities for working with TypeScript + ESLint together", "keywords": [ "eslint", @@ -40,9 +40,9 @@ }, "dependencies": { "@types/json-schema": "^7.0.7", - "@typescript-eslint/scope-manager": "4.29.3", - "@typescript-eslint/types": "4.29.3", - "@typescript-eslint/typescript-estree": "4.29.3", + "@typescript-eslint/scope-manager": "4.30.0", + "@typescript-eslint/types": "4.30.0", + "@typescript-eslint/typescript-estree": "4.30.0", "eslint-scope": "^5.1.1", "eslint-utils": "^3.0.0" }, 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. */ diff --git a/packages/parser/CHANGELOG.md b/packages/parser/CHANGELOG.md index 3d2486446acd..5f6f603f8148 100644 --- a/packages/parser/CHANGELOG.md +++ b/packages/parser/CHANGELOG.md @@ -3,6 +3,17 @@ 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) + + +### Features + +* **typescript-estree:** add support for class static blocks ([#3730](https://github.com/typescript-eslint/typescript-eslint/issues/3730)) ([f81831b](https://github.com/typescript-eslint/typescript-eslint/commit/f81831bd279a32da6dbab0f1c061053ea43965f6)) + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/parser diff --git a/packages/parser/package.json b/packages/parser/package.json index 29afe096e674..5e802a17872b 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/parser", - "version": "4.29.3", + "version": "4.30.0", "description": "An ESLint custom parser which leverages TypeScript ESTree", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -44,14 +44,14 @@ "eslint": "^5.0.0 || ^6.0.0 || ^7.0.0" }, "dependencies": { - "@typescript-eslint/scope-manager": "4.29.3", - "@typescript-eslint/types": "4.29.3", - "@typescript-eslint/typescript-estree": "4.29.3", + "@typescript-eslint/scope-manager": "4.30.0", + "@typescript-eslint/types": "4.30.0", + "@typescript-eslint/typescript-estree": "4.30.0", "debug": "^4.3.1" }, "devDependencies": { "@types/glob": "*", - "@typescript-eslint/experimental-utils": "4.29.3", + "@typescript-eslint/experimental-utils": "4.30.0", "glob": "*", "typescript": "*" }, 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/CHANGELOG.md b/packages/scope-manager/CHANGELOG.md index f15ef8da580b..23932d879409 100644 --- a/packages/scope-manager/CHANGELOG.md +++ b/packages/scope-manager/CHANGELOG.md @@ -3,6 +3,17 @@ 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) + + +### Features + +* **typescript-estree:** add support for class static blocks ([#3730](https://github.com/typescript-eslint/typescript-eslint/issues/3730)) ([f81831b](https://github.com/typescript-eslint/typescript-eslint/commit/f81831bd279a32da6dbab0f1c061053ea43965f6)) + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/scope-manager diff --git a/packages/scope-manager/package.json b/packages/scope-manager/package.json index 7db0210d405c..63d3a69cecbb 100644 --- a/packages/scope-manager/package.json +++ b/packages/scope-manager/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/scope-manager", - "version": "4.29.3", + "version": "4.30.0", "description": "TypeScript scope analyser for ESLint", "keywords": [ "eslint", @@ -39,12 +39,12 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "4.29.3", - "@typescript-eslint/visitor-keys": "4.29.3" + "@typescript-eslint/types": "4.30.0", + "@typescript-eslint/visitor-keys": "4.30.0" }, "devDependencies": { "@types/glob": "*", - "@typescript-eslint/typescript-estree": "4.29.3", + "@typescript-eslint/typescript-estree": "4.30.0", "glob": "*", "jest-specific-snapshot": "*", "make-dir": "*", 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/CHANGELOG.md b/packages/shared-fixtures/CHANGELOG.md index 9a7b51acca7d..52a786b215ff 100644 --- a/packages/shared-fixtures/CHANGELOG.md +++ b/packages/shared-fixtures/CHANGELOG.md @@ -3,6 +3,17 @@ 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) + + +### Features + +* **typescript-estree:** add support for class static blocks ([#3730](https://github.com/typescript-eslint/typescript-eslint/issues/3730)) ([f81831b](https://github.com/typescript-eslint/typescript-eslint/commit/f81831bd279a32da6dbab0f1c061053ea43965f6)) + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/shared-fixtures 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/shared-fixtures/package.json b/packages/shared-fixtures/package.json index 666d29d0ed59..b5610cdd4378 100644 --- a/packages/shared-fixtures/package.json +++ b/packages/shared-fixtures/package.json @@ -1,5 +1,5 @@ { "name": "@typescript-eslint/shared-fixtures", - "version": "4.29.3", + "version": "4.30.0", "private": true } diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index e6131eca1229..cb86be96ec30 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -3,6 +3,14 @@ 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) + +**Note:** Version bump only for package @typescript-eslint/types + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/types diff --git a/packages/types/package.json b/packages/types/package.json index 7e46f7704ca6..6e23a521e748 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/types", - "version": "4.29.3", + "version": "4.30.0", "description": "Types for the TypeScript-ESTree AST spec", "keywords": [ "eslint", diff --git a/packages/typescript-estree/CHANGELOG.md b/packages/typescript-estree/CHANGELOG.md index e44dd7584acc..94a9165463b9 100644 --- a/packages/typescript-estree/CHANGELOG.md +++ b/packages/typescript-estree/CHANGELOG.md @@ -3,6 +3,17 @@ 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) + + +### Features + +* **typescript-estree:** add support for class static blocks ([#3730](https://github.com/typescript-eslint/typescript-eslint/issues/3730)) ([f81831b](https://github.com/typescript-eslint/typescript-eslint/commit/f81831bd279a32da6dbab0f1c061053ea43965f6)) + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/typescript-estree diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index a07fedf4db51..4366789dfa39 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/typescript-estree", - "version": "4.29.3", + "version": "4.30.0", "description": "A parser that converts TypeScript source code into an ESTree compatible form", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -41,8 +41,8 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "4.29.3", - "@typescript-eslint/visitor-keys": "4.29.3", + "@typescript-eslint/types": "4.30.0", + "@typescript-eslint/visitor-keys": "4.30.0", "debug": "^4.3.1", "globby": "^11.0.3", "is-glob": "^4.0.1", @@ -59,7 +59,7 @@ "@types/is-glob": "*", "@types/semver": "*", "@types/tmp": "*", - "@typescript-eslint/shared-fixtures": "4.29.3", + "@typescript-eslint/shared-fixtures": "4.30.0", "glob": "*", "jest-specific-snapshot": "*", "make-dir": "*", 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/CHANGELOG.md b/packages/visitor-keys/CHANGELOG.md index e1913397b9b5..8b1f5b13d4d0 100644 --- a/packages/visitor-keys/CHANGELOG.md +++ b/packages/visitor-keys/CHANGELOG.md @@ -3,6 +3,22 @@ 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 + +* **visitor-keys:** add key to StaticBlock (v5) ([#3812](https://github.com/typescript-eslint/typescript-eslint/issues/3812)) ([fa35e22](https://github.com/typescript-eslint/typescript-eslint/commit/fa35e22702207baf07acb3eec11d3383721bf6b6)) + + +### Features + +* **typescript-estree:** add support for class static blocks ([#3730](https://github.com/typescript-eslint/typescript-eslint/issues/3730)) ([f81831b](https://github.com/typescript-eslint/typescript-eslint/commit/f81831bd279a32da6dbab0f1c061053ea43965f6)) + + + + + ## [4.29.3](https://github.com/typescript-eslint/typescript-eslint/compare/v4.29.2...v4.29.3) (2021-08-23) **Note:** Version bump only for package @typescript-eslint/visitor-keys diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index d98f1a1f21ab..90167ed5d1be 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -1,6 +1,6 @@ { "name": "@typescript-eslint/visitor-keys", - "version": "4.29.3", + "version": "4.30.0", "description": "Visitor keys used to help traverse the TypeScript-ESTree AST", "keywords": [ "eslint", @@ -38,7 +38,7 @@ "typecheck": "tsc -p tsconfig.json --noEmit" }, "dependencies": { - "@typescript-eslint/types": "4.29.3", + "@typescript-eslint/types": "4.30.0", "eslint-visitor-keys": "^2.0.0" }, "devDependencies": { diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index 1f2363e948ec..efad2828a376 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: ['body'], // JSX JSXOpeningElement: ['name', 'typeParameters', 'attributes'], diff --git a/yarn.lock b/yarn.lock index fcc05284ae5a..0b88e0d193b0 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" @@ -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" 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