diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index 863cd0542ee6538239eb3a0b81042fa373a3d206..f9d81f9317b599a35160beab5646d9ebf1afdd4f 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -50,6 +50,7 @@ import { ReportAutofixCallback } from './autofixes/ReportAutofixCallback'; import { DiagnosticChecker } from './utils/functions/DiagnosticChecker'; import { ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE, + NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE, TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE, LibraryTypeCallDiagnosticChecker } from './utils/functions/LibraryTypeCallDiagnosticChecker'; @@ -1566,6 +1567,9 @@ export class TypeScriptLinter { [ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE]: (pos: number) => { return this.checkInRange(rangesToFilter, pos); }, + [NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE]: (pos: number) => { + return this.checkInRange([{begin: callExpr.pos, end: callExpr.end}], pos); + }, [TYPE_0_IS_NOT_ASSIGNABLE_TO_TYPE_1_ERROR_CODE]: (pos: number) => { return this.checkInRange(rangesToFilter, pos); } diff --git a/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts b/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts index 72778922bfed4c2efc5e60cb04287f342e8344f2..3adf03b3e315c490b1b6616fadf7179ce5aa5d98 100644 --- a/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts +++ b/linter/src/utils/functions/LibraryTypeCallDiagnosticChecker.ts @@ -24,6 +24,7 @@ export const TYPE_NULL_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = /^Type 'null' is not ass export const TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_TYPE_1_RE = /^Type 'undefined' is not assignable to type '.*'\.$/; export const ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE = 2345; +export const NO_OVERLOAD_MATCHES_THIS_CALL_ERROR_CODE = 2769; export const ARGUMENT_OF_TYPE_NULL_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE = /^Argument of type 'null' is not assignable to parameter of type '.*'\.$/; export const ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE = /^Argument of type 'undefined' is not assignable to parameter of type '.*'\.$/; @@ -64,6 +65,14 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { return false; } } + if (chain.code == ARGUMENT_OF_TYPE_0_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_ERROR_CODE) { + if (this.inLibCall && chain.messageText.match(ARGUMENT_OF_TYPE_UNDEFINED_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE)) { + return false; + } + if (this.inLibCall && chain.messageText.match(ARGUMENT_OF_TYPE_NULL_IS_NOT_ASSIGNABLE_TO_PARAMETER_OF_TYPE_1_RE)) { + return false; + } + } return chain.next == undefined ? true : this.checkMessageChain(chain.next[0]); }; diff --git a/linter/test/null_check_calls.ts.relax.json b/linter/test/null_check_calls.ts.relax.json index 8d879ca4223e2bce2d0709c852246dd3ad3ab734..dda25acbfec4d84cec0fc79719420f95ed456b73 100644 --- a/linter/test/null_check_calls.ts.relax.json +++ b/linter/test/null_check_calls.ts.relax.json @@ -14,30 +14,33 @@ "limitations under the License." ], "nodes": [ - { - "line": 33, - "column": 12, - "problem": "StrictDiagnostic" - }, { "line": 37, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'number[]'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'number[]'." }, { "line": 42, "column": 20, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'number'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'number'." }, { "line": 43, "column": 42, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'.", + "rule": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'." }, { "line": 47, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'.", + "rule": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'." }, { "line": 52, diff --git a/linter/test/null_check_calls.ts.strict.json b/linter/test/null_check_calls.ts.strict.json index fef4e06af40b279782d379965a669bfdb2bdbf71..6ae1263ea8889c0434cf633704ca2787dddc5c9f 100644 --- a/linter/test/null_check_calls.ts.strict.json +++ b/linter/test/null_check_calls.ts.strict.json @@ -17,32 +17,37 @@ { "line": 43, "column": 1, - "problem": "LimitedReturnTypeInference" - }, - { - "line": 33, - "column": 12, - "problem": "StrictDiagnostic" + "problem": "LimitedReturnTypeInference", + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" }, { "line": 37, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'number[]'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'number[]'." }, { "line": 42, "column": 20, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'null' is not assignable to parameter of type 'number'.", + "rule": "Argument of type 'null' is not assignable to parameter of type 'number'." }, { "line": 43, "column": 42, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'.", + "rule": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'." }, { "line": 47, "column": 5, - "problem": "StrictDiagnostic" + "problem": "StrictDiagnostic", + "suggest": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'.", + "rule": "Argument of type 'number | null' is not assignable to parameter of type 'number'.\n Type 'null' is not assignable to type 'number'." }, { "line": 52, diff --git a/linter/test/undefined_check_calls.ts.relax.json b/linter/test/undefined_check_calls.ts.relax.json index 33bf02fda0a29ea9c00dd44708ba54fe03e202a3..21f9e86912824a3b0262300c1ecf7d222a815994 100644 --- a/linter/test/undefined_check_calls.ts.relax.json +++ b/linter/test/undefined_check_calls.ts.relax.json @@ -14,13 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 33, - "column": 12, - "problem": "StrictDiagnostic", - "suggest": "No overload matches this call.\n Overload 1 of 2, '(func: Function, ...args: unknown[]): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'Function'.\n Overload 2 of 2, '(group: TaskGroup, priority?: Priority | undefined): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'TaskGroup'.", - "rule": "No overload matches this call.\n Overload 1 of 2, '(func: Function, ...args: unknown[]): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'Function'.\n Overload 2 of 2, '(group: TaskGroup, priority?: Priority | undefined): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'TaskGroup'." - }, { "line": 37, "column": 5, diff --git a/linter/test/undefined_check_calls.ts.strict.json b/linter/test/undefined_check_calls.ts.strict.json index 33bf02fda0a29ea9c00dd44708ba54fe03e202a3..21f9e86912824a3b0262300c1ecf7d222a815994 100644 --- a/linter/test/undefined_check_calls.ts.strict.json +++ b/linter/test/undefined_check_calls.ts.strict.json @@ -14,13 +14,6 @@ "limitations under the License." ], "nodes": [ - { - "line": 33, - "column": 12, - "problem": "StrictDiagnostic", - "suggest": "No overload matches this call.\n Overload 1 of 2, '(func: Function, ...args: unknown[]): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'Function'.\n Overload 2 of 2, '(group: TaskGroup, priority?: Priority | undefined): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'TaskGroup'.", - "rule": "No overload matches this call.\n Overload 1 of 2, '(func: Function, ...args: unknown[]): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'Function'.\n Overload 2 of 2, '(group: TaskGroup, priority?: Priority | undefined): Promise', gave the following error.\n Argument of type 'undefined' is not assignable to parameter of type 'TaskGroup'." - }, { "line": 37, "column": 5,