diff --git a/ets2panda/linter/src/cli/LinterCLI.ts b/ets2panda/linter/src/cli/LinterCLI.ts index 447a2358d12e80890328e3fad0331113b17bb781..b0851047c3eadefc9979b370d2ba43bb22941f7b 100644 --- a/ets2panda/linter/src/cli/LinterCLI.ts +++ b/ets2panda/linter/src/cli/LinterCLI.ts @@ -128,6 +128,12 @@ async function executeHomeCheckTask(scanTaskRelatedInfo: ScanTaskRelatedInfo): P migrationTool = null; scanTaskRelatedInfo.homeCheckResult = transferIssues2ProblemInfo(result); for (const [filePath, problems] of scanTaskRelatedInfo.homeCheckResult) { + if ( + !scanTaskRelatedInfo.cmdOptions.scanWholeProjectInHomecheck && + !scanTaskRelatedInfo.cmdOptions.inputFiles.includes(filePath) + ) { + continue; + } if (!scanTaskRelatedInfo.mergedProblems.has(filePath)) { scanTaskRelatedInfo.mergedProblems.set(filePath, []); } diff --git a/ets2panda/linter/src/lib/autofixes/Autofixer.ts b/ets2panda/linter/src/lib/autofixes/Autofixer.ts index 3ef2aba012eaa6e092826910b187dc0c631ba5fe..c321277ede6d057cefdb8d548a49814a3926a8d6 100644 --- a/ets2panda/linter/src/lib/autofixes/Autofixer.ts +++ b/ets2panda/linter/src/lib/autofixes/Autofixer.ts @@ -4739,7 +4739,7 @@ export class Autofixer { return undefined; } - const typeArgs = Autofixer.getTypeArgumentsFromType(contextualType); + const typeArgs = this.getTypeArgumentsFromType(contextualType); if (typeArgs.length === 0) { return undefined; } @@ -5044,8 +5044,8 @@ export class Autofixer { return [{ start: identifier.getEnd(), end: identifier.getEnd(), replacementText: typeArgsText }]; } - static getTypeArgumentsFromType(type: ts.Type): ts.Type[] { - const typeReference = type as ts.TypeReference; + private getTypeArgumentsFromType(type: ts.Type): ts.Type[] { + const typeReference = this.utils.getNonNullableType(type) as ts.TypeReference; if (typeReference.typeArguments) { return [...typeReference.typeArguments]; } diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets index 43830e5da0bb5ebcc71a2d22a9aa1c7dbb308730..173fc2a7abbf7e6d13c3bfc3b1f825505d807bde 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets @@ -121,4 +121,20 @@ let subWeakSet = new SubWeakSet(); class C {} class D {} -let a: D<[C]> = new D(); \ No newline at end of file +let a: D<[C]> = new D(); + +function fun(a?:Map){ + let c:Map|undefined + if(a === undefined){ + a = new Map() + } + if(a){ + a = new Map() + } + if(c){ + c = new Map() + } + if(c === undefined){ + c = new Map() + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json index 788aaf8aaa07a8e20c9a9642e9ba0d7d01b0b6f0..e63b5502e111431a7d73d2411011127753168697 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.arkts2.json @@ -534,6 +534,56 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 127, + "column": 7, + "endLine": 127, + "endColumn": 8, + "problem": "VariableMissingInitializer", + "suggest": "", + "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", + "severity": "ERROR" + }, + { + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json index 6d8c8403ac0826036252dd6b0bec721f33a4fc57..25fbbab8a6e9053c8d941c06301c3aaca60969aa 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.autofix.json @@ -787,6 +787,100 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 127, + "column": 7, + "endLine": 127, + "endColumn": 8, + "problem": "VariableMissingInitializer", + "suggest": "", + "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", + "severity": "ERROR" + }, + { + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3430, + "end": 3430, + "replacementText": "", + "line": 129, + "column": 9, + "endLine": 129, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3461, + "end": 3461, + "replacementText": "", + "line": 132, + "column": 9, + "endLine": 132, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3492, + "end": 3492, + "replacementText": "", + "line": 135, + "column": 9, + "endLine": 135, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, + { + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18, + "problem": "GenericCallNoTypeArgs", + "autofix": [ + { + "start": 3537, + "end": 3537, + "replacementText": "", + "line": 138, + "column": 9, + "endLine": 138, + "endColumn": 18 + } + ], + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", + "severity": "ERROR" + }, { "line": 84, "column": 2, diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets index 3cfe89eaab8d03105a0c493fbe8b206f07520dff..68520df9e2244e5b6b2ca1c43a3e946ad820ccbd 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.ets @@ -128,4 +128,20 @@ let subWeakSet = new SubWeakSet(); class C {} class D {} -let a: D<[C]> = new D<[C]>(); \ No newline at end of file +let a: D<[C]> = new D<[C]>(); + +function fun(a?:Map){ + let c:Map|undefined + if(a === undefined){ + a = new Map() + } + if(a){ + a = new Map() + } + if(c){ + c = new Map() + } + if(c === undefined){ + c = new Map() + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json index 452d9d6225f6f7e27b5814b2af5bde4081f692cc..fb18fc7ef8368cb45045a4d5ff27127add53cf5c 100644 --- a/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json +++ b/ets2panda/linter/test/main/func_inferred_type_args_2.ets.migrate.json @@ -304,6 +304,16 @@ "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)", "severity": "ERROR" }, + { + "line": 134, + "column": 7, + "endLine": 134, + "endColumn": 8, + "problem": "VariableMissingInitializer", + "suggest": "", + "rule": "After a variable is declared, a value must be assigned before using it (arkts-var-assignment-before-use)", + "severity": "ERROR" + }, { "line": 110, "column": 22,