• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 - 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Logger, { LOG_MODULE_TYPE } from 'arkanalyzer/lib/utils/logger';
17import { ObservedDecoratorCheck } from '../../checker/migration/ObservedDecoratorCheck';
18import { ThisBindCheck } from '../../checker/migration/ThisBindCheck';
19import { ObjectLiteralCheck } from '../../checker/migration/ObjectLiteralCheck';
20import { AppStorageGetCheck } from '../../checker/migration/AppStorageGetCheck';
21import { ModifyStateVarCheck } from '../../checker/migration/ModifyStateVarCheck';
22import { NoMethodOverridingFieldCheck } from '../../checker/migration/NoMethodOverridingFieldCheck';
23import { CustomBuilderCheck } from '../../checker/migration/CustomBuilderCheck';
24import { InteropBackwardDFACheck } from '../../checker/migration/InteropBackwardDFACheck';
25import { InteropBoxedTypeCheck } from '../../checker/migration/InteropBoxedTypeCheck';
26import { InteropObjectLiteralCheck } from '../../checker/migration/InteropDynamicObjectLiteralsCheck';
27import { InteropAssignCheck } from '../../checker/migration/InteropAssignCheck';
28import { InteropJSModifyPropertyCheck } from '../../checker/migration/InteropJSModifyPropertyCheck';
29import { NoTSLikeAsCheck } from '../../checker/migration/NoTSLikeAsCheck';
30import { InteropS2DObjectLiteralCheck } from '../../checker/migration/InteropS2DObjectLiteralsCheck';
31import { InteropDeprecatedBuiltInAPICheck } from '../../checker/migration/InteropDeprecatedBuiltInAPICheck';
32
33const logger = Logger.getLogger(LOG_MODULE_TYPE.HOMECHECK, 'CheckerIndex');
34
35export const fileRules = {
36    '@migration/arkts-instance-method-bind-this': ThisBindCheck,
37    '@migration/arkui-data-observation': ObservedDecoratorCheck,
38    '@migration/arkui-stateful-appstorage': AppStorageGetCheck,
39    '@migration/arkui-no-update-in-build': ModifyStateVarCheck,
40    '@migration/arkui-custombuilder-passing': CustomBuilderCheck,
41    '@migration/no-method-overriding-field-check': NoMethodOverridingFieldCheck,
42    '@migration/interop-boxed-type-check': InteropBoxedTypeCheck,
43    '@migration/arkts-interop-s2d-object-literal': InteropS2DObjectLiteralCheck,
44};
45
46export const projectRules = {
47    '@migration/arkts-obj-literal-generate-class-instance': ObjectLiteralCheck,
48    '@migration/interop-backward-dfa': InteropBackwardDFACheck,
49    '@migration/interop-assign': InteropAssignCheck,
50    '@migration/interop-js-modify-property': InteropJSModifyPropertyCheck,
51    '@migration/interop-dynamic-object-literals': InteropObjectLiteralCheck,
52    '@migration/arkts-no-ts-like-as': NoTSLikeAsCheck,
53    '@migration/arkts-interop-s2d-dynamic-call-builtin-api-not-in-static': InteropDeprecatedBuiltInAPICheck,
54};
55
56// 新增文件级的checker,需要在此处注册
57export const file2CheckRuleMap: Map<string, any> = new Map(Object.entries(fileRules));
58// 新增项目级checker,需要在此处注册
59export const project2CheckRuleMap: Map<string, any> = new Map(Object.entries(projectRules));
60
61export class ProxyChecker {
62    static getClass(ruleId: string): any {
63        const checker = file2CheckRuleMap.get(ruleId) ?? project2CheckRuleMap.get(ruleId);
64        if (!checker) {
65            logger.error(`${ruleId} is not matched to any checker`);
66            return null;
67        }
68        return new checker();
69    }
70}
71