Skip to content

Commit

Permalink
fix: relax diagnostic for typedefs (#644)
Browse files Browse the repository at this point in the history
* fix: relax diagnostic for typedefs

* fix: add change set
  • Loading branch information
marufrasully authored Aug 2, 2023
1 parent af5e085 commit 8fff87d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .changeset/beige-eagles-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/xml-views-validation": patch
"@ui5-language-assistant/logic-utils": patch
---

releax typedefs validation
1 change: 1 addition & 0 deletions packages/logic-utils/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export {
tryFetch,
getLocalUrl,
isXMLView,
getUI5KindByXMLElement,
} from "./src/api";

export { FetchResponse } from "./src/utils/types";
1 change: 1 addition & 0 deletions packages/logic-utils/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export { isRootSymbol, getRootSymbolParent } from "./utils/root-symbols";
export { typeToString } from "./utils/type-to-string";
export {
getUI5ClassByXMLElement,
getUI5KindByXMLElement,
getUI5ClassByXMLElementClosingTag,
getUI5AggregationByXMLElement,
getUI5PropertyByXMLAttributeKey,
Expand Down
17 changes: 15 additions & 2 deletions packages/logic-utils/src/utils/xml-node-to-ui5-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,29 @@ import {
BaseUI5Node,
UI5Event,
UI5Association,
UI5Enum,
UI5Typedef,
UI5Function,
} from "@ui5-language-assistant/semantic-model-types";
import { find } from "lodash";
import { findSymbol } from "@ui5-language-assistant/semantic-model";

export function getUI5KindByXMLElement<
T = UI5Class | UI5Enum | UI5Typedef | UI5Function | UI5Enum | undefined
>(
element: XMLElement,
model: UI5SemanticModel,
kind: "classes" | "enums" | "typedefs" | "functions" | "enums"
): T {
const fqn = xmlToFQN(element);
return model[kind][fqn] as T;
}

export function getUI5ClassByXMLElement(
element: XMLElement,
model: UI5SemanticModel
): UI5Class | undefined {
const elementTagFqn = xmlToFQN(element);
const ui5Class = model.classes[elementTagFqn];
const ui5Class = getUI5KindByXMLElement<UI5Class>(element, model, "classes");
// The class name might not be the same as the element name in case the element name contained a dot
// (example: using core:mvc.View instead of mvc:View), which is not allowed.
if (ui5Class === undefined || ui5Class.name !== element.name) {
Expand Down
3 changes: 2 additions & 1 deletion packages/xml-views-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"devDependencies": {
"@ui5-language-assistant/semantic-model": "4.0.11",
"@ui5-language-assistant/test-utils": "4.0.9",
"@xml-tools/parser": "1.0.7"
"@xml-tools/parser": "1.0.7",
"@ui5-language-assistant/test-framework": "4.0.11"
},
"scripts": {
"ci": "npm-run-all clean compile lint coverage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getUI5AggregationByXMLElement,
isSameXMLNS,
resolveXMLNS,
getUI5KindByXMLElement,
} from "@ui5-language-assistant/logic-utils";
import {
validations,
Expand Down Expand Up @@ -91,10 +92,11 @@ function validateTagWithNamespace(
return [];
}

// Check if it's a known class or aggregaion, or an element that should be ignored
// Check if it's a known class, typedefs or aggregation, or an element that should be ignored
if (
shouldIgnoreElement(xmlElement) ||
getUI5ClassByXMLElement(xmlElement, model) !== undefined ||
getUI5KindByXMLElement(xmlElement, model, "typedefs") !== undefined ||
getUI5AggregationByXMLElement(xmlElement, model) !== undefined
) {
return [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { join } from "path";
import { partial } from "lodash";
import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types";
import { generateModel } from "@ui5-language-assistant/test-utils";
import { generate } from "@ui5-language-assistant/semantic-model";
import {
validations,
buildMessage,
Expand All @@ -12,9 +10,17 @@ import {
assertSingleIssue as assertSingleIssueBase,
testValidationsScenario,
computeExpectedRanges,
getDefaultContext,
} from "../../test-utils";
import { Context as AppContext } from "@ui5-language-assistant/context";
import {
Context as AppContext,
getContext,
} from "@ui5-language-assistant/context";
import {
Config,
ProjectName,
ProjectType,
TestFramework,
} from "@ui5-language-assistant/test-framework";

const {
UNKNOWN_CLASS_IN_NS,
Expand All @@ -28,15 +34,29 @@ const {
} = validations;

describe("the unknown tag name validation", () => {
let ui5SemanticModel: UI5SemanticModel;
let appContext: AppContext;
let framework: TestFramework;
const viewFilePathSegments = [
"app",
"manage_travels",
"webapp",
"ext",
"main",
"Main.view.xml",
];
beforeAll(async () => {
ui5SemanticModel = await generateModel({
framework: "SAPUI5",
version: "1.71.49",
modelGenerator: generate,
});
appContext = getDefaultContext(ui5SemanticModel);
const config: Config = {
projectInfo: {
name: ProjectName.cap,
type: ProjectType.CAP,
npmInstall: false,
deleteBeforeCopy: false,
},
};
framework = new TestFramework(config);
appContext = (await getContext(
join(framework.getProjectRoot(), ...viewFilePathSegments)
)) as AppContext;
});

describe("true positive scenarios", () => {
Expand Down Expand Up @@ -563,6 +583,18 @@ describe("the unknown tag name validation", () => {
);
});

it("will not detect an issue for typedefs as element [macrosTable:Action]", async () => {
assertNoIssues(
`<mvc:View
xmlns:macrosTable="sap.fe.macros.table"
>
<macrosTable:Action
key="customAction"
text="My Custom Action"
/>
</mvc:View>`
);
});
it("will detect an issue for sap.ui.core.ExtensionPoint in the root tag", () => {
assertSingleIssue(
`<🢂ExtensionPoint🢀 name="extension1"></ExtensionPoint>`,
Expand Down

0 comments on commit 8fff87d

Please sign in to comment.