mirror of
https://github.com/Mibew/simple-icons.git
synced 2024-11-15 09:54:11 +03:00
Add svg linter to check center (#3250)
This adds a tolerance of +/- 0.001 to either the X or Y dimensions, adjusting the existing ignore list and size linter to fit the new structure of the ignore file. See https://github.com/simple-icons/simple-icons/pull/3107#issuecomment-648089119
This commit is contained in:
parent
4ab6532e18
commit
cc509d9246
File diff suppressed because one or more lines are too long
@ -7,6 +7,7 @@ const svgRegexp = /^<svg( [^\s]*=".*"){3}><title>.*<\/title><path d=".*"\/><\/sv
|
||||
|
||||
const iconSize = 24;
|
||||
const iconFloatPrecision = 3;
|
||||
const iconTolerance = 0.001;
|
||||
const iconIgnored = require("./.svglint-ignored.json");
|
||||
|
||||
module.exports = {
|
||||
@ -58,7 +59,7 @@ module.exports = {
|
||||
reporter.name = "icon-size";
|
||||
|
||||
const iconPath = $.find("path").attr("d");
|
||||
if (iconIgnored.hasOwnProperty(iconPath)) {
|
||||
if (iconIgnored.size.hasOwnProperty(iconPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,6 +81,31 @@ module.exports = {
|
||||
reporter.error("Unexpected character(s), most likely extraneous whitespace, detected in SVG markup");
|
||||
}
|
||||
},
|
||||
function(reporter, $, ast) {
|
||||
reporter.name = "icon-centered";
|
||||
const iconPath = $.find("path").attr("d");
|
||||
const bounds = getBounds(iconPath);
|
||||
|
||||
if (
|
||||
iconIgnored.size.hasOwnProperty(iconPath) ||
|
||||
iconIgnored.center.hasOwnProperty(iconPath)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const targetCenter = iconSize / 2;
|
||||
const centerX = +((bounds.minX + bounds.maxX) / 2).toFixed(iconFloatPrecision);
|
||||
const devianceX = centerX - targetCenter;
|
||||
const centerY = +((bounds.minY + bounds.maxY) / 2).toFixed(iconFloatPrecision);
|
||||
const devianceY = centerY - targetCenter;
|
||||
|
||||
if (
|
||||
Math.abs(devianceX) > iconTolerance ||
|
||||
Math.abs(devianceY) > iconTolerance
|
||||
) {
|
||||
reporter.error(`<path> must be centered at (${targetCenter}, ${targetCenter}); the center is currently (${centerX}, ${centerY})`);
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user