diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 3328315b274f8e7718d6ed1563ff158f1ef666da..c43dbc874f43e176b5d9909148ac6f1f4ccde0c4 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -80,7 +80,7 @@ import { DEFAULT_DECORATOR_WHITE_LIST } from './utils/consts/DefaultDecoratorWhi import { INVALID_IDENTIFIER_KEYWORDS } from './utils/consts/InValidIndentifierKeywords'; import { WORKER_MODULES, WORKER_TEXT } from './utils/consts/WorkerAPI'; import { COLLECTIONS_TEXT, COLLECTIONS_MODULES } from './utils/consts/CollectionsAPI'; -import { ASON_TEXT, ASON_MODULES, ARKTS_UTILS_TEXT } from './utils/consts/ArkTSUtilsAPI'; +import { ASON_TEXT, ASON_MODULES, ARKTS_UTILS_TEXT, JSON_TEXT, ASON_WHITE_SET } from './utils/consts/ArkTSUtilsAPI'; import { interanlFunction } from './utils/consts/InternalFunction'; import { ETS_PART, PATH_SEPARATOR } from './utils/consts/OhmUrl'; import { @@ -7046,8 +7046,11 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (parent.right.text !== node.text) { return; } - this.checkAsonUsage(parent.left); - + if (ts.isQualifiedName(parent.parent) && ASON_WHITE_SET.has(parent.parent.right.text)) { + this.checkAsonUsage(parent.left, undefined); + } else { + this.checkAsonUsage(parent.left, this.autofixer); + } break; case ts.SyntaxKind.PropertyAccessExpression: if (!ts.isPropertyAccessExpression(parent)) { @@ -7056,20 +7059,25 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { if (parent.name.text !== node.text) { return; } - this.checkAsonUsage(parent.expression); - + if (ts.isPropertyAccessExpression(parent.parent) && ASON_WHITE_SET.has(parent.parent.name.text)) { + this.checkAsonUsage(parent.expression, undefined); + } else { + this.checkAsonUsage(parent.expression, this.autofixer); + } break; default: } } - private checkAsonUsage(nodeToCheck: ts.Node): void { + private checkAsonUsage(nodeToCheck: ts.Node, autofixer: Autofixer | undefined): void { if (!ts.isIdentifier(nodeToCheck)) { return; } + const declaration = this.tsUtils.getDeclarationNode(nodeToCheck); if (!declaration && nodeToCheck.text === ARKTS_UTILS_TEXT) { - this.incrementCounters(nodeToCheck, FaultID.LimitedStdLibNoASON); + const autofix = autofixer?.replaceNode(nodeToCheck.parent, JSON_TEXT); + this.incrementCounters(nodeToCheck, FaultID.LimitedStdLibNoASON, autofix); return; } @@ -7085,7 +7093,8 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return fileName.startsWith(moduleName); }) ) { - this.incrementCounters(nodeToCheck, FaultID.LimitedStdLibNoASON); + const autofix = this.autofixer?.replaceNode(nodeToCheck.parent, JSON_TEXT); + this.incrementCounters(nodeToCheck, FaultID.LimitedStdLibNoASON, autofix); } } diff --git a/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts b/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts index 8218ffc5113110bf9692d2a2f8ec847471e0dc93..e9ca2a1581b4f483a2f4115c35d2c784f9d441cb 100644 --- a/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArkTSUtilsAPI.ts @@ -17,3 +17,5 @@ export const ASON_TEXT = 'ASON'; export const ASON_MODULES = ['@arkts.utils', '@kit.ArkTS']; export const JSON_TEXT = 'JSON'; export const ARKTS_UTILS_TEXT = 'ArkTSUtils'; + +export const ASON_WHITE_SET: Set = new Set(['ParseReturnType']); diff --git a/ets2panda/linter/test/main/arktsutils_module.ets b/ets2panda/linter/test/main/arktsutils_module.ets index 4e81dea82b9caa9f42f8000a32557894ad38463d..a8fbe4b65e5e0ecc29045471c29da4584632c4af 100644 --- a/ets2panda/linter/test/main/arktsutils_module.ets +++ b/ets2panda/linter/test/main/arktsutils_module.ets @@ -35,4 +35,6 @@ function tesCollectionsUsage() { type CreatedType = ArkTSUtils.ASON.SomeType; const someType: CreatedType = ArkTSUtils.ASON.SomeType; + + const map: number = ArkTSUtils.ASON.ParseReturnType.map; } diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json b/ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json index 6da6e6ae1588b4a7791270d2b02b227b7b9cf6eb..30c0ecdc72049b06d77ad84ec14d418e9c70e2a9 100644 --- a/ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json +++ b/ets2panda/linter/test/main/arktsutils_module.ets.arkts2.json @@ -113,6 +113,16 @@ "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" + }, + { + "line": 39, + "column": 23, + "endLine": 39, + "endColumn": 33, + "problem": "LimitedStdLibNoASON", + "suggest": "", + "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", + "severity": "ERROR" } ] } diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.autofix.json b/ets2panda/linter/test/main/arktsutils_module.ets.autofix.json index d6868a9cbf4f513be46a17011c04913690564267..9f6d6e0d9c33764ee0b9dea4913c4f62bf537ade 100644 --- a/ets2panda/linter/test/main/arktsutils_module.ets.autofix.json +++ b/ets2panda/linter/test/main/arktsutils_module.ets.autofix.json @@ -20,6 +20,17 @@ "endLine": 27, "endColumn": 31, "problem": "LimitedStdLibNoASON", + "autofix": [ + { + "start": 980, + "end": 990, + "replacementText": "JSON", + "line": 27, + "column": 26, + "endLine": 27, + "endColumn": 31 + } + ], "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" @@ -51,6 +62,17 @@ "endLine": 29, "endColumn": 33, "problem": "LimitedStdLibNoASON", + "autofix": [ + { + "start": 1023, + "end": 1043, + "replacementText": "JSON", + "line": 29, + "column": 18, + "endLine": 29, + "endColumn": 33 + } + ], "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" @@ -82,6 +104,17 @@ "endLine": 31, "endColumn": 31, "problem": "LimitedStdLibNoASON", + "autofix": [ + { + "start": 1076, + "end": 1094, + "replacementText": "JSON", + "line": 31, + "column": 18, + "endLine": 31, + "endColumn": 31 + } + ], "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" @@ -113,6 +146,17 @@ "endLine": 33, "endColumn": 41, "problem": "LimitedStdLibNoASON", + "autofix": [ + { + "start": 1135, + "end": 1155, + "replacementText": "JSON", + "line": 33, + "column": 26, + "endLine": 33, + "endColumn": 41 + } + ], "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" @@ -144,6 +188,17 @@ "endLine": 35, "endColumn": 32, "problem": "LimitedStdLibNoASON", + "autofix": [ + { + "start": 1192, + "end": 1207, + "replacementText": "JSON", + "line": 35, + "column": 22, + "endLine": 35, + "endColumn": 32 + } + ], "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" @@ -154,6 +209,27 @@ "endLine": 37, "endColumn": 43, "problem": "LimitedStdLibNoASON", + "autofix": [ + { + "start": 1251, + "end": 1266, + "replacementText": "JSON", + "line": 37, + "column": 33, + "endLine": 37, + "endColumn": 43 + } + ], + "suggest": "", + "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", + "severity": "ERROR" + }, + { + "line": 39, + "column": 23, + "endLine": 39, + "endColumn": 33, + "problem": "LimitedStdLibNoASON", "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.migrate.ets b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.ets index 3b1d7e17b6e5f116f3051c61fe671e0dee13327e..32dc4cb60d06fb646cd27d3f0296a2fe3af5171b 100644 --- a/ets2panda/linter/test/main/arktsutils_module.ets.migrate.ets +++ b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.ets @@ -24,15 +24,17 @@ export { utils } from './oh_modules/@arkts.utils'; function tesCollectionsUsage() { - const utils1: string = utils.ASON.stringify(1.0); + const utils1: string = JSON.stringify(1.0); - const utils2 = ArkTSUtilsAlias.ASON.stringify(1.0); + const utils2 = JSON.stringify(1.0); - const utils3 = kitArkTSUtils.ASON.stringify(1.0); + const utils3 = JSON.stringify(1.0); - const utils4: string = ArkTSUtilsAlias.ASON.stringify(1.0); + const utils4: string = JSON.stringify(1.0); - type CreatedType = ArkTSUtils.ASON.SomeType; + type CreatedType = JSON.SomeType; - const someType: CreatedType = ArkTSUtils.ASON.SomeType; + const someType: CreatedType = JSON.SomeType; + + const map: number = ArkTSUtils.ASON.ParseReturnType.map; } diff --git a/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json index 1b597eff5b8579d13d203bafc99002f5f4b2ce85..f4bff9a11a16c98100be050b6ab0e11336c78549 100644 --- a/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json +++ b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json @@ -15,64 +15,14 @@ ], "result": [ { - "line": 27, - "column": 26, - "endLine": 27, - "endColumn": 31, - "problem": "LimitedStdLibNoASON", - "suggest": "", - "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", - "severity": "ERROR" - }, - { - "line": 29, - "column": 18, - "endLine": 29, + "line": 39, + "column": 23, + "endLine": 39, "endColumn": 33, "problem": "LimitedStdLibNoASON", "suggest": "", "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", "severity": "ERROR" - }, - { - "line": 31, - "column": 18, - "endLine": 31, - "endColumn": 31, - "problem": "LimitedStdLibNoASON", - "suggest": "", - "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", - "severity": "ERROR" - }, - { - "line": 33, - "column": 26, - "endLine": 33, - "endColumn": 41, - "problem": "LimitedStdLibNoASON", - "suggest": "", - "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", - "severity": "ERROR" - }, - { - "line": 35, - "column": 22, - "endLine": 35, - "endColumn": 32, - "problem": "LimitedStdLibNoASON", - "suggest": "", - "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", - "severity": "ERROR" - }, - { - "line": 37, - "column": 33, - "endLine": 37, - "endColumn": 43, - "problem": "LimitedStdLibNoASON", - "suggest": "", - "rule": "ASON is not supported. (arkts-no-need-stdlib-ason)", - "severity": "ERROR" } ] }