Skip to content

Commit

Permalink
refactor: Address GH comments
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Feb 11, 2025
1 parent ce27fdd commit ce8a0db
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class SourceFileLinter {
} else if (ts.isObjectLiteralExpression(node)) {
node.properties.forEach((prop) => {
if (ts.isPropertyAssignment(prop) &&
ts.isIdentifier(prop.name) &&
(ts.isIdentifier(prop.name) || ts.isStringLiteralLike(prop.name)) &&
ts.isStringLiteralLike(prop.initializer) &&
["definition", "fragmentContent", "viewContent"].includes(prop.name.text) &&
this.isXMLInJsCreationCall(prop, prop.name.text)) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/linter/rules/XMLInJs/FragmentLoad.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sap.ui.require(["sap/ui/core/Fragment"], async (Fragment) => {
const content = await Fragment.load({
type: "XML",
definition: `<core:FragmentDefinition
"definition": `<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<Button tap=".sayHello">
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/linter/rules/XMLInJs/SapUIFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ sap.ui.require([], () => {
<Button tap=".sayHello">
</core:FragmentDefinition>`,
});

const fragment2 = sap.ui.xmlfragment({
fragmentContent: `<core:FragmentDefinition
"fragmentContent": `<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<Button tap=".sayHello">
Expand Down
6 changes: 5 additions & 1 deletion test/fixtures/linter/rules/XMLInJs/SapUIView.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sap.ui.define([], () => {

const oView2 = sap.ui.view({
type: "XML",
viewContent: `<mvc:View
"viewContent": `<mvc:View
controllerName="ui5app.controller.Home"
displayBlock="true"
xmlns="sap.m"
Expand All @@ -35,4 +35,8 @@ sap.ui.define([], () => {
<Button tap=".sayHello">
</mvc:View>`,
});

sap.ui.xmlview({
viewContent: `<mvc:View controllerName="ui5app.controller.Home" displayBlock="true" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core"><Button tap=".sayHello"></mvc:View>`,
});
});
4 changes: 2 additions & 2 deletions test/fixtures/linter/rules/XMLInJs/ViewCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ sap.ui.define(
});
oView.placeAt("content");

const oView2 = XMLView.create({
definition: `<mvc:View
const oView2 = await XMLView.create({
"definition": `<mvc:View
controllerName="ui5app.controller.Home"
displayBlock="true"
xmlns="sap.m"
Expand Down
File renamed without changes.
39 changes: 28 additions & 11 deletions test/lib/linter/rules/snapshots/XMLInJs.ts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Snapshot report for `test/lib/linter/rules/XMLInJs.ts`
# Snapshot report for `test/lib/linter/rules/XmlInJs.ts`

The actual snapshot is saved in `XMLInJs.ts.snap`.
The actual snapshot is saved in `XmlInJs.ts.snap`.

Generated by [AVA](https://avajs.dev).

Expand Down Expand Up @@ -99,7 +99,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 9,
errorCount: 12,
fatalErrorCount: 0,
filePath: 'SapUIView.js',
messages: [
Expand Down Expand Up @@ -167,6 +167,22 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 2,
line: 39,
message: 'Access of global variable \'sap\' (sap.ui.xmlview)',
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: 9,
line: 39,
message: 'Call to deprecated function \'xmlview\' (sap.ui.xmlview)',
messageDetails: 'Deprecated test message',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 13,
line: 35,
Expand All @@ -175,6 +191,14 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 146,
line: 40,
message: 'Use of deprecated property \'tap\' of class \'Button\'',
messageDetails: 'Deprecated test message',
ruleId: 'no-deprecated-api',
severity: 2,
},
],
warningCount: 0,
},
Expand All @@ -186,14 +210,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [
{
category: 1,
column: 3,
line: 27,
message: 'Unable to analyze this method call because the type of identifier "placeAt" in "oView2.placeAt("content")"" could not be determined',
},
],
coverageInfo: [],
errorCount: 2,
fatalErrorCount: 0,
filePath: 'ViewCreate.js',
Expand Down
Binary file modified test/lib/linter/rules/snapshots/XMLInJs.ts.snap
Binary file not shown.

0 comments on commit ce8a0db

Please sign in to comment.