From 6357df7b11e7eeb03833c90ff74111e25ff0ebad Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Tue, 22 Nov 2022 11:31:23 +0100 Subject: [PATCH] Update to TypeScript 4.9 (#3569) --- eslint-bridge/package-lock.json | 14 +++++++------- eslint-bridge/package.json | 2 +- .../src/linting/eslint/rules/helpers/ast.ts | 6 +++--- .../linting/eslint/rules/helpers/module.ts | 19 +++++++++++++------ .../it/plugin/EslintCustomRulesTest.java | 2 +- .../js/backbone/javascript-S3800.json | 5 ----- .../js/es5-shim/javascript-S1874.json | 3 +++ .../js/mootools-core/javascript-S1874.json | 3 +++ .../js/paper.js/javascript-S2259.json | 16 ---------------- .../js/paper.js/javascript-S3758.json | 5 ----- .../js/prototype/javascript-S1874.json | 3 +++ .../ts/TypeScript/typescript-S4325.json | 1 + .../ts/ant-design/typescript-S1874.json | 3 +++ 13 files changed, 38 insertions(+), 44 deletions(-) delete mode 100644 its/ruling/src/test/expected/js/backbone/javascript-S3800.json delete mode 100644 its/ruling/src/test/expected/js/paper.js/javascript-S2259.json delete mode 100644 its/ruling/src/test/expected/js/paper.js/javascript-S3758.json diff --git a/eslint-bridge/package-lock.json b/eslint-bridge/package-lock.json index 10b21c0d799..388da86921a 100644 --- a/eslint-bridge/package-lock.json +++ b/eslint-bridge/package-lock.json @@ -72,7 +72,7 @@ "scslre": "0.1.6", "stylelint": "14.13.0", "tmp": "0.2.1", - "typescript": "4.8.3", + "typescript": "4.9.3", "vue-eslint-parser": "9.1.0", "yaml": "2.1.1" }, @@ -9732,9 +9732,9 @@ } }, "node_modules/typescript": { - "version": "4.8.3", - "resolved": "https://repox.jfrog.io/repox/api/npm/npm/typescript/-/typescript-4.8.3.tgz", - "integrity": "sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==", + "version": "4.9.3", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/typescript/-/typescript-4.9.3.tgz", + "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==", "inBundle": true, "bin": { "tsc": "bin/tsc", @@ -17124,9 +17124,9 @@ } }, "typescript": { - "version": "4.8.3", - "resolved": "https://repox.jfrog.io/repox/api/npm/npm/typescript/-/typescript-4.8.3.tgz", - "integrity": "sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==" + "version": "4.9.3", + "resolved": "https://repox.jfrog.io/repox/api/npm/npm/typescript/-/typescript-4.9.3.tgz", + "integrity": "sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==" }, "unbox-primitive": { "version": "1.0.2", diff --git a/eslint-bridge/package.json b/eslint-bridge/package.json index 7856831c15a..2debb16a968 100644 --- a/eslint-bridge/package.json +++ b/eslint-bridge/package.json @@ -74,7 +74,7 @@ "scslre": "0.1.6", "stylelint": "14.13.0", "tmp": "0.2.1", - "typescript": "4.8.3", + "typescript": "4.9.3", "vue-eslint-parser": "9.1.0", "yaml": "2.1.1" }, diff --git a/eslint-bridge/src/linting/eslint/rules/helpers/ast.ts b/eslint-bridge/src/linting/eslint/rules/helpers/ast.ts index a9482b19bd6..fa4367bc059 100644 --- a/eslint-bridge/src/linting/eslint/rules/helpers/ast.ts +++ b/eslint-bridge/src/linting/eslint/rules/helpers/ast.ts @@ -267,12 +267,12 @@ export function getUniqueWriteUsageOrNode( } } -export function getValueOfExpression( +export function getValueOfExpression( context: Rule.RuleContext, - expr: Node | undefined | null, + expr: estree.Node | undefined | null, type: T, recursive = false, -): Extract | undefined { +): Extract | undefined { if (!expr) { return undefined; } diff --git a/eslint-bridge/src/linting/eslint/rules/helpers/module.ts b/eslint-bridge/src/linting/eslint/rules/helpers/module.ts index dfc44df0faf..bf70a07e8a0 100644 --- a/eslint-bridge/src/linting/eslint/rules/helpers/module.ts +++ b/eslint-bridge/src/linting/eslint/rules/helpers/module.ts @@ -20,6 +20,7 @@ import assert from 'assert'; import { Rule, Scope } from 'eslint'; import * as estree from 'estree'; +import { TSESTree } from '@typescript-eslint/experimental-utils'; import { Node, isDefaultSpecifier, @@ -270,7 +271,7 @@ export function hasFullyQualifiedName( */ export function getFullyQualifiedName( context: Rule.RuleContext, - node: Node, + node: estree.Node, fqn: string[] = [], scope?: Scope.Scope, ): string | null { @@ -339,7 +340,7 @@ export function getFullyQualifiedName( * @param node the Node to traverse * @param fqn the array with the qualifiers */ -export function reduceToIdentifier(node: Node, fqn: string[] = []): Node { +export function reduceToIdentifier(node: estree.Node, fqn: string[] = []): estree.Node { return reduceTo('Identifier', node, fqn); } @@ -351,8 +352,12 @@ export function reduceToIdentifier(node: Node, fqn: string[] = []): Node { * @param node the Node to traverse * @param fqn the array with the qualifiers */ -export function reduceTo(type: T, node: Node, fqn: string[] = []): Node { - let nodeToCheck: Node = node; +export function reduceTo( + type: T, + node: estree.Node, + fqn: string[] = [], +): estree.Node { + let nodeToCheck: estree.Node = node; while (nodeToCheck.type !== type) { if (nodeToCheck.type === 'MemberExpression') { @@ -369,8 +374,10 @@ export function reduceTo(type: T, node: Node, fqn: strin nodeToCheck = nodeToCheck.callee; } else if (nodeToCheck.type === 'ChainExpression') { nodeToCheck = nodeToCheck.expression; - } else if (nodeToCheck.type === 'TSNonNullExpression') { - nodeToCheck = nodeToCheck.expression; + } else if ((nodeToCheck as TSESTree.Node).type === 'TSNonNullExpression') { + // we should migrate to use only TSESTree types everywhere to avoid casting + nodeToCheck = (nodeToCheck as unknown as TSESTree.TSNonNullExpression) + .expression as estree.Expression; } else { break; } diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/EslintCustomRulesTest.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/EslintCustomRulesTest.java index fdf4f4c8e34..b0df8faac99 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/EslintCustomRulesTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/EslintCustomRulesTest.java @@ -98,7 +98,7 @@ void test() { BuildResult buildResult = runBuild(orchestrator); assertThat(buildResult.getLogsLines(l -> l.matches(".*DEBUG: Deploying custom rules bundle jar:file:.*/custom-eslint-based-rules-1\\.0\\.0\\.tgz to .*"))).hasSize(1); assertThat(buildResult.getLogsLines(l -> l.contains("Custom JavaScript rules are deprecated and API will be removed in future version."))).isEmpty(); - assertThat(buildResult.getLogsLines(l -> l.contains("TS API in custom rule: TS version 4.8.3"))).hasSize(2); + assertThat(buildResult.getLogsLines(l -> l.contains("TS API in custom rule: TS version 4.9.3"))).hasSize(2); List issues = findIssues("eslint-custom-rules:sqKey", orchestrator); assertThat(issues).hasSize(2); assertThat(issues).extracting(Issue::getRule, Issue::getComponent, Issue::getLine, Issue::getMessage) diff --git a/its/ruling/src/test/expected/js/backbone/javascript-S3800.json b/its/ruling/src/test/expected/js/backbone/javascript-S3800.json deleted file mode 100644 index d230e91fb21..00000000000 --- a/its/ruling/src/test/expected/js/backbone/javascript-S3800.json +++ /dev/null @@ -1,5 +0,0 @@ -{ -'backbone:backbone.js':[ -473, -], -} diff --git a/its/ruling/src/test/expected/js/es5-shim/javascript-S1874.json b/its/ruling/src/test/expected/js/es5-shim/javascript-S1874.json index 23c6678918a..56af88f45a5 100644 --- a/its/ruling/src/test/expected/js/es5-shim/javascript-S1874.json +++ b/its/ruling/src/test/expected/js/es5-shim/javascript-S1874.json @@ -1,4 +1,7 @@ { +'es5-shim:es5-sham.js':[ +214, +], 'es5-shim:es5-shim.js':[ 1949, 1950, diff --git a/its/ruling/src/test/expected/js/mootools-core/javascript-S1874.json b/its/ruling/src/test/expected/js/mootools-core/javascript-S1874.json index 65b83cffbb4..95101243705 100644 --- a/its/ruling/src/test/expected/js/mootools-core/javascript-S1874.json +++ b/its/ruling/src/test/expected/js/mootools-core/javascript-S1874.json @@ -1,4 +1,7 @@ { +'mootools-core:Source/Fx/Fx.CSS.js':[ +125, +], 'mootools-core:Source/Types/Function.js':[ 91, ], diff --git a/its/ruling/src/test/expected/js/paper.js/javascript-S2259.json b/its/ruling/src/test/expected/js/paper.js/javascript-S2259.json deleted file mode 100644 index c95007c3641..00000000000 --- a/its/ruling/src/test/expected/js/paper.js/javascript-S2259.json +++ /dev/null @@ -1,16 +0,0 @@ -{ -'paper.js:src/item/Item.js':[ -979, -1284, -3593, -], -'paper.js:src/path/Curve.js':[ -492, -], -'paper.js:src/path/Path.js':[ -231, -], -'paper.js:src/style/Gradient.js':[ -162, -], -} diff --git a/its/ruling/src/test/expected/js/paper.js/javascript-S3758.json b/its/ruling/src/test/expected/js/paper.js/javascript-S3758.json deleted file mode 100644 index f5fce12742a..00000000000 --- a/its/ruling/src/test/expected/js/paper.js/javascript-S3758.json +++ /dev/null @@ -1,5 +0,0 @@ -{ -'paper.js:src/path/PathFlattener.js':[ -121, -], -} diff --git a/its/ruling/src/test/expected/js/prototype/javascript-S1874.json b/its/ruling/src/test/expected/js/prototype/javascript-S1874.json index 79f798292b9..e69db4dd3d4 100644 --- a/its/ruling/src/test/expected/js/prototype/javascript-S1874.json +++ b/its/ruling/src/test/expected/js/prototype/javascript-S1874.json @@ -1,4 +1,7 @@ { +'prototype:src/prototype/ajax/request.js':[ +327, +], 'prototype:src/prototype/ajax/response.js':[ 159, ], diff --git a/its/ruling/src/test/expected/ts/TypeScript/typescript-S4325.json b/its/ruling/src/test/expected/ts/TypeScript/typescript-S4325.json index 27cc9a4b502..df30f23c638 100644 --- a/its/ruling/src/test/expected/ts/TypeScript/typescript-S4325.json +++ b/its/ruling/src/test/expected/ts/TypeScript/typescript-S4325.json @@ -180,6 +180,7 @@ 917, 985, 1362, +1366, ], 'TypeScript:src/compiler/declarationEmitter.ts':[ 789, diff --git a/its/ruling/src/test/expected/ts/ant-design/typescript-S1874.json b/its/ruling/src/test/expected/ts/ant-design/typescript-S1874.json index 307a5fdacb8..1fec4600e9c 100644 --- a/its/ruling/src/test/expected/ts/ant-design/typescript-S1874.json +++ b/its/ruling/src/test/expected/ts/ant-design/typescript-S1874.json @@ -29,4 +29,7 @@ 90, 91, ], +'ant-design:site/theme/template/Layout/Header/SearchBar.tsx':[ +38, +], }