diff --git a/.svglintrc.js b/.svglintrc.js index 6b248565644a..492213b40b75 100644 --- a/.svglintrc.js +++ b/.svglintrc.js @@ -80,6 +80,17 @@ module.exports = { reporter.error("Unexpected character(s) detected outside the opening and/or closing tags"); } }, + function(reporter, $, ast) { + reporter.name = "icon-centered"; + const iconPath = $.find("path").attr("d"); + const bounds = getBounds(iconPath); + + const centerX = +((bounds.minX + bounds.maxX) / 2).toFixed(iconFloatPrecision) + const centerY = +((bounds.minY + bounds.maxY) / 2).toFixed(iconFloatPrecision) + if (centerX !== iconSize / 2 && centerY !== iconSize / 2) { + reporter.error(` must be centered on the canvas; the center is currently ${centerX} x ${centerY}`); + } + } ] } };