diff --git a/ets2panda/linter/src/lib/TypeScriptLinter.ts b/ets2panda/linter/src/lib/TypeScriptLinter.ts index 84b5a362bffd31b3599d67e33eaa79e5b47b21d1..23d5cb90c5934b3801fc5b113bc19fe3a08aee14 100644 --- a/ets2panda/linter/src/lib/TypeScriptLinter.ts +++ b/ets2panda/linter/src/lib/TypeScriptLinter.ts @@ -103,7 +103,8 @@ import { PropDecoratorName, PropFunctionName, StorageTypeName, - customLayoutFunctionName + customLayoutFunctionName, + sdkFileName } from './utils/consts/ArkuiConstants'; import { arkuiImportList } from './utils/consts/ArkuiImportList'; import type { IdentifierAndArguments, ForbidenAPICheckResult } from './utils/consts/InteropAPI'; @@ -146,6 +147,7 @@ import { globalApiAssociatedInfo } from './utils/consts/AssociatedInfo'; import { ARRAY_API_LIST } from './utils/consts/ArraysAPI'; import { ERROR_PROP_LIST } from './utils/consts/ErrorProp'; import { D_ETS, D_TS } from './utils/consts/TsSuffix'; +import { STANDARD_LIBRARIES } from './utils/consts/StandardLibraries' interface InterfaceSymbolTypeResult { propNames: string[]; @@ -7293,9 +7295,9 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { private shouldSkipIdentifier(identifier: ts.Identifier): boolean { const name = identifier.getText(); - if (!arkuiImportList.has(name)) { - return true; - } + // if (!arkuiImportList.has(name)) { + // return true; + // } if (skipImportDecoratorName.has(name)) { return true; @@ -7318,7 +7320,7 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { } } - if (this.isDeclarationInSameFile(identifier)) { + if (this.isDeclOutsideTargetFile(identifier)) { return true; } @@ -7336,6 +7338,23 @@ export class TypeScriptLinter extends BaseTypeScriptLinter { return undefined; } + private isDeclOutsideTargetFile(node: ts.Node): boolean { + const symbol = this.tsTypeChecker.getSymbolAtLocation(node); + // console.log(`${node.getText()}` + ": " + symbol === undefined); + const decl = TsUtils.getDeclaration(symbol); + const file = decl?.getSourceFile(); + if (file !== undefined) { + const fileName = path.basename(file.fileName); + console.log(`${node.getText()} : ${fileName}`); + if (!sdkFileName.has(fileName) && !STANDARD_LIBRARIES.includes(fileName)) { + return true; + } + } else { + console.log(`${node.getText()} : undefined`); + } + return false; + } + private isDeclarationInSameFile(node: ts.Node): boolean { const symbol = this.tsTypeChecker.getSymbolAtLocation(node); const decl = TsUtils.getDeclaration(symbol); diff --git a/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts b/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts index 5405ffe91fbad020ed6821eed61444cea308736f..3a86ab2e7b782a9936d6ba7602191734c20a7fa3 100644 --- a/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts +++ b/ets2panda/linter/src/lib/utils/consts/ArkuiConstants.ts @@ -78,6 +78,146 @@ export const skipImportDecoratorName: Set = new Set([ 'LocalStorageProp' ]); +export const sdkFileName: Set = new Set([ + 'ability_component.d.ts', + 'action_sheet.d.ts', + 'alert_dialog.d.ts', + 'alphabet_indexer.d.ts', + 'animator.d.ts', + 'badge.d.ts', + 'blank.d.ts', + 'button.d.ts', + 'calendar.d.ts', + 'calendar_picker.d.ts', + 'canvas.d.ts', + 'checkbox.d.ts', + 'checkboxgroup.d.ts', + 'circle.d.ts', + 'column.d.ts', + 'column_split.d.ts', + 'common.d.ts', + 'common_ts_ets_api.d.ts', + 'component3d.d.ts', + 'container_span.d.ts', + 'content_slot.d.ts', + 'context_menu.d.ts', + 'counter.d.ts', + 'custom_dialog_controller.d.ts', + 'data_panel.d.ts', + 'date_picker.d.ts', + 'divider.d.ts', + 'effect_component.d.ts', + 'ellipse.d.ts', + 'embedded_component.d.ts', + 'enums.d.ts', + 'flex.d.ts', + 'flow_item.d.ts', + 'focus.d.ts', + 'folder_stack.d.ts', + 'for_each.d.ts', + 'form_component.d.ts', + 'form_link.d.ts', + 'gauge.d.ts', + 'gesture.d.ts', + 'grid.d.ts', + 'gridItem.d.ts', + 'grid_col.d.ts', + 'grid_container.d.ts', + 'grid_row.d.ts', + 'hyperlink.d.ts', + 'image.d.ts', + 'image_animator.d.ts', + 'image_common.d.ts', + 'image_span.d.ts', + 'index-full.d.ts', + 'indicatorcomponent.d.ts', + 'inspector.d.ts', + 'isolated_component.d.ts', + 'lazy_for_each.d.ts', + 'lazy_grid_layout.d.ts', + 'line.d.ts', + 'list.d.ts', + 'list_item.d.ts', + 'list_item_group.d.ts', + 'loading_progress.d.ts', + 'marquee.d.ts', + 'matrix2d.d.ts', + 'media_cached_image.d.ts', + 'menu.d.ts', + 'menu_item.d.ts', + 'menu_item_group.d.ts', + 'nav_destination.d.ts', + 'nav_router.d.ts', + 'navigation.d.ts', + 'navigator.d.ts', + 'node_container.d.ts', + 'page_transition.d.ts', + 'panel.d.ts', + 'particle.d.ts', + 'paste_button.d.ts', + 'path.d.ts', + 'pattern_lock.d.ts', + 'plugin_component.d.ts', + 'polygon.d.ts', + 'polyline.d.ts', + 'progress.d.ts', + 'qrcode.d.ts', + 'radio.d.ts', + 'rating.d.ts', + 'rect.d.ts', + 'refresh.d.ts', + 'relative_container.d.ts', + 'remote_window.d.ts', + 'repeat.d.ts', + 'rich_editor.d.ts', + 'rich_text.d.ts', + 'root_scene.d.ts', + 'row.d.ts', + 'row_split.d.ts', + 'save_button.d.ts', + 'screen.d.ts', + 'scroll.d.ts', + 'scroll_bar.d.ts', + 'search.d.ts', + 'security_component.d.ts', + 'select.d.ts', + 'shape.d.ts', + 'sidebar.d.ts', + 'slider.d.ts', + 'span.d.ts', + 'stack.d.ts', + 'state_management.d.ts', + 'stepper.d.ts', + 'stepper_item.d.ts', + 'styled_string.d.ts', + 'swiper.d.ts', + 'symbol_span.d.ts', + 'symbolglyph.d.ts', + 'tab_content.d.ts', + 'tabs.d.ts', + 'text.d.ts', + 'text_area.d.ts', + 'text_clock.d.ts', + 'text_common.d.ts', + 'text_input.d.ts', + 'text_picker.d.ts', + 'text_timer.d.ts', + 'time_picker.d.ts', + 'toggle.d.ts', + 'toolbar.d.ts', + 'ui_extension_component.d.ts', + 'units.d.ts', + 'video.d.ts', + 'water_flow.d.ts', + 'web.d.ts', + 'window_scene.d.ts', + 'with_theme.d.ts', + 'xcomponent.d.ts', + 'rawFileDescriptor.d.ts', + 'resource.d.ts', + 'global.d.ts' +]); + export const customLayoutFunctionName: Set = new Set(['onMeasureSize', 'onPlaceChildren']); export const ENTRY_DECORATOR_NAME = 'Entry'; diff --git a/ets2panda/linter/test/main/interface_import_5.ets b/ets2panda/linter/test/main/interface_import_5.ets new file mode 100644 index 0000000000000000000000000000000000000000..64a90a84f2bfaac0bf68d82091fa02b01cd9c708 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_5.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Base from '@ohos.base' +const err = (err: Base.BusinessError) => {} + +@Entry +@Component +struct MyComponent { + build() { + + } +} \ No newline at end of file diff --git a/ets2panda/linter/test/main/interface_import_5.ets.args.json b/ets2panda/linter/test/main/interface_import_5.ets.args.json new file mode 100644 index 0000000000000000000000000000000000000000..ef3938e967322a0c7551d84c7b6d280de94144c8 --- /dev/null +++ b/ets2panda/linter/test/main/interface_import_5.ets.args.json @@ -0,0 +1,21 @@ +{ + "copyright": [ + "Copyright (c) 2025 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "mode": { + "arkts2": "", + "autofix": "--arkts-2", + "migrate": "--arkts-2" + } +} \ No newline at end of file