Skip to content

Commit

Permalink
feat: Handle ES6 interface implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed May 7, 2024
1 parent bf932e3 commit ccbee8b
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/linter/ui5Types/BestPractices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function findAsyncInterface({classDefinition, manifestContent, checker, uiCompon

// Checks the interfaces and manifest
const curClassAnalysis = classDefinition.members.reduce((acc, member) => {
const checkResult = doChecks(member as ts.PropertyDeclaration, manifestContent);
const checkResult = doPropChecks(member as ts.PropertyDeclaration, manifestContent);
return mergeResults(acc, checkResult);
}, {...returnTypeTemplate});

Expand All @@ -119,6 +119,8 @@ function findAsyncInterface({classDefinition, manifestContent, checker, uiCompon
checker,
uiComponentImportVar,
}) ?? result;
} else if (ts.isInterfaceDeclaration(declaration)) {
result.hasAsyncInterface = doAsyncInterfaceChecks(parentClass) ?? result.hasAsyncInterface;
}

return result;
Expand All @@ -132,7 +134,33 @@ function findAsyncInterface({classDefinition, manifestContent, checker, uiCompon
}
}

function doChecks(metadata: ts.PropertyDeclaration, manifestContent: string | undefined) {
function doAsyncInterfaceChecks(importDeclaration: ts.Node): boolean | undefined {
while (!importDeclaration || importDeclaration.kind !== ts.SyntaxKind.SourceFile) {
importDeclaration = importDeclaration.parent;
}

// @ts-expect-error imports is part of SourceFileObject
const moduleImports = importDeclaration?.imports as ts.Node[];
const coreLib = moduleImports?.find((importModule) => {
return importModule.getText() === "\"sap/ui/core/library\"";
}) as ts.StringLiteral | undefined;

let hasAsyncInterface;
if (coreLib && ts.isImportDeclaration(coreLib.parent)) {
if (coreLib.parent.importClause?.namedBindings &&
coreLib.parent.importClause.namedBindings.kind === ts.SyntaxKind.NamedImports) {
hasAsyncInterface = coreLib.parent.importClause.namedBindings.elements.some(
(namedImport) => namedImport.getText() === "IAsyncContentCreation");
} else {
hasAsyncInterface =
coreLib.parent.importClause?.name?.getText() === "IAsyncContentCreation";
}
}

return hasAsyncInterface;
}

function doPropChecks(metadata: ts.PropertyDeclaration, manifestContent: string | undefined) {
let classInterfaces: ts.ObjectLiteralElementLike | undefined;
let componentManifest: ts.ObjectLiteralElementLike | undefined;

Expand Down

0 comments on commit ccbee8b

Please sign in to comment.