Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Provide check for alternative names of the properties #506

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,15 @@ export default class SourceFileLinter {
} else if (symbolName.startsWith("bind") &&
nodeType.symbol?.declarations?.some((declaration) =>
this.isUi5ClassDeclaration(declaration, "sap/ui/core/Control")) &&
node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0]) &&
this.#isPropertyBinding(node, symbolName.replace("bind", "").toLocaleLowerCase())) {
this.#analyzePropertyBindings(node.arguments[0], ["type"]);
node.arguments[0] && ts.isObjectLiteralExpression(node.arguments[0])) {
// Setting names in UI5 are case sensitive. So, we're not sure of the exact name of the property.
// Check decapitalized version of the property name as well.
const propName = symbolName.replace("bind", "");
const alternativePropName = propName.charAt(0).toLowerCase() + propName.slice(1);

if (this.#isPropertyBinding(node, [propName, alternativePropName])) {
this.#analyzePropertyBindings(node.arguments[0], ["type"]);
}
}
}

Expand Down Expand Up @@ -1173,7 +1179,7 @@ export default class SourceFileLinter {
.forEach((prop) => {
if (ts.isPropertyAssignment(prop) &&
(ts.isCallExpression(node) ||
this.#isPropertyBinding(node, getPropertyNameText(prop.name)?.toLocaleLowerCase()))
this.#isPropertyBinding(node, [getPropertyNameText(prop.name) ?? ""]))
) {
if (ts.isObjectLiteralExpression(prop.initializer)) {
this.#analyzePropertyBindings(prop.initializer, ["type"]);
Expand Down Expand Up @@ -1241,7 +1247,7 @@ export default class SourceFileLinter {
* from there. Directly finding the type of the property is not possible from here as it's
* missing some context.
*/
#isPropertyBinding(node: ts.NewExpression | ts.CallExpression, propName: string | undefined) {
#isPropertyBinding(node: ts.NewExpression | ts.CallExpression, propNames: string[]) {
const controlAmbientModule =
this.getSymbolModuleDeclaration(this.checker.getTypeAtLocation(node).symbol);

Expand All @@ -1254,7 +1260,7 @@ export default class SourceFileLinter {

const constructorArgType = classArg && this.checker.getTypeAtLocation(classArg.parameters[0]);
const argProperty = constructorArgType?.getProperties()
.find((p: ts.Symbol) => p.name.toLocaleLowerCase() === propName);
.find((p: ts.Symbol) => propNames.includes(p.name));
const argPropType = argProperty?.valueDeclaration &&
this.checker.getTypeAtLocation(argProperty.valueDeclaration);

Expand Down