diff --git a/src/linter/ui5Types/SourceFileLinter.ts b/src/linter/ui5Types/SourceFileLinter.ts index ded9e7c46..d908d1bc2 100644 --- a/src/linter/ui5Types/SourceFileLinter.ts +++ b/src/linter/ui5Types/SourceFileLinter.ts @@ -90,7 +90,7 @@ export default class SourceFileLinter { this.visitNode(this.sourceFile); if (this.sourceFile.fileName.includes(".qunit.js") && - !metadata?.transformedImports?.get("sap.ui.define")?.size) { + !metadata?.transformedImports?.get("sap.ui.define")) { this.#reporter.addMessage(MESSAGE.PREFER_TEST_STARTER, this.sourceFile); } diff --git a/src/linter/ui5Types/amdTranspiler/tsTransformer.ts b/src/linter/ui5Types/amdTranspiler/tsTransformer.ts index 5ee248b83..a0726a192 100644 --- a/src/linter/ui5Types/amdTranspiler/tsTransformer.ts +++ b/src/linter/ui5Types/amdTranspiler/tsTransformer.ts @@ -113,8 +113,13 @@ function transform( const moduleDeclaration = parseModuleDeclaration(node.arguments, checker); const moduleDefinition = moduleDeclarationToDefinition(moduleDeclaration, sourceFile, nodeFactory); moduleDefinitions.push(moduleDefinition); - moduleDefinition.imports.forEach((importStatement) => - addModuleMetadata(metadata, "sap.ui.define", importStatement)); + if (moduleDefinition.imports.length) { + moduleDefinition.imports.forEach((importStatement) => + addModuleMetadata(metadata, "sap.ui.define", importStatement)); + } else { + // Empty sap.ui.define (no imports, no body) + addModuleMetadata(metadata, "sap.ui.define"); + } pruneNode(node); // Mark the define call for removal } catch (err) { if (err instanceof UnsupportedModuleError) { @@ -278,12 +283,12 @@ function transform( } }); - function addModuleMetadata(metadata: LintMetadata, importType: string, importStatement: ts.ImportDeclaration) { + function addModuleMetadata(metadata: LintMetadata, importType: string, importStatement?: ts.ImportDeclaration) { if (!metadata.transformedImports) { metadata.transformedImports = new Map>(); } const curResource = metadata.transformedImports.get(importType) ?? new Set(); - if (ts.isStringLiteral(importStatement.moduleSpecifier)) { + if (importStatement && ts.isStringLiteral(importStatement.moduleSpecifier)) { curResource.add(importStatement.moduleSpecifier.text); } metadata.transformedImports.set(importType, curResource); diff --git a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md index 59d2c53e5..f1a6fbcf0 100644 --- a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md +++ b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md @@ -2956,16 +2956,8 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-theme', severity: 2, }, - { - column: 9, - line: 3, - message: 'To save boilerplate code and ensure compliance with UI5 2.x best practices, please migrate to the Test Starter concept', - messageDetails: 'Test Starter (https://ui5.sap.com/#/topic/032be2cb2e1d4115af20862673bedcdb)', - ruleId: 'prefer-test-starter', - severity: 1, - }, ], - warningCount: 1, + warningCount: 0, }, ] @@ -3044,16 +3036,8 @@ Generated by [AVA](https://avajs.dev). ruleId: 'no-deprecated-theme', severity: 2, }, - { - column: 9, - line: 3, - message: 'To save boilerplate code and ensure compliance with UI5 2.x best practices, please migrate to the Test Starter concept', - messageDetails: 'Test Starter (https://ui5.sap.com/#/topic/032be2cb2e1d4115af20862673bedcdb)', - ruleId: 'prefer-test-starter', - severity: 1, - }, ], - warningCount: 1, + warningCount: 0, }, ] diff --git a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap index 4e5470a91..b35f0c47e 100644 Binary files a/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap and b/test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap differ