Skip to content

Commit

Permalink
Add linting step for extraneous elements in SVGs (#3239)
Browse files Browse the repository at this point in the history
* Add linting step for extraneous elements in SVGs

... such as a trailing "s" in the Quasar SVG (#3221)

* Remove trailing space from BMC Software icon

* Improve error message for violations

Co-authored-by: Peter Noble <PeterShaggyNoble@users.noreply.github.com>
Co-authored-by: Lucas Becker <runxel@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 22, 2020
1 parent af4024c commit 01221c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .svglintrc.js
Expand Up @@ -3,6 +3,8 @@ const { htmlFriendlyToTitle } = require("./scripts/utils.js");
const getBounds = require("svg-path-bounding-box");

const titleRegexp = /(.+) icon$/;
const svgRegexp = /^<svg.*<\/svg>\r?\n?$/;

const iconSize = 24;
const iconFloatPrecision = 3;
const iconIgnored = require("./.svglint-ignored.json");
Expand Down Expand Up @@ -70,6 +72,14 @@ module.exports = {
reporter.error(`Size of <path> must be exactly ${iconSize} in one dimension; the size is currently ${width} x ${height}`);
}
},
function(reporter, $, ast) {
reporter.name = "extraneous";

const rawSVG = $.html();
if (!svgRegexp.test(rawSVG)) {
reporter.error("Unexpected character(s) detected outside the opening and/or closing <svg> tags");
}
},
]
}
};
2 changes: 1 addition & 1 deletion icons/bmcsoftware.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 01221c0

Please sign in to comment.