-
Notifications
You must be signed in to change notification settings - Fork 16
/
.svglintrc.js
33 lines (28 loc) · 1.13 KB
/
.svglintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const ignoreFillColors = ['google-color', 'microsoft-color'];
const checkForRootSVG = (reporter, $, ast) => {
Array.from($.find('svg')).forEach((item) => {
reporter.error('Icon SVG files must omit the root <svg> tag.', item, ast);
});
};
const ELEMENTS_ALLOWING_FILL = ['mask'];
const checkForFillAttributes = (reporter, $, ast, info) => {
const filename = info.filepath.split('/').slice(-1)[0];
const isIgnored = ignoreFillColors.includes(filename.split('.')[0]);
if (!isIgnored) {
Array.from($.find('[fill]')).forEach((item) => {
if (item.attribs.fill !== 'none' && !ELEMENTS_ALLOWING_FILL.includes(item.name)) {
// 'none' is necessary to make some icon parts transparent
reporter.error(
`Fill value '${item.attribs.fill}' should only be present if this part of the icon's color is not meant to be controlled by the consumer. If you're sure this icon is using fill attributes appropriately, add it to the fillAllowList in .svglintrc.js.`,
item,
ast
);
}
});
}
};
module.exports = {
rules: {
custom: [checkForRootSVG, checkForFillAttributes],
},
};