diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 309d60b1b1ac29304927e5896612d666041add46..d5700efe95367d2fc4118311f32f27eb84a27b1d 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -7795,16 +7795,27 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return; } - // check if any argument is a `new` expression - const hasNewExpressionArg = callExpr.arguments.some((arg) => { - return ts.isNewExpression(arg); + callExpr.arguments.forEach((arg) => { + const type = this.tsTypeChecker.getTypeAtLocation(arg); + if (ts.isArrowFunction(arg)) { + this.incrementCounters(arg, FaultID.InteropJsObjectCallStaticFunc); + } else if (ts.isIdentifier(arg)) { + const sym = this.tsTypeChecker.getSymbolAtLocation(arg); + const decl = sym?.declarations?.[0]; + if ( + decl && + (ts.isFunctionDeclaration(decl) || + ts.isVariableDeclaration(decl) && decl.initializer && ts.isArrowFunction(decl.initializer)) + ) { + this.incrementCounters(arg, FaultID.InteropJsObjectCallStaticFunc); + } + if (type?.isClassOrInterface()) { + this.incrementCounters(arg, FaultID.InteropJsObjectExpandStaticInstance); + } + } else if (ts.isObjectLiteralExpression(arg) || type?.isClassOrInterface()) { + this.incrementCounters(arg, FaultID.InteropJsObjectExpandStaticInstance); + } }); - - const faultId = hasNewExpressionArg ? - FaultID.InteropJsObjectExpandStaticInstance : - FaultID.InteropJsObjectCallStaticFunc; - - this.incrementCounters(callExpr, faultId); } private fixJsImportExtendsClass( diff --git a/ets2panda/linter/test/interop/call_function.ets.arkts2.json b/ets2panda/linter/test/interop/call_function.ets.arkts2.json index 75b5fe5523b8596a04cdb184e1b73bcb3fb72679..ed940011235b6ccb492d75ad97bafe0ec9ff7cdd 100644 --- a/ets2panda/linter/test/interop/call_function.ets.arkts2.json +++ b/ets2panda/linter/test/interop/call_function.ets.arkts2.json @@ -34,16 +34,6 @@ "rule": "Importing directly from \"JS\" module is not supported (arkts-interop-js2s-import-js)", "severity": "ERROR" }, - { - "line": 18, - "column": 1, - "endLine": 18, - "endColumn": 6, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 18, "column": 1, @@ -54,16 +44,6 @@ "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", "severity": "ERROR" }, - { - "line": 19, - "column": 1, - "endLine": 19, - "endColumn": 9, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 19, "column": 1, diff --git a/ets2panda/linter/test/interop/call_object_methods.ets.arkts2.json b/ets2panda/linter/test/interop/call_object_methods.ets.arkts2.json index 08caa2a29e9cd2a4c445e1140152e08aeed29fc5..d088101b49fff0479cfefc0586220ee0b8fbc083 100644 --- a/ets2panda/linter/test/interop/call_object_methods.ets.arkts2.json +++ b/ets2panda/linter/test/interop/call_object_methods.ets.arkts2.json @@ -34,16 +34,6 @@ "rule": "Importing directly from \"JS\" module is not supported (arkts-interop-js2s-import-js)", "severity": "ERROR" }, - { - "line": 18, - "column": 1, - "endLine": 18, - "endColumn": 13, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 18, "column": 1, diff --git a/ets2panda/linter/test/interop/call_object_methods.ets.autofix.json b/ets2panda/linter/test/interop/call_object_methods.ets.autofix.json index 5b9ab33651dce29197a58e836b3b0da56a91c806..7a42f85097961d7260b20bccb9ae92f098f20bf2 100644 --- a/ets2panda/linter/test/interop/call_object_methods.ets.autofix.json +++ b/ets2panda/linter/test/interop/call_object_methods.ets.autofix.json @@ -54,16 +54,6 @@ "rule": "Importing directly from \"JS\" module is not supported (arkts-interop-js2s-import-js)", "severity": "ERROR" }, - { - "line": 18, - "column": 1, - "endLine": 18, - "endColumn": 13, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 18, "column": 1, diff --git a/ets2panda/linter/test/interop/interop_import_js_rules.ets b/ets2panda/linter/test/interop/interop_import_js_rules.ets index 3b88109fc29630d3e6a092967366596f836c6936..38872997a7b4bd8a6ccd03780de58a31cc9757a8 100644 --- a/ets2panda/linter/test/interop/interop_import_js_rules.ets +++ b/ets2panda/linter/test/interop/interop_import_js_rules.ets @@ -65,3 +65,13 @@ handle(lambda) class X{a = 1; b= 2; c= 3} expand(new X()) // ERROR expand-static +class Y { + str: string = 'str'; + bool: boolean = false; +} +let testY: Y = { + str: "hello", + bool: false, +} +expand(testY); +expand({x: '1', y: "hello", z: false}); \ No newline at end of file diff --git a/ets2panda/linter/test/interop/interop_import_js_rules.ets.arkts2.json b/ets2panda/linter/test/interop/interop_import_js_rules.ets.arkts2.json index eb568c3a7ca351a70a508b37ab0cbed3ce539b5c..d08c71268340d4fb3ac97ce6b146f26848f76f73 100644 --- a/ets2panda/linter/test/interop/interop_import_js_rules.ets.arkts2.json +++ b/ets2panda/linter/test/interop/interop_import_js_rules.ets.arkts2.json @@ -264,16 +264,6 @@ "rule": "Trying to catch JS errors is not permitted (arkts-interop-js2s-js-exception)", "severity": "ERROR" }, - { - "line": 44, - "column": 3, - "endLine": 44, - "endColumn": 8, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 44, "column": 3, @@ -416,9 +406,9 @@ }, { "line": 63, - "column": 1, + "column": 8, "endLine": 63, - "endColumn": 13, + "endColumn": 12, "problem": "InteropJsObjectCallStaticFunc", "suggest": "", "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", @@ -436,9 +426,9 @@ }, { "line": 64, - "column": 1, + "column": 8, "endLine": 64, - "endColumn": 15, + "endColumn": 14, "problem": "InteropJsObjectCallStaticFunc", "suggest": "", "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", @@ -516,9 +506,9 @@ }, { "line": 67, - "column": 1, + "column": 8, "endLine": 67, - "endColumn": 16, + "endColumn": 15, "problem": "InteropJsObjectExpandStaticInstance", "suggest": "", "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)", @@ -533,6 +523,46 @@ "suggest": "", "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", "severity": "ERROR" + }, + { + "line": 76, + "column": 8, + "endLine": 76, + "endColumn": 13, + "problem": "InteropJsObjectExpandStaticInstance", + "suggest": "", + "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)", + "severity": "ERROR" + }, + { + "line": 76, + "column": 1, + "endLine": 76, + "endColumn": 14, + "problem": "CallJSFunction", + "suggest": "", + "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", + "severity": "ERROR" + }, + { + "line": 77, + "column": 8, + "endLine": 77, + "endColumn": 38, + "problem": "InteropJsObjectExpandStaticInstance", + "suggest": "", + "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)", + "severity": "ERROR" + }, + { + "line": 77, + "column": 1, + "endLine": 77, + "endColumn": 39, + "problem": "CallJSFunction", + "suggest": "", + "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", + "severity": "ERROR" } ] } diff --git a/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json b/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json index b9eb9db8fbb2ab9457af147d76e03b275f98b0dd..a8f273bd7d1e0e0735f2476ce18c3cfb6a7e0048 100644 --- a/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json +++ b/ets2panda/linter/test/interop/interop_import_js_rules.ets.autofix.json @@ -479,16 +479,6 @@ "rule": "Trying to catch JS errors is not permitted (arkts-interop-js2s-js-exception)", "severity": "ERROR" }, - { - "line": 44, - "column": 3, - "endLine": 44, - "endColumn": 8, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 44, "column": 3, @@ -741,9 +731,9 @@ }, { "line": 63, - "column": 1, + "column": 8, "endLine": 63, - "endColumn": 13, + "endColumn": 12, "problem": "InteropJsObjectCallStaticFunc", "suggest": "", "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", @@ -761,9 +751,9 @@ }, { "line": 64, - "column": 1, + "column": 8, "endLine": 64, - "endColumn": 15, + "endColumn": 14, "problem": "InteropJsObjectCallStaticFunc", "suggest": "", "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", @@ -907,9 +897,9 @@ }, { "line": 67, - "column": 1, + "column": 8, "endLine": 67, - "endColumn": 16, + "endColumn": 15, "problem": "InteropJsObjectExpandStaticInstance", "suggest": "", "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)", @@ -924,6 +914,46 @@ "suggest": "", "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", "severity": "ERROR" + }, + { + "line": 76, + "column": 8, + "endLine": 76, + "endColumn": 13, + "problem": "InteropJsObjectExpandStaticInstance", + "suggest": "", + "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)", + "severity": "ERROR" + }, + { + "line": 76, + "column": 1, + "endLine": 76, + "endColumn": 14, + "problem": "CallJSFunction", + "suggest": "", + "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", + "severity": "ERROR" + }, + { + "line": 77, + "column": 8, + "endLine": 77, + "endColumn": 38, + "problem": "InteropJsObjectExpandStaticInstance", + "suggest": "", + "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-expand-static-instance)", + "severity": "ERROR" + }, + { + "line": 77, + "column": 1, + "endLine": 77, + "endColumn": 39, + "problem": "CallJSFunction", + "suggest": "", + "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", + "severity": "ERROR" } ] } diff --git a/ets2panda/linter/test/interop/interop_import_typeof_js.ets.arkts2.json b/ets2panda/linter/test/interop/interop_import_typeof_js.ets.arkts2.json index 0689065be94d05900a62fa395381b6fc841334e0..454dd0994b68102be3168fb72b02178a3c64e1e4 100755 --- a/ets2panda/linter/test/interop/interop_import_typeof_js.ets.arkts2.json +++ b/ets2panda/linter/test/interop/interop_import_typeof_js.ets.arkts2.json @@ -84,16 +84,6 @@ "rule": "The \"typeof\" expression can't be used with interop JS objects (arkts-interop-js2s-typeof-js-type)", "severity": "ERROR" }, - { - "line": 21, - "column": 8, - "endLine": 21, - "endColumn": 15, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 21, "column": 8, @@ -104,16 +94,6 @@ "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", "severity": "ERROR" }, - { - "line": 22, - "column": 11, - "endLine": 22, - "endColumn": 18, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 22, "column": 11, @@ -154,16 +134,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 25, - "column": 8, - "endLine": 25, - "endColumn": 19, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 25, "column": 8, @@ -194,16 +164,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 26, - "column": 8, - "endLine": 26, - "endColumn": 20, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 26, "column": 8, @@ -554,16 +514,6 @@ "rule": "The \"typeof\" expression can't be used with interop JS objects (arkts-interop-js2s-typeof-js-type)", "severity": "ERROR" }, - { - "line": 72, - "column": 8, - "endLine": 72, - "endColumn": 30, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 72, "column": 8, @@ -604,16 +554,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 73, - "column": 8, - "endLine": 73, - "endColumn": 31, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 73, "column": 8, diff --git a/ets2panda/linter/test/interop/interop_import_typeof_js.ets.autofix.json b/ets2panda/linter/test/interop/interop_import_typeof_js.ets.autofix.json index c18bdee1768febce019f79e85387b56ff2ea858e..afe18d8b10deb365932b324ccc0f60039b715a65 100755 --- a/ets2panda/linter/test/interop/interop_import_typeof_js.ets.autofix.json +++ b/ets2panda/linter/test/interop/interop_import_typeof_js.ets.autofix.json @@ -155,16 +155,6 @@ "rule": "The \"typeof\" expression can't be used with interop JS objects (arkts-interop-js2s-typeof-js-type)", "severity": "ERROR" }, - { - "line": 21, - "column": 8, - "endLine": 21, - "endColumn": 15, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 21, "column": 8, @@ -175,16 +165,6 @@ "rule": "ArkTS directly call JS functions or parameters is not supported (arkts-interop-js2s-call-js-func)", "severity": "ERROR" }, - { - "line": 22, - "column": 11, - "endLine": 22, - "endColumn": 18, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 22, "column": 11, @@ -247,16 +227,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 25, - "column": 8, - "endLine": 25, - "endColumn": 19, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 25, "column": 8, @@ -298,16 +268,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 26, - "column": 8, - "endLine": 26, - "endColumn": 20, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 26, "column": 8, @@ -955,16 +915,6 @@ "rule": "The \"typeof\" expression can't be used with interop JS objects (arkts-interop-js2s-typeof-js-type)", "severity": "ERROR" }, - { - "line": 72, - "column": 8, - "endLine": 72, - "endColumn": 30, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 72, "column": 8, @@ -1027,16 +977,6 @@ "rule": "Type \"void\" has no instances.(arkts-limited-void-type)", "severity": "ERROR" }, - { - "line": 73, - "column": 8, - "endLine": 73, - "endColumn": 31, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 73, "column": 8, diff --git a/ets2panda/linter/test/interop/no_await_js_promise.ets.arkts2.json b/ets2panda/linter/test/interop/no_await_js_promise.ets.arkts2.json index 54dff3eb9234b3f09d0902f6ebbac8ea91691542..5021d02c431e482be957465ba47d4f742f95d3f9 100755 --- a/ets2panda/linter/test/interop/no_await_js_promise.ets.arkts2.json +++ b/ets2panda/linter/test/interop/no_await_js_promise.ets.arkts2.json @@ -54,16 +54,6 @@ "rule": "\"Await\" operator can't be used with interop objects (arkts-interop-js2s-await-js-promise)", "severity": "ERROR" }, - { - "line": 24, - "column": 16, - "endLine": 24, - "endColumn": 21, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 24, "column": 16, @@ -94,16 +84,6 @@ "rule": "\"Await\" operator can't be used with interop objects (arkts-interop-js2s-await-js-promise)", "severity": "ERROR" }, - { - "line": 32, - "column": 16, - "endLine": 32, - "endColumn": 27, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 32, "column": 16, @@ -184,16 +164,6 @@ "rule": "\"Await\" operator can't be used with interop objects (arkts-interop-js2s-await-js-promise)", "severity": "ERROR" }, - { - "line": 55, - "column": 18, - "endLine": 55, - "endColumn": 23, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 55, "column": 18, @@ -234,16 +204,6 @@ "rule": "\"Await\" operator can't be used with interop objects (arkts-interop-js2s-await-js-promise)", "severity": "ERROR" }, - { - "line": 64, - "column": 43, - "endLine": 64, - "endColumn": 54, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 64, "column": 43, diff --git a/ets2panda/linter/test/interop/no_js_instanceof.ets.arkts2.json b/ets2panda/linter/test/interop/no_js_instanceof.ets.arkts2.json index 7f34d1cc41501add68494e07069933e98c42e852..6df8274a39d62c37566cf9b8edf5c37ddb4e0d16 100755 --- a/ets2panda/linter/test/interop/no_js_instanceof.ets.arkts2.json +++ b/ets2panda/linter/test/interop/no_js_instanceof.ets.arkts2.json @@ -64,16 +64,6 @@ "rule": "Usage of \"instanceof\" operator is not allowed with interop objects (arkts-interop-js2s-instanceof-js-type)", "severity": "ERROR" }, - { - "line": 39, - "column": 28, - "endLine": 39, - "endColumn": 50, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 39, "column": 28, @@ -154,16 +144,6 @@ "rule": "Usage of \"instanceof\" operator is not allowed with interop objects (arkts-interop-js2s-instanceof-js-type)", "severity": "ERROR" }, - { - "line": 69, - "column": 4, - "endLine": 69, - "endColumn": 7, - "problem": "InteropJsObjectCallStaticFunc", - "suggest": "", - "rule": "Direct usage of interop JS functions is not supported (arkts-interop-js2s-js-call-static-function)", - "severity": "ERROR" - }, { "line": 69, "column": 4,