• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 * as arkts from '@koalaui/libarkts';
17import { getAnnotationUsage, PresetDecorators } from '../utils';
18import { UISyntaxRule } from './ui-syntax-rule';
19
20const rule: UISyntaxRule = {
21  name: 'entry-struct-no-export',
22  messages: {
23    noExportWithEntry: `It's not a recommended way to export struct with @Entry decorator, which may cause ACE Engine error in component preview mode.`,
24  },
25  setup(context) {
26    return {
27      parsed: (node): void => {
28        // Check if the current node is a schema declaration
29        if (!arkts.isStructDeclaration(node)) {
30          return;
31        }
32        // Get the usage of the @Entry decorator
33        const entryDecoratorUsage = getAnnotationUsage(
34          node,
35          PresetDecorators.ENTRY,
36        );
37
38        //Determines whether the struct is exported
39        const isExported = node.dumpSrc().includes('export struct');
40
41        // If a @Entry decorator is present and the struct is exported
42        if (entryDecoratorUsage && isExported) {
43          context.report({
44            node: entryDecoratorUsage,
45            message: this.messages.noExportWithEntry,
46          });
47        }
48      },
49    };
50  },
51};
52
53export default rule;