diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 4b72c290e05d73733982df18ff0bd274c0acbbdd..00b6bcfc0c4f0dec81528c767947bb1eb2423064 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 { @@ -7065,8 +7065,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, true); + } else { + this.checkAsonUsage(parent.left, false); + } break; case ts.SyntaxKind.PropertyAccessExpression: if (!ts.isPropertyAccessExpression(parent)) { @@ -7075,20 +7078,27 @@ 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, true); + } else { + this.checkAsonUsage(parent.expression, false); + } break; default: } } - private checkAsonUsage(nodeToCheck: ts.Node): void { + private checkAsonUsage(nodeToCheck: ts.Node, needAutofix: boolean): 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 = (needAutofix && this.autofixer) ? + this.autofixer.replaceNode(nodeToCheck.parent, JSON_TEXT) : + undefined; + this.incrementCounters(nodeToCheck, FaultID.LimitedStdLibNoASON, autofix); return; } @@ -7104,7 +7114,10 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return fileName.startsWith(moduleName); }) ) { - this.incrementCounters(nodeToCheck, FaultID.LimitedStdLibNoASON); + const autofix = (needAutofix && this.autofixer) ? + this.autofixer.replaceNode(nodeToCheck.parent, JSON_TEXT) : + undefined; + 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..bae5dc65cc4e7b65fd607f7142fcd376411b217d 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(['stringify']); 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..bb4f5f6610bee78fe73dbd965ea29822ece7213e 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" @@ -157,6 +201,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.migrate.ets b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.ets index 3b1d7e17b6e5f116f3051c61fe671e0dee13327e..5dc1d2c5c20b4c35d42c78d51ede0c60612106fd 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; const someType: CreatedType = ArkTSUtils.ASON.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..a3e735670a47e1abef69d029c41ae952cb0394ec 100644 --- a/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json +++ b/ets2panda/linter/test/main/arktsutils_module.ets.migrate.json @@ -14,46 +14,6 @@ "limitations under the License." ], "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, - "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, @@ -73,6 +33,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" } ] }