Skip to content

Commit

Permalink
fix: Check bindings of all ManagedObject subclasses
Browse files Browse the repository at this point in the history
Follow-up of #513
  • Loading branch information
matz3 committed Feb 18, 2025
1 parent 0bbf8df commit 0e410db
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ export default class SourceFileLinter {
} else if (moduleDeclaration?.name.text === "sap/ui/model/odata/v4/ODataModel") {
this.#analyzeNewOdataModelV4(node);
} else if (nodeType.symbol.declarations?.some(
(declaration) => this.isUi5ClassDeclaration(declaration, "sap/ui/core/Control"))) {
(declaration) => this.isUi5ClassDeclaration(declaration, "sap/ui/base/ManagedObject"))) {
const originalFilename = this.#metadata?.xmlCompiledResource;
// Do not process xml-s. This case would be handled separately within the BindingParser
if (!originalFilename ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sap.ui.define(
["sap/m/Input", "ui5/walkthrough/model/formatter"],
(Input, formatter) => {
["sap/m/Input", "sap/ui/table/RowSettings", "ui5/walkthrough/model/formatter"],
(Input, RowSettings, formatter) => {
// The following two cases using global notations should be detected:
const input = new Input({
value: "{ path: 'invoice>Status', formatter: 'ui5.walkthrough.model.formatter.statusText' }"
Expand All @@ -14,5 +14,14 @@ sap.ui.define(
const input2 = new Input({
value: "{ path: 'invoice>Status', formatter: 'formatter.statusText' }"
});

// Note: RowSettings is an element, not a control (bindings are supported for all ManagedObject sub-classes)
const rowSettings = new RowSettings({
highlight: "{ path: 'invoice>Status', formatter: 'ui5.walkthrough.model.formatter.statusText' }",
});

rowSettings.applySettings({
highlight: "{ path: 'invoice>Status', formatter: 'ui5.walkthrough.model.formatter.statusText' }",
});
}
);
19 changes: 17 additions & 2 deletions test/fixtures/linter/rules/NoGlobals/ModelDataTypes_New.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sap.ui.define(["sap/m/Input"], (Input) => {
sap.ui.define(["sap/m/Input", "sap/ui/table/RowSettings"], (Input, RowSettings) => {
const input = new Input({
value: {
path: "/names/0/amount",
Expand All @@ -7,7 +7,7 @@ sap.ui.define(["sap/m/Input"], (Input) => {
constraints: { maximum: 1000 },
},
});

input.applySettings({
value: {
path: "/names/0/amount",
Expand All @@ -16,4 +16,19 @@ sap.ui.define(["sap/m/Input"], (Input) => {
constraints: { maximum: 1000 },
},
});

// Note: RowSettings is an element, not a control (bindings are supported for all ManagedObject sub-classes)
const rowSettings = new RowSettings({
highlight: {
path: "/names/0/amount",
type: "sap.ui.model.type.Integer"
}
});

rowSettings.applySettings({
highlight: {
path: "/names/0/amount",
type: "sap.ui.model.type.Integer"
}
});
});
13 changes: 11 additions & 2 deletions test/fixtures/linter/rules/NoGlobals/ModelDataTypes_NewString.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
sap.ui.define(["sap/m/Input"], (Input) => {
sap.ui.define(["sap/m/Input", "sap/ui/table/RowSettings"], (Input, RowSettings) => {
const input = new Input({
value: "{ path: '/names/0/amount', type: 'sap.ui.model.type.Integer' }",
});

input.applySettings({
value: "{ path: '/names/0/amount', type: 'sap.ui.model.type.Integer' }",
});

// Note: RowSettings is an element, not a control (bindings are supported for all ManagedObject sub-classes)
const rowSettings = new RowSettings({
highlight: "{ path: '/names/0/amount', type: 'sap.ui.model.type.Integer' }",
});

rowSettings.applySettings({
highlight: "{ path: '/names/0/amount', type: 'sap.ui.model.type.Integer' }",
});
});
54 changes: 51 additions & 3 deletions test/lib/linter/rules/snapshots/NoGlobals.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 3,
errorCount: 5,
fatalErrorCount: 0,
filePath: 'FormatterGlobalBindingString.js',
messages: [
Expand Down Expand Up @@ -63,6 +63,22 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'no-globals',
severity: 2,
},
{
column: 15,
line: 20,
message: 'Access of global variable \'ui5\' (ui5.walkthrough.model.formatter.statusText)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
{
column: 15,
line: 24,
message: 'Access of global variable \'ui5\' (ui5.walkthrough.model.formatter.statusText)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
],
warningCount: 0,
},
Expand Down Expand Up @@ -279,7 +295,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 2,
errorCount: 4,
fatalErrorCount: 0,
filePath: 'ModelDataTypes_New.js',
messages: [
Expand All @@ -299,6 +315,22 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'no-globals',
severity: 2,
},
{
column: 10,
line: 24,
message: 'Access of global variable \'sap.ui.model.type.Integer\' (sap/ui/model/type/Integer)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
{
column: 10,
line: 31,
message: 'Access of global variable \'sap.ui.model.type.Integer\' (sap/ui/model/type/Integer)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
],
warningCount: 0,
},
Expand Down Expand Up @@ -326,7 +358,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 2,
errorCount: 4,
fatalErrorCount: 0,
filePath: 'ModelDataTypes_NewString.js',
messages: [
Expand All @@ -346,6 +378,22 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'no-globals',
severity: 2,
},
{
column: 14,
line: 12,
message: 'Access of global variable \'sap\' (sap.ui.model.type.Integer)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
{
column: 14,
line: 16,
message: 'Access of global variable \'sap\' (sap.ui.model.type.Integer)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
],
warningCount: 0,
},
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoGlobals.ts.snap
Binary file not shown.

0 comments on commit 0e410db

Please sign in to comment.