Files
lucide/prettier-plugin-lucide-svg.mjs
Karsa 5d36179bf4 feat(ci): added custom prettier plugin for icon SVG files (#4576)
* feat(ci): added custom prettier plugin for icon SVG files

* feat(ci): added custom prettier plugin for icon SVG files

* feat(ci): replace prettier plugin implementation with one based on svgo

* fix(ci): fix linting issues in prettier plugin

* Allow fill in path to fix podcast icon

* Format code

---------

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
2026-07-24 14:23:56 +02:00

75 lines
1.7 KiB
JavaScript

import { optimize } from 'svgo';
const plugin = {
languages: [
{
name: 'Lucide SVG',
parsers: ['lucide-svg'],
extensions: ['.svg'],
vscodeLanguageIds: ['svg'],
},
],
parsers: {
'lucide-svg': {
astFormat: 'lucide-svg',
parse: (path) => path,
locStart: () => 0,
locEnd: () => 0,
},
},
printers: {
'lucide-svg': {
print(path) {
return optimize(path.node, {
multipass: true,
floatPrecision: 3,
plugins: [
'removeDoctype',
'removeComments',
'collapseGroups',
'removeEmptyContainers',
{
name: 'removeAttrs',
params: {
attrs: [
'svg:^(?!(xmlns|width|height|fill|stroke|stroke-linecap|stroke-linejoin|stroke-width)$).+',
'path:^(?!(d|fill)$).+',
'line:^(?!(x1|x2|y1|y2)$).+',
'polygon:^(?!points$).+',
'polyline:^(?!points$).+',
'circle:^(?!(cx|cy|r|fill)$).+',
'ellipse:^(?!(cx|cy|rx|ry)$).+',
'rect:^(?!(x|y|width|height|rx|ry)$).+',
],
},
},
],
js2svg: {
indent: 2,
pretty: true,
useShortTags: true,
finalNewline: true,
},
})
.data.replace(
/<svg[^>]+>/,
`<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>`,
)
.replace(/"\/>/g, `" />`);
},
},
},
};
export default plugin;