From 353fdda8c00bc14dc7fc13f8b90a1e1d39b63af0 Mon Sep 17 00:00:00 2001 From: Orlovsky Maxim Date: Mon, 21 Aug 2023 13:13:54 +0300 Subject: [PATCH] [linter] Relaxed rule for object literal in struct declaration Signed-off-by: Orlovsky Maxim --- linter-4.2/src/TypeScriptLinter.ts | 11 +++++++++++ linter/src/TypeScriptLinter.ts | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/linter-4.2/src/TypeScriptLinter.ts b/linter-4.2/src/TypeScriptLinter.ts index b1de4c274..b5f624fc9 100644 --- a/linter-4.2/src/TypeScriptLinter.ts +++ b/linter-4.2/src/TypeScriptLinter.ts @@ -447,6 +447,17 @@ export class TypeScriptLinter { if (this.tsUtils.isDestructuringAssignmentLHS(objectLiteralExpr)) return; + // HACK: Relaxing rule for object literal typecheck, if object literal contained in structure + // declaration, than don't process it + // Very unoptimal, but in one place for later removal + let parent = node.parent; + while (parent !== null && parent !== undefined) { + if (LinterConfig.tsSyntaxKindNames[parent.kind] === 'StructDeclaration') { + return; + } + parent = parent.parent; + } + let objectLiteralType = this.tsTypeChecker.getContextualType(objectLiteralExpr); if (!this.tsUtils.areTypesAssignable(objectLiteralType, objectLiteralExpr)) this.incrementCounters(node, FaultID.ObjectLiteralNoContextType); diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index 9c1defffd..73c808a65 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -464,6 +464,17 @@ export class TypeScriptLinter { if (this.tsUtils.isDestructuringAssignmentLHS(objectLiteralExpr)) return; + // HACK: Relaxing rule for object literal typecheck, if object literal contained in structure + // declaration, than don't process it + // Very unoptimal, but in one place for later removal + let parent = node.parent; + while (parent !== null && parent !== undefined) { + if (LinterConfig.tsSyntaxKindNames[parent.kind] === 'StructDeclaration') { + return; + } + parent = parent.parent; + } + let objectLiteralType = this.tsTypeChecker.getContextualType(objectLiteralExpr); if (!this.tsUtils.areTypesAssignable(objectLiteralType, objectLiteralExpr)) this.incrementCounters(node, FaultID.ObjectLiteralNoContextType); -- Gitee