-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy path.svglintrc.js
More file actions
38 lines (33 loc) · 1.18 KB
/
.svglintrc.js
File metadata and controls
38 lines (33 loc) · 1.18 KB
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
34
35
36
37
38
const ignoreFillColors = [
'google-color',
'microsoft-color',
'notification-unread',
'research-tool',
];
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],
},
};