From 34864cc445ef66f9acd11e4ef5a71ca8c8537107 Mon Sep 17 00:00:00 2001 From: Igor Rossinski Date: Wed, 18 Oct 2023 01:57:36 +0300 Subject: [PATCH] [ArkTS Linter] fix err#13851 Signed-off-by: Igor Rossinski --- linter-4.2/src/TypeScriptLinter.ts | 12 +++++++----- linter-4.2/test/ts_ignore.ts.relax.json | 5 ----- linter-4.2/test/ts_ignore.ts.strict.json | 5 ----- linter/src/TypeScriptLinter.ts | 21 ++++++++++++--------- linter/test/ts_ignore.ts.relax.json | 5 ----- linter/test/ts_ignore.ts.strict.json | 5 ----- 6 files changed, 19 insertions(+), 34 deletions(-) diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index 1f79539c6..d1057736e 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -676,7 +676,7 @@ export class TypeScriptLinter { const baseExprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode.expression); const baseExprType = this.tsTypeChecker.getTypeAtLocation(propertyAccessNode.expression); - if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { + if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); } if (!!exprSym && this.tsUtils.isSymbolAPI(exprSym) && !TsUtils.ALLOWED_STD_SYMBOL_API.includes(exprSym.getName())) { @@ -764,7 +764,7 @@ export class TypeScriptLinter { ts.isIdentifier(x.expression.expression) ) decoratorName = x.expression.expression.text; - + // special case for property of type CustomDialogController of the @CustomDialog-decorated class if (expectedDecorators.includes(TsUtils.NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS[0])) { return expectedDecorators.includes(decoratorName) && propType === 'CustomDialogController' @@ -1578,7 +1578,7 @@ export class TypeScriptLinter { ); const checkClassOrInterface = tsElemAccessBaseExprType.isClassOrInterface() && !this.tsUtils.isGenericArrayType(tsElemAccessBaseExprType) && - !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); + !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); const checkThisOrSuper = this.tsUtils.isThisOrSuperExpr(tsElementAccessExpr.expression) && !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); @@ -1696,7 +1696,7 @@ export class TypeScriptLinter { this.handleStructIdentAndUndefinedInArgs(tsCallExpr, callSignature); } this.handleLibraryTypeCall(tsCallExpr, calleeType); - + if (ts.isPropertyAccessExpression(tsCallExpr.expression) && this.tsUtils.hasEsObjectType(tsCallExpr.expression.expression)) { this.incrementCounters(node, FaultID.EsObjectAccess); } @@ -2028,7 +2028,9 @@ export class TypeScriptLinter { comment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? srcText.slice(comment.pos + 2, comment.end - 2) : srcText.slice(comment.pos + 2, comment.end); - + //if comment is multiline end closing '*/' is not at the same line as '@ts-xxx' - do nothing (see #13851) + if (commentContent.endsWith('\n')) + return; let trimmedContent = commentContent.trim(); if ( trimmedContent.startsWith("@ts-ignore") || diff --git a/linter-4.2/test/ts_ignore.ts.relax.json b/linter-4.2/test/ts_ignore.ts.relax.json index d1f517671..787d4b0e1 100644 --- a/linter-4.2/test/ts_ignore.ts.relax.json +++ b/linter-4.2/test/ts_ignore.ts.relax.json @@ -34,11 +34,6 @@ "column": 9, "problem": "ErrorSuppression" }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" - }, { "line": 43, "column": 9, diff --git a/linter-4.2/test/ts_ignore.ts.strict.json b/linter-4.2/test/ts_ignore.ts.strict.json index d1f517671..787d4b0e1 100644 --- a/linter-4.2/test/ts_ignore.ts.strict.json +++ b/linter-4.2/test/ts_ignore.ts.strict.json @@ -34,11 +34,6 @@ "column": 9, "problem": "ErrorSuppression" }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" - }, { "line": 43, "column": 9, diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index bb384674b..27f7eecd5 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -599,7 +599,7 @@ export class TypeScriptLinter { const baseExprSym = this.tsUtils.trueSymbolAtLocation(propertyAccessNode.expression); const baseExprType = this.tsTypeChecker.getTypeAtLocation(propertyAccessNode.expression); - if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { + if (this.isPrototypePropertyAccess(propertyAccessNode, exprSym, baseExprSym, baseExprType)) { this.incrementCounters(propertyAccessNode.name, FaultID.Prototype); } if (!!exprSym && this.tsUtils.isSymbolAPI(exprSym) && !ALLOWED_STD_SYMBOL_API.includes(exprSym.getName())) { @@ -640,7 +640,7 @@ export class TypeScriptLinter { this.handleDecorators(decorators); this.filterOutDecoratorsDiagnostics(decorators, NON_INITIALIZABLE_PROPERTY_DECORATORS, {begin: propName.getStart(), end: propName.getStart()}, PROPERTY_HAS_NO_INITIALIZER_ERROR_CODE); - + const classDecorators = ts.getDecorators(node.parent); const propType = (node as ts.PropertyDeclaration).type?.getText(); this.filterOutDecoratorsDiagnostics(classDecorators, NON_INITIALIZABLE_PROPERTY_CLASS_DECORATORS, @@ -1271,7 +1271,7 @@ export class TypeScriptLinter { private handleRestrictedValues(tsIdentifier: ts.Identifier, tsIdentSym: ts.Symbol) { const illegalValues = ts.SymbolFlags.ConstEnum | ts.SymbolFlags.RegularEnum | ts.SymbolFlags.ValueModule | (TypeScriptLinter.advancedClassChecks? 0 : ts.SymbolFlags.Class); - + // If module name is duplicated by another declaration, this increases the possibility // of finding a lot of false positives. Thus, do not check further in that case. if ((tsIdentSym.flags & ts.SymbolFlags.ValueModule) != 0) { @@ -1305,7 +1305,7 @@ export class TypeScriptLinter { const checkClassOrInterface = tsElemAccessBaseExprType.isClassOrInterface() && !this.tsUtils.isGenericArrayType(tsElemAccessBaseExprType) && - !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); + !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); const checkThisOrSuper = this.tsUtils.isThisOrSuperExpr(tsElementAccessExpr.expression) && !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); @@ -1404,7 +1404,7 @@ export class TypeScriptLinter { this.handleStructIdentAndUndefinedInArgs(tsCallExpr, callSignature); } this.handleLibraryTypeCall(tsCallExpr, calleeType); - + if (ts.isPropertyAccessExpression(tsCallExpr.expression) && this.tsUtils.hasEsObjectType(tsCallExpr.expression.expression)) { this.incrementCounters(node, FaultID.EsObjectAccess); } @@ -1443,8 +1443,8 @@ export class TypeScriptLinter { private handleGenericCallWithNoTypeArgs(callLikeExpr: ts.CallExpression | ts.NewExpression, callSignature: ts.Signature) { // Note: The PR!716 has led to a significant performance degradation. // Since initial problem was fixed in a more general way, this change - // became redundant. Therefore, it was reverted. See #13721 comments - // for a detailed analysis. + // became redundant. Therefore, it was reverted. See #13721 comments + // for a detailed analysis. const tsSyntaxKind = ts.isNewExpression(callLikeExpr) ? ts.SyntaxKind.Constructor : ts.SyntaxKind.FunctionDeclaration; const signFlags = ts.NodeBuilderFlags.WriteTypeArgumentsOfSignature | ts.NodeBuilderFlags.IgnoreErrors; const signDecl = this.tsTypeChecker.signatureToSignatureDeclaration(callSignature, tsSyntaxKind, undefined, signFlags); @@ -1703,9 +1703,12 @@ export class TypeScriptLinter { const commentContent = comment.kind === ts.SyntaxKind.MultiLineCommentTrivia ? srcText.slice(comment.pos + 2, comment.end - 2) : srcText.slice(comment.pos + 2, comment.end); - const trimmedContent = commentContent.trim() + //if comment is multiline end closing '*/' is not at the same line as '@ts-xxx' - do nothing (see #13851) + if (commentContent.endsWith('\n')) + return; + const trimmedContent = commentContent.trim(); if (trimmedContent.startsWith('@ts-ignore') || - trimmedContent.startsWith('@ts-nocheck') || + trimmedContent.startsWith('@ts-nocheck') || trimmedContent.startsWith('@ts-expect-error')) this.incrementCounters(comment, FaultID.ErrorSuppression); } diff --git a/linter/test/ts_ignore.ts.relax.json b/linter/test/ts_ignore.ts.relax.json index d1f517671..787d4b0e1 100644 --- a/linter/test/ts_ignore.ts.relax.json +++ b/linter/test/ts_ignore.ts.relax.json @@ -34,11 +34,6 @@ "column": 9, "problem": "ErrorSuppression" }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" - }, { "line": 43, "column": 9, diff --git a/linter/test/ts_ignore.ts.strict.json b/linter/test/ts_ignore.ts.strict.json index d1f517671..787d4b0e1 100644 --- a/linter/test/ts_ignore.ts.strict.json +++ b/linter/test/ts_ignore.ts.strict.json @@ -34,11 +34,6 @@ "column": 9, "problem": "ErrorSuppression" }, - { - "line": 33, - "column": 2, - "problem": "ErrorSuppression" - }, { "line": 43, "column": 9, -- Gitee