Skip to content

Commit

Permalink
feat: Analyze sap.ui.core.Lib.init() call
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Mar 14, 2024
1 parent 88b327e commit 40e878e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/detectors/typeChecker/FileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class FileLinter {
// const nodeType = this.#checker.getTypeAtLocation(node);
this.analyzePropertyAccessExpression(node as ts.CallExpression); // Check for global
this.analyzeCallExpression(node as ts.CallExpression); // Check for deprecation
this.analyzeLibInitCall(node as ts.CallExpression); // Check for sap.ui.coreLib.init usages
} else if (node.kind === ts.SyntaxKind.PropertyAccessExpression ||
node.kind === ts.SyntaxKind.ElementAccessExpression) {
this.analyzePropertyAccessExpression(
Expand Down Expand Up @@ -206,6 +207,35 @@ export default class FileLinter {
messageDetails: deprecationInfo.messageDetails,
});
}

Check failure on line 210 in src/detectors/typeChecker/FileLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Trailing spaces not allowed
analyzeLibInitCall(node: ts.CallExpression) {
const nodeExp = node.expression as ts.PropertyAccessExpression;
if (nodeExp?.name?.text !== "init" ||
!ts.isPropertyAccessExpression(nodeExp) ||

Check failure on line 214 in src/detectors/typeChecker/FileLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Trailing spaces not allowed
!ts.isIdentifier(nodeExp.expression) ||
nodeExp?.expression?.text !== "Library") { // TODO: Check more reliably the import var of sap.ui.core.Lib
// Library.init() -> init() is already identified as CallExpression, so
// Library needs to be a propertyAccessExpression
return;
}

Check failure on line 221 in src/detectors/typeChecker/FileLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Trailing spaces not allowed
const libVersion = (node.arguments[0] as ts.ObjectLiteralExpression)
.properties.find((prop: ts.ObjectLiteralElementLike) => {
return ts.isPropertyAssignment(prop) &&
ts.isIdentifier(prop.name) && prop.name.text === "version" &&

Check failure on line 225 in src/detectors/typeChecker/FileLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Trailing spaces not allowed
ts.isLiteralExpression(prop.initializer) && prop.initializer.text !== "2";
}) as ts.PropertyAssignment | undefined;

Check failure on line 228 in src/detectors/typeChecker/FileLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Trailing spaces not allowed
if (libVersion) {
this.#reporter.addMessage({
node: libVersion,
severity: LintMessageSeverity.Error,
ruleId: "ui5-linter-no-partially-deprecated-api",
message:
`Call to ${nodeExp.expression.text}.init() must be declared with property {version: 2}`

Check failure on line 235 in src/detectors/typeChecker/FileLinter.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Missing trailing comma
});
}
}

getDeprecationInfoForAccess(node: ts.AccessExpression): DeprecationInfo | null {
let symbol;
Expand Down

0 comments on commit 40e878e

Please sign in to comment.