Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn if svg uses the viewbox attribute #1077

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/validate/html/validateElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ export default function validateElement(
});
}

if (node.name === 'svg') {
node.attributes.forEach(attribute => {
if (attribute.name === 'viewbox') {
validator.warn(
`<svg> has an invalid viewbox attribute – did you mean viewBox?`,
node.start
)
}
})
}

let hasIntro: boolean;
let hasOutro: boolean;
let hasTransition: boolean;
Expand Down
6 changes: 6 additions & 0 deletions test/validator/samples/svg-viewbox/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<svg viewbox="-250 -250 500 500">
<line x1="0" y1="0" x2="200" y2="0" stroke="black" />
<line x1="0" y1="0" x2="-200" y2="0" stroke="black" />
<line x1="0" y1="0" x2="0" y2="200" stroke="black" />
<line x1="0" y1="0" x2="0" y2="-200" stroke="black" />
</svg>
8 changes: 8 additions & 0 deletions test/validator/samples/svg-viewbox/warnings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"message": "<svg> has an invalid viewbox attribute – did you mean viewBox?",
"loc": {
"line": 1,
"column": 0
},
"pos": 0
}]