mirror of
https://github.com/Mibew/simple-icons.git
synced 2024-11-16 02:14:12 +03:00
287317b7b6
* Add custom SVGLint rule to lint the general <title> format i.e. the <title> should be "[ICON_NAME] icon" * Check if there exists an entry in simple-icons.json with the icon name ... found in the <title> * Normalize all icons <title> value * Fix mismatch between HTML's icon title and simple-icons.json title ... due to HTML special entities (such as `&`). Affected icons: - AT&T (AT&T) - Let's Encrypt (Let's Encrypt) * Refactor .svglintrc.js to make the code style more in line with scripts/prepublish.js * Add SVG with invalid <title> format * Add SVG with unknown title * Revert 6912816 and f002504
52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
const data = require("./_data/simple-icons.json");
|
|
const { htmlFriendlyToTitle } = require("./scripts/utils.js");
|
|
|
|
const titleRegexp = /(.+) icon$/;
|
|
|
|
module.exports = {
|
|
rules: {
|
|
elm: {
|
|
"svg": 1,
|
|
"svg > title": 1,
|
|
"svg > path": 1,
|
|
"*": false,
|
|
},
|
|
attr: [
|
|
{ // ensure that the SVG elm has the appropriate attrs
|
|
"role": "img",
|
|
"viewBox": "0 0 24 24",
|
|
"xmlns": "http://www.w3.org/2000/svg",
|
|
|
|
"rule::selector": "svg",
|
|
"rule::whitelist": true,
|
|
},
|
|
{ // ensure that the title elm has the appropriate attr
|
|
"rule::selector": "svg > title",
|
|
"rule::whitelist": true,
|
|
},
|
|
{ // ensure that the path element only has the 'd' attr (no style, opacity, etc.)
|
|
"d": /^[,a-zA-Z0-9\. -]+$/,
|
|
"rule::selector": "svg > path",
|
|
"rule::whitelist": true,
|
|
}
|
|
],
|
|
custom: [
|
|
function(reporter, $, ast) {
|
|
const iconTitleText = $.find("title").text();
|
|
if (!titleRegexp.test(iconTitleText)) {
|
|
reporter.error("<title> should follow the format \"[ICON_NAME] icon\"");
|
|
} else {
|
|
const titleMatch = iconTitleText.match(titleRegexp);
|
|
// titleMatch = [ "[ICON_NAME] icon", "[ICON_NAME]" ]
|
|
const rawIconName = titleMatch[1];
|
|
const iconName = htmlFriendlyToTitle(rawIconName);
|
|
const icon = data.icons.find(icon => icon.title === iconName);
|
|
if (icon === undefined) {
|
|
reporter.error(`No icon with title "${iconName}" found in simple-icons.json`);
|
|
}
|
|
}
|
|
},
|
|
]
|
|
}
|
|
};
|