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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting step for extraneous elements in SVGs #3239

Merged
merged 4 commits into from Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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("Detected unexpected characters outside the <svg>");
ericcornelissen marked this conversation as resolved.
Show resolved Hide resolved
}
},
]
}
};
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.