Add linting step for extraneous elements in SVGs (#3239)

* 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>
This commit is contained in:
Eric Cornelissen 2020-06-22 19:24:56 +03:00 committed by GitHub
parent af4024cc4c
commit 01221c047d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -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");
@ -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");
}
},
]
}
};

View file

@ -1 +1 @@
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>BMC Software icon</title><path d="M6.389 23.97c-.948 0-1.946-.747-1.946-2.194v-3.392c0-1.346.848-2.892 2.045-3.54l4.739-2.794-4.739-2.793c-1.147-.749-2.045-2.245-2.045-3.592V2.224C4.443.777 5.441.029 6.44.029c.399 0 .847.1 1.246.35L18.36 6.712c.748.449 1.147 1.147 1.147 1.845 0 .749-.45 1.447-1.147 1.846L15.816 11.9l2.544 1.497c.748.449 1.197 1.147 1.197 1.845 0 .748-.45 1.447-1.197 1.846L7.685 23.622c-.448.25-.847.349-1.296.349zm7.132-10.573l-5.836 3.441c-.448.25-.897 1.048-.897 1.546v3.043l10.125-5.985zM6.788 2.623v3.042c0 .5.449 1.297.897 1.547l5.836 3.441 3.442-2.045z"/></svg>
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>BMC Software icon</title><path d="M6.389 23.97c-.948 0-1.946-.747-1.946-2.194v-3.392c0-1.346.848-2.892 2.045-3.54l4.739-2.794-4.739-2.793c-1.147-.749-2.045-2.245-2.045-3.592V2.224C4.443.777 5.441.029 6.44.029c.399 0 .847.1 1.246.35L18.36 6.712c.748.449 1.147 1.147 1.147 1.845 0 .749-.45 1.447-1.147 1.846L15.816 11.9l2.544 1.497c.748.449 1.197 1.147 1.197 1.845 0 .748-.45 1.447-1.197 1.846L7.685 23.622c-.448.25-.847.349-1.296.349zm7.132-10.573l-5.836 3.441c-.448.25-.897 1.048-.897 1.546v3.043l10.125-5.985zM6.788 2.623v3.042c0 .5.449 1.297.897 1.547l5.836 3.441 3.442-2.045z"/></svg>

Before

Width:  |  Height:  |  Size: 667 B

After

Width:  |  Height:  |  Size: 666 B