mirror of
https://github.com/Mibew/simple-icons.git
synced 2025-02-22 08:54:33 +03:00
Proposal: Check outlying precision while running linter (#3750)
* Check outlying precision while running linter * Prevent reduce error on empty array * Rebase on branch develop * Add svgpath dep * Improve decimal precision verification * Check outlying precision while running linter * Prevent reduce error on empty array * Fix ignored file * Fix reverted dep version * Check decimal according to review proposal * Pin svgpath version * Use te maximum precision only * Run linter again * Fix uglify-js version * Add supported engines to package.json * Improve message * Revert engines and use version check in linter * Move function * Update node version to 12 in Travis * Add skip ignored
This commit is contained in:
parent
3ff22a7cf6
commit
9cee719fcb
File diff suppressed because one or more lines are too long
@ -3,12 +3,14 @@ const fs = require('fs');
|
|||||||
const data = require("./_data/simple-icons.json");
|
const data = require("./_data/simple-icons.json");
|
||||||
const { htmlFriendlyToTitle } = require("./scripts/utils.js");
|
const { htmlFriendlyToTitle } = require("./scripts/utils.js");
|
||||||
const getBounds = require("svg-path-bounding-box");
|
const getBounds = require("svg-path-bounding-box");
|
||||||
|
const parsePath = require("svgpath/lib/path_parse");
|
||||||
|
|
||||||
const titleRegexp = /(.+) icon$/;
|
const titleRegexp = /(.+) icon$/;
|
||||||
const svgRegexp = /^<svg( [^\s]*=".*"){3}><title>.*<\/title><path d=".*"\/><\/svg>\r?\n?$/;
|
const svgRegexp = /^<svg( [^\s]*=".*"){3}><title>.*<\/title><path d=".*"\/><\/svg>\r?\n?$/;
|
||||||
|
|
||||||
const iconSize = 24;
|
const iconSize = 24;
|
||||||
const iconFloatPrecision = 3;
|
const iconFloatPrecision = 3;
|
||||||
|
const iconMaxFloatPrecision = 5;
|
||||||
const iconTolerance = 0.001;
|
const iconTolerance = 0.001;
|
||||||
|
|
||||||
// set env SI_UPDATE_IGNORE to recreate the ignore file
|
// set env SI_UPDATE_IGNORE to recreate the ignore file
|
||||||
@ -30,6 +32,11 @@ function sortObjectByValue(obj) {
|
|||||||
.reduce((r, k) => Object.assign(r, { [k]: obj[k] }), {});
|
.reduce((r, k) => Object.assign(r, { [k]: obj[k] }), {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Array.prototype.flat === undefined) {
|
||||||
|
console.error(`Minimum NodeJS v11.15.0 is required, but you are running ${process.version}.`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (updateIgnoreFile) {
|
if (updateIgnoreFile) {
|
||||||
process.on('exit', () => {
|
process.on('exit', () => {
|
||||||
// ensure object output order is consistent due to async svglint processing
|
// ensure object output order is consistent due to async svglint processing
|
||||||
@ -129,6 +136,38 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
function(reporter, $, ast) {
|
||||||
|
reporter.name = "icon-precision";
|
||||||
|
|
||||||
|
const iconPath = $.find("path").attr("d");
|
||||||
|
if (!updateIgnoreFile && isIgnored(reporter.name, iconPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { segments } = parsePath(iconPath);
|
||||||
|
const segmentParts = segments.flat().filter((num) => (typeof num === 'number'));
|
||||||
|
|
||||||
|
const countDecimals = (num) => {
|
||||||
|
if (num && num % 1) {
|
||||||
|
let [base, op, trail] = num.toExponential().split(/e([+-])/);
|
||||||
|
let elen = parseInt(trail, 10);
|
||||||
|
let idx = base.indexOf('.');
|
||||||
|
return idx == -1 ? elen : base.length - idx - 1 + (op === '+' ? -elen : elen);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
const precisionArray = segmentParts.map(countDecimals);
|
||||||
|
const precisionMax = precisionArray && precisionArray.length > 0 ?
|
||||||
|
Math.max(...precisionArray) :
|
||||||
|
0;
|
||||||
|
|
||||||
|
if (precisionMax > iconMaxFloatPrecision) {
|
||||||
|
reporter.error(`Maximum precision should not be greater than ${iconMaxFloatPrecision}; it is currently ${precisionMax}`);
|
||||||
|
if (updateIgnoreFile) {
|
||||||
|
ignoreIcon(reporter.name, iconPath, $);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
function(reporter, $, ast) {
|
function(reporter, $, ast) {
|
||||||
reporter.name = "extraneous";
|
reporter.name = "extraneous";
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ jobs:
|
|||||||
- stage: "Test"
|
- stage: "Test"
|
||||||
name: "Lint"
|
name: "Lint"
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: 10
|
node_js: 12
|
||||||
git:
|
git:
|
||||||
depth: 1
|
depth: 1
|
||||||
script:
|
script:
|
||||||
@ -27,7 +27,7 @@ jobs:
|
|||||||
- jekyll build
|
- jekyll build
|
||||||
- name: "Test package"
|
- name: "Test package"
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: 10
|
node_js: 12
|
||||||
git:
|
git:
|
||||||
depth: 1
|
depth: 1
|
||||||
script:
|
script:
|
||||||
@ -51,7 +51,7 @@ jobs:
|
|||||||
cleanup: false
|
cleanup: false
|
||||||
- name: "NPM Package"
|
- name: "NPM Package"
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js: 10
|
node_js: 12
|
||||||
git:
|
git:
|
||||||
depth: 1
|
depth: 1
|
||||||
if: branch = master
|
if: branch = master
|
||||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -7014,9 +7014,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"svgpath": {
|
"svgpath": {
|
||||||
"version": "2.2.3",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/svgpath/-/svgpath-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/svgpath/-/svgpath-2.3.0.tgz",
|
||||||
"integrity": "sha512-xA0glXYpJ9SYT4JeMp3c0psbqdZsG1c0ywGvdJUPY2FKEgwJV7NgkeYuuQiOxMp+XsK9nCqjm3KDw0LkM1YLXw==",
|
"integrity": "sha512-N/4UDu3Y2ICik0daMmFW1tplw0XPs1nVIEVYkTiQfj9/JQZeEtAKaSYwheCwje1I4pQ5r22fGpoaNIvGgsyJyg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"symbol-tree": {
|
"symbol-tree": {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
"svg-path-bounding-box": "1.0.4",
|
"svg-path-bounding-box": "1.0.4",
|
||||||
"svglint": "1.0.6",
|
"svglint": "1.0.6",
|
||||||
"svgo": "1.3.2",
|
"svgo": "1.3.2",
|
||||||
|
"svgpath": "2.3.0",
|
||||||
"uglify-js": "3.11.6"
|
"uglify-js": "3.11.6"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
Reference in New Issue
Block a user