• 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 { GlobMatch } from '../utils/common/GlobMatch';
17
18export class RuleConfig {
19    public files: GlobMatch;
20    public ignore: GlobMatch;
21    public rules: object;
22    public extRules: object;
23    public extRuleSet: object[];
24    public ruleSet: string[];
25    public overrides: RuleConfig[];
26
27    constructor(config: any) {
28        if (config.files && config.files.length > 0) {
29            this.files = new GlobMatch(config.files);
30        } else {
31            this.files = new GlobMatch(['**/*.ets']);
32        }
33        if (config.ignore) {
34            if (config.ignore.length > 0) {
35                this.ignore = new GlobMatch(config.ignore);
36            }
37        } else if (config.excluded && config.excluded.length > 0) {
38            this.ignore = new GlobMatch(config.excluded);
39        }
40        this.rules = config.rules ?? {};
41        this.extRules = config.extRules ?? {};
42        this.extRuleSet = config.extRuleSet ?? [];
43        this.ruleSet = config.ruleSet ?? [];
44
45        if (config.overrides) {
46            let overrides: RuleConfig[] = [];
47            let overRuleConfigs = config.overrides;
48            overRuleConfigs.forEach((overRuleConfig: any) => {
49                overrides.push(new RuleConfig(overRuleConfig));
50            });
51            this.overrides = overrides;
52        } else {
53            this.overrides = [];
54        }
55    }
56}