Skip to content

Commit

Permalink
fix: ignore unknown namespace message for whitelisted namespaces (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapirpol authored Jul 15, 2020
1 parent 65ddb60 commit bdcab7d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<mvc:View xmlns:core="sap.ui.core" xmlns:uxap="sap.uxap" xmlns:m="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.ui.commons"
xmlns:sap.ui.dt=🢂"sap.ui.dt"🢀>
xmlns:sap.ui.dt="sap.ui.dt">
<m:CheckBox id="dummy-id"></m:CheckBox>
<🢂m:Button🢀>
<m:customData>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 = `
<mvc:View
xmlns:mvc="sap.ui.core.mvc"
xmlns:sap.ui.dt="sap.ui.dt">
</mvc:View>`;

testValidationsScenario({
model: ui5SemanticModel,
xmlText: xmlSnippet,
validators: {
attribute: [validateUnknownXmlnsNamespace],
},
assertion: (issues) => {
expect(issues).to.be.empty;
},
});
});
});
});

0 comments on commit bdcab7d

Please sign in to comment.