Skip to content

Commit

Permalink
Add svg linter to check center
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjb committed Jun 23, 2020
1 parent 01221c0 commit 39332ee
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .svglintrc.js
Expand Up @@ -80,6 +80,17 @@ module.exports = {
reporter.error("Unexpected character(s) detected outside the opening and/or closing <svg> 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(`<path> must be centered on the canvas; the center is currently ${centerX} x ${centerY}`);
}
}
]
}
};

0 comments on commit 39332ee

Please sign in to comment.