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

Add linting for extraneous elements in SVGs #3223

Closed
ericcornelissen opened this issue Jun 15, 2020 · 2 comments · Fixed by #3239
Closed

Add linting for extraneous elements in SVGs #3223

ericcornelissen opened this issue Jun 15, 2020 · 2 comments · Fixed by #3239
Assignees
Labels
meta Issues or pull requests regarding the project or repository itself

Comments

@ericcornelissen
Copy link
Contributor

To prevent issues like #3220. The simplest solution would be to run a regular expression on all SVGs to guarentee they start with <svg and end in </svg> (e.g. ^<svg.*</svg>$). But ideally we include this linting step as a part of svglint, and I'm not sure if that allows us to do such a regular expression.

@ericcornelissen ericcornelissen added the meta Issues or pull requests regarding the project or repository itself label Jun 15, 2020
@PeterShaggyNoble
Copy link
Member

It looks to me like we should be able to do it within custom as both functions in there have the SVG file available via the $ parameter so would it be as simple as adding a new function, passing it the same agrument for the SVG, converting the markup to a string and then running the RegEx validation on it?

Side note: I have been meaning for a while now to run such a RegEx on all our existing icons to take care of a few, other, minor issues I've encountered (e.g., a space before the / in the <path> tag), for the sake of consistency.

@ericcornelissen
Copy link
Contributor Author

It looks to me like we should be able to do it within custom as both functions in there have the SVG file available via the $ parameter so would it be as simple as adding a new function, passing it the same agrument for the SVG, converting the markup to a string and then running the RegEx validation on it?

Definitely, just wasn't 100% sure so I added the caveat to the post 🙂

Side note: I have been meaning for a while now to run such a RegEx on all our existing icons to take care of a few, other, minor issues I've encountered (e.g., a space before the / in the tag), for the sake of consistency.

Good idea, I'd be in favor of that 👍 Perhaps you could open a separate issue for that with a complete list of what you want to test for so there can be proper discussion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Issues or pull requests regarding the project or repository itself
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants