diff --git a/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/input.xml b/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/input.xml index 00590cd2b..f5dcde93a 100644 --- a/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/input.xml +++ b/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/input.xml @@ -1,7 +1,7 @@ + xmlns:sap.ui.dt="sap.ui.dt"> <🢂m:Button🢀> diff --git a/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/output-lsp-response.json b/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/output-lsp-response.json index 99c05aac5..db5fa7511 100644 --- a/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/output-lsp-response.json +++ b/packages/language-server/test/snapshots/xml-view-diagnostics/non-stable-id/output-lsp-response.json @@ -1,13 +1,4 @@ [ - { - "range": { - "start": { "line": 3, "character": 20 }, - "end": { "line": 3, "character": 31 } - }, - "severity": 2, - "source": "UI5 Language Assistant", - "message": "Unknown namespace: \"sap.ui.dt\"" - }, { "range": { "start": { "line": 5, "character": 9 }, diff --git a/packages/xml-views-validation/src/validators/attributes/unknown-xmlns-namespace.ts b/packages/xml-views-validation/src/validators/attributes/unknown-xmlns-namespace.ts index 6909574c2..b6610db6f 100644 --- a/packages/xml-views-validation/src/validators/attributes/unknown-xmlns-namespace.ts +++ b/packages/xml-views-validation/src/validators/attributes/unknown-xmlns-namespace.ts @@ -1,9 +1,9 @@ +import { find, includes } from "lodash"; import { XMLAttribute } from "@xml-tools/ast"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { findSymbol } from "@ui5-language-assistant/semantic-model"; import { isXMLNamespaceKey } from "@xml-tools/common"; import { UnknownNamespaceInXmlnsAttributeValueIssue } from "../../../api"; -import { find } from "lodash"; export function validateUnknownXmlnsNamespace( attribute: XMLAttribute, @@ -25,6 +25,11 @@ export function validateUnknownXmlnsNamespace( return []; } + const whiteListedNamespaces = ["sap.ui.dt"]; + if (includes(whiteListedNamespaces, attributeValue)) { + return []; + } + // Only check namespaces from libraries. // There are valid namespaces like some that start with "http" that should not return an error. // Additionally, customers can develop in custom namespaces, even those that start with "sap", and we don't want to give false positives. diff --git a/packages/xml-views-validation/test/validators/attributes/unknown-xmlns-namespace-spec.ts b/packages/xml-views-validation/test/validators/attributes/unknown-xmlns-namespace-spec.ts index 5ff627018..56aa0710c 100644 --- a/packages/xml-views-validation/test/validators/attributes/unknown-xmlns-namespace-spec.ts +++ b/packages/xml-views-validation/test/validators/attributes/unknown-xmlns-namespace-spec.ts @@ -1,12 +1,12 @@ import { expect } from "chai"; 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 { testValidationsScenario, computeExpectedRange, } from "../../test-utils"; import { validateUnknownXmlnsNamespace } from "../../../src/validators/attributes/unknown-xmlns-namespace"; -import { generate } from "@ui5-language-assistant/semantic-model"; describe("the unknown namespace in xmlns attribute value validation", () => { let ui5SemanticModel: UI5SemanticModel; @@ -205,5 +205,24 @@ describe("the unknown namespace in xmlns attribute value validation", () => { }, }); }); + + it("will not detect an issue when the attribute value is a whitelisted namespace", () => { + const xmlSnippet = ` + + `; + + testValidationsScenario({ + model: ui5SemanticModel, + xmlText: xmlSnippet, + validators: { + attribute: [validateUnknownXmlnsNamespace], + }, + assertion: (issues) => { + expect(issues).to.be.empty; + }, + }); + }); }); });