From 39332ee3d040aa74b931c82c327c106eed361f9e Mon Sep 17 00:00:00 2001 From: David Beitey Date: Tue, 23 Jun 2020 23:33:46 +1000 Subject: [PATCH] Add svg linter to check center See https://github.com/simple-icons/simple-icons/pull/3107#issuecomment-648089119 --- .svglintrc.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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}`); + } + } ] } };