From bc00e20b71b64fe09eef88c44c1824409a2c6d08 Mon Sep 17 00:00:00 2001 From: Emil Ajdyna Date: Fri, 5 Jan 2018 20:46:53 +0100 Subject: [PATCH] Warn if svg uses the viewbox attribute --- src/validate/html/validateElement.ts | 11 +++++++++++ test/validator/samples/svg-viewbox/input.html | 6 ++++++ test/validator/samples/svg-viewbox/warnings.json | 8 ++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/validator/samples/svg-viewbox/input.html create mode 100644 test/validator/samples/svg-viewbox/warnings.json diff --git a/src/validate/html/validateElement.ts b/src/validate/html/validateElement.ts index 2572fd29d40c..16e5e05220e0 100644 --- a/src/validate/html/validateElement.ts +++ b/src/validate/html/validateElement.ts @@ -79,6 +79,17 @@ export default function validateElement( }); } + if (node.name === 'svg') { + node.attributes.forEach(attribute => { + if (attribute.name === 'viewbox') { + validator.warn( + ` has an invalid viewbox attribute – did you mean viewBox?`, + node.start + ) + } + }) + } + let hasIntro: boolean; let hasOutro: boolean; let hasTransition: boolean; diff --git a/test/validator/samples/svg-viewbox/input.html b/test/validator/samples/svg-viewbox/input.html new file mode 100644 index 000000000000..84ab3c11bd6a --- /dev/null +++ b/test/validator/samples/svg-viewbox/input.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/validator/samples/svg-viewbox/warnings.json b/test/validator/samples/svg-viewbox/warnings.json new file mode 100644 index 000000000000..4cb413b730f8 --- /dev/null +++ b/test/validator/samples/svg-viewbox/warnings.json @@ -0,0 +1,8 @@ +[{ + "message": " has an invalid viewbox attribute – did you mean viewBox?", + "loc": { + "line": 1, + "column": 0 + }, + "pos": 0 +}]