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 getBounds = require("svg-path-bounding-box");
const titleRegexp = /(.+) icon$/; const titleRegexp = /(.+) icon$/;
const svgRegexp = /^<svg.*<\/svg>\r?\n?$/;
const iconSize = 24; const iconSize = 24;
const iconFloatPrecision = 3; const iconFloatPrecision = 3;
const iconIgnored = require("./.svglint-ignored.json"); 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}`); 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");
}
},
] ]
} }
}; };