1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00

Add lint rule to prohibit negative zeros within paths (#4350)

* Add lint to check negative zeros in paths

* Bump minimum NodeJS version to test locally to v12.4.0

* Simplify regular expression

* Add resolution tip to error message

* Convert iterator to array directly

* Improve comment

* Remove GodotEngine from lint ignores file

* Improve resolution tip message if previous character is a number
This commit is contained in:
Álvaro Mondéjar 2020-12-14 20:35:27 +01:00 committed by GitHub
parent da86aafdcc
commit fb2e2b6cd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,7 @@ const { svgPathBbox } = require("svg-path-bbox");
const titleRegexp = /(.+) icon$/;
const svgRegexp = /^<svg( [^\s]*=".*"){3}><title>.*<\/title><path d=".*"\/><\/svg>\r?\n?$/;
const negativeZerosRegexp = /-0(?=[^\.]|[\s\d\w]|$)/g;
const iconSize = 24;
const iconFloatPrecision = 3;
@ -308,6 +309,30 @@ module.exports = {
reporter.error("Unexpected character(s), most likely extraneous whitespace, detected in SVG markup");
}
},
function(reporter, $, ast) {
reporter.name = "negative-zeros";
const iconPath = $.find("path").attr("d");
if (!updateIgnoreFile && isIgnored(reporter.name, iconPath)) {
return;
}
// Find negative zeros inside path
const negativeZeroMatches = Array.from(iconPath.matchAll(negativeZerosRegexp));
if (negativeZeroMatches.length) {
// Calculate the index for each match in the file
const pathDStart = '<path d="';
const svgFileHtml = $.html();
const pathDIndex = svgFileHtml.indexOf(pathDStart) + pathDStart.length;
negativeZeroMatches.forEach((match) => {
const negativeZeroFileIndex = match.index + pathDIndex;
const previousChar = svgFileHtml[negativeZeroFileIndex - 1];
const replacement = "0123456789".includes(previousChar) ? " 0" : "0";
reporter.error(`Found "-0" at index ${negativeZeroFileIndex} (should be "${replacement}")`);
})
}
},
function(reporter, $, ast) {
reporter.name = "icon-centered";

View File

@ -237,7 +237,7 @@ If you have an affiliation to the brand you contributing that allows you to spea
## Testing Package Locally
* Make sure you have [NodeJS](https://nodejs.org/en/download/) installed. At least version 11.15.0 is required.
* Make sure you have [NodeJS](https://nodejs.org/en/download/) installed. At least version 12.4.0 is required.
* Install the dependencies using `$ npm install`.
* Build and test the package using `$ npm test`.
* Run the project linting process using `$ npm run lint`.