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 12ccddb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .svglintrc.js
Expand Up @@ -80,6 +80,21 @@ 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);

if (iconIgnored.hasOwnProperty(iconPath)) {
return;
}

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 12ccddb

Please sign in to comment.