Skip to content

Commit 8fff87d

Browse files
authored
fix: relax diagnostic for typedefs (#644)
* fix: relax diagnostic for typedefs * fix: add change set
1 parent af5e085 commit 8fff87d

File tree

7 files changed

+74
-16
lines changed

7 files changed

+74
-16
lines changed

.changeset/beige-eagles-warn.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
3+
"vscode-ui5-language-assistant": patch
4+
"@ui5-language-assistant/xml-views-validation": patch
5+
"@ui5-language-assistant/logic-utils": patch
6+
---
7+
8+
releax typedefs validation

packages/logic-utils/api.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export {
274274
tryFetch,
275275
getLocalUrl,
276276
isXMLView,
277+
getUI5KindByXMLElement,
277278
} from "./src/api";
278279

279280
export { FetchResponse } from "./src/utils/types";

packages/logic-utils/src/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export { isRootSymbol, getRootSymbolParent } from "./utils/root-symbols";
1616
export { typeToString } from "./utils/type-to-string";
1717
export {
1818
getUI5ClassByXMLElement,
19+
getUI5KindByXMLElement,
1920
getUI5ClassByXMLElementClosingTag,
2021
getUI5AggregationByXMLElement,
2122
getUI5PropertyByXMLAttributeKey,

packages/logic-utils/src/utils/xml-node-to-ui5-node.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,29 @@ import {
1818
BaseUI5Node,
1919
UI5Event,
2020
UI5Association,
21+
UI5Enum,
22+
UI5Typedef,
23+
UI5Function,
2124
} from "@ui5-language-assistant/semantic-model-types";
2225
import { find } from "lodash";
2326
import { findSymbol } from "@ui5-language-assistant/semantic-model";
2427

28+
export function getUI5KindByXMLElement<
29+
T = UI5Class | UI5Enum | UI5Typedef | UI5Function | UI5Enum | undefined
30+
>(
31+
element: XMLElement,
32+
model: UI5SemanticModel,
33+
kind: "classes" | "enums" | "typedefs" | "functions" | "enums"
34+
): T {
35+
const fqn = xmlToFQN(element);
36+
return model[kind][fqn] as T;
37+
}
38+
2539
export function getUI5ClassByXMLElement(
2640
element: XMLElement,
2741
model: UI5SemanticModel
2842
): UI5Class | undefined {
29-
const elementTagFqn = xmlToFQN(element);
30-
const ui5Class = model.classes[elementTagFqn];
43+
const ui5Class = getUI5KindByXMLElement<UI5Class>(element, model, "classes");
3144
// The class name might not be the same as the element name in case the element name contained a dot
3245
// (example: using core:mvc.View instead of mvc:View), which is not allowed.
3346
if (ui5Class === undefined || ui5Class.name !== element.name) {

packages/xml-views-validation/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"devDependencies": {
3333
"@ui5-language-assistant/semantic-model": "4.0.11",
3434
"@ui5-language-assistant/test-utils": "4.0.9",
35-
"@xml-tools/parser": "1.0.7"
35+
"@xml-tools/parser": "1.0.7",
36+
"@ui5-language-assistant/test-framework": "4.0.11"
3637
},
3738
"scripts": {
3839
"ci": "npm-run-all clean compile lint coverage",

packages/xml-views-validation/src/validators/elements/unknown-tag-name.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getUI5AggregationByXMLElement,
1313
isSameXMLNS,
1414
resolveXMLNS,
15+
getUI5KindByXMLElement,
1516
} from "@ui5-language-assistant/logic-utils";
1617
import {
1718
validations,
@@ -91,10 +92,11 @@ function validateTagWithNamespace(
9192
return [];
9293
}
9394

94-
// Check if it's a known class or aggregaion, or an element that should be ignored
95+
// Check if it's a known class, typedefs or aggregation, or an element that should be ignored
9596
if (
9697
shouldIgnoreElement(xmlElement) ||
9798
getUI5ClassByXMLElement(xmlElement, model) !== undefined ||
99+
getUI5KindByXMLElement(xmlElement, model, "typedefs") !== undefined ||
98100
getUI5AggregationByXMLElement(xmlElement, model) !== undefined
99101
) {
100102
return [];

packages/xml-views-validation/test/unit/validators/element/unknown-tag-name.test.ts

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
import { join } from "path";
12
import { partial } from "lodash";
2-
import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types";
3-
import { generateModel } from "@ui5-language-assistant/test-utils";
4-
import { generate } from "@ui5-language-assistant/semantic-model";
53
import {
64
validations,
75
buildMessage,
@@ -12,9 +10,17 @@ import {
1210
assertSingleIssue as assertSingleIssueBase,
1311
testValidationsScenario,
1412
computeExpectedRanges,
15-
getDefaultContext,
1613
} from "../../test-utils";
17-
import { Context as AppContext } from "@ui5-language-assistant/context";
14+
import {
15+
Context as AppContext,
16+
getContext,
17+
} from "@ui5-language-assistant/context";
18+
import {
19+
Config,
20+
ProjectName,
21+
ProjectType,
22+
TestFramework,
23+
} from "@ui5-language-assistant/test-framework";
1824

1925
const {
2026
UNKNOWN_CLASS_IN_NS,
@@ -28,15 +34,29 @@ const {
2834
} = validations;
2935

3036
describe("the unknown tag name validation", () => {
31-
let ui5SemanticModel: UI5SemanticModel;
3237
let appContext: AppContext;
38+
let framework: TestFramework;
39+
const viewFilePathSegments = [
40+
"app",
41+
"manage_travels",
42+
"webapp",
43+
"ext",
44+
"main",
45+
"Main.view.xml",
46+
];
3347
beforeAll(async () => {
34-
ui5SemanticModel = await generateModel({
35-
framework: "SAPUI5",
36-
version: "1.71.49",
37-
modelGenerator: generate,
38-
});
39-
appContext = getDefaultContext(ui5SemanticModel);
48+
const config: Config = {
49+
projectInfo: {
50+
name: ProjectName.cap,
51+
type: ProjectType.CAP,
52+
npmInstall: false,
53+
deleteBeforeCopy: false,
54+
},
55+
};
56+
framework = new TestFramework(config);
57+
appContext = (await getContext(
58+
join(framework.getProjectRoot(), ...viewFilePathSegments)
59+
)) as AppContext;
4060
});
4161

4262
describe("true positive scenarios", () => {
@@ -563,6 +583,18 @@ describe("the unknown tag name validation", () => {
563583
);
564584
});
565585

586+
it("will not detect an issue for typedefs as element [macrosTable:Action]", async () => {
587+
assertNoIssues(
588+
`<mvc:View
589+
xmlns:macrosTable="sap.fe.macros.table"
590+
>
591+
<macrosTable:Action
592+
key="customAction"
593+
text="My Custom Action"
594+
/>
595+
</mvc:View>`
596+
);
597+
});
566598
it("will detect an issue for sap.ui.core.ExtensionPoint in the root tag", () => {
567599
assertSingleIssue(
568600
`<🢂ExtensionPoint🢀 name="extension1"></ExtensionPoint>`,

0 commit comments

Comments
 (0)