diff --git a/.github/workflows/lint-code.yml b/.github/workflows/lint-code.yml index f2aeefc1b..8fb9a83d5 100644 --- a/.github/workflows/lint-code.yml +++ b/.github/workflows/lint-code.yml @@ -1,9 +1,7 @@ -name: Linting PR +name: Linting PR code on: pull_request: - paths-ignore: - - icons/*.svg jobs: lint-code: diff --git a/.github/workflows/lint-pr-title.yml b/.github/workflows/lint-pr-title.yml index d5f7ce8a3..a336a39a5 100644 --- a/.github/workflows/lint-pr-title.yml +++ b/.github/workflows/lint-pr-title.yml @@ -1,4 +1,4 @@ -name: Linting PR +name: Linting PR title on: pull_request: diff --git a/icons/a-large-small.svg b/icons/a-large-small.svg index 2ea7f7f03..bc1ea1278 100644 --- a/icons/a-large-small.svg +++ b/icons/a-large-small.svg @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/icons/ambulance.svg b/icons/ambulance.svg index c192da79c..7e08bedb2 100644 --- a/icons/ambulance.svg +++ b/icons/ambulance.svg @@ -11,10 +11,9 @@ > - + - \ No newline at end of file + diff --git a/icons/bone-fracture.svg b/icons/bone-fracture.svg index fc839a13a..cc7f42ee8 100644 --- a/icons/bone-fracture.svg +++ b/icons/bone-fracture.svg @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/icons/bot-off.svg b/icons/bot-off.svg index 273dac52b..77b973b67 100644 --- a/icons/bot-off.svg +++ b/icons/bot-off.svg @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/icons/captions.svg b/icons/captions.svg index fdf03617b..ae7335a42 100644 --- a/icons/captions.svg +++ b/icons/captions.svg @@ -11,4 +11,4 @@ > - \ No newline at end of file + diff --git a/icons/circle-fading-plus.svg b/icons/circle-fading-plus.svg index 16be9dcff..5c9ef7499 100644 --- a/icons/circle-fading-plus.svg +++ b/icons/circle-fading-plus.svg @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/icons/diamond-minus.svg b/icons/diamond-minus.svg index ac6b36e4a..e71cf8bf8 100644 --- a/icons/diamond-minus.svg +++ b/icons/diamond-minus.svg @@ -11,4 +11,4 @@ > - \ No newline at end of file + diff --git a/icons/diamond-plus.svg b/icons/diamond-plus.svg index 2e2b72157..d4d968727 100644 --- a/icons/diamond-plus.svg +++ b/icons/diamond-plus.svg @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/icons/flag-triangle-left.svg b/icons/flag-triangle-left.svg index b999166a4..e9aea9403 100644 --- a/icons/flag-triangle-left.svg +++ b/icons/flag-triangle-left.svg @@ -10,4 +10,4 @@ stroke-linejoin="round" > - \ No newline at end of file + diff --git a/icons/gamepad-directional.svg b/icons/gamepad-directional.svg index f7626066b..f61cdafdf 100644 --- a/icons/gamepad-directional.svg +++ b/icons/gamepad-directional.svg @@ -9,12 +9,8 @@ stroke-linecap="round" stroke-linejoin="round" > - - - - + + + + diff --git a/icons/git-merge-conflict.svg b/icons/git-merge-conflict.svg index d89792893..be617b12e 100644 --- a/icons/git-merge-conflict.svg +++ b/icons/git-merge-conflict.svg @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/icons/id-card-lanyard.svg b/icons/id-card-lanyard.svg index 019196180..0cc2e7545 100644 --- a/icons/id-card-lanyard.svg +++ b/icons/id-card-lanyard.svg @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/icons/keyboard-off.svg b/icons/keyboard-off.svg index ace95b8ab..01810b422 100644 --- a/icons/keyboard-off.svg +++ b/icons/keyboard-off.svg @@ -19,4 +19,4 @@ - \ No newline at end of file + diff --git a/icons/layers-plus.svg b/icons/layers-plus.svg index 55df36544..390770e61 100644 --- a/icons/layers-plus.svg +++ b/icons/layers-plus.svg @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/icons/lens-convex.svg b/icons/lens-convex.svg index 0f7b5540a..40fb9f9f7 100644 --- a/icons/lens-convex.svg +++ b/icons/lens-convex.svg @@ -9,6 +9,5 @@ stroke-linecap="round" stroke-linejoin="round" > - + diff --git a/icons/line-squiggle.svg b/icons/line-squiggle.svg index 68bc86948..dd6e1c810 100644 --- a/icons/line-squiggle.svg +++ b/icons/line-squiggle.svg @@ -10,4 +10,4 @@ stroke-linejoin="round" > - \ No newline at end of file + diff --git a/icons/mirror-rectangular.svg b/icons/mirror-rectangular.svg index f2c650a65..eeec365f1 100644 --- a/icons/mirror-rectangular.svg +++ b/icons/mirror-rectangular.svg @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/icons/mirror-round.svg b/icons/mirror-round.svg index e818e7d0e..5039ed965 100644 --- a/icons/mirror-round.svg +++ b/icons/mirror-round.svg @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/icons/pilcrow-right.svg b/icons/pilcrow-right.svg index 8266db1e6..9c09eb396 100644 --- a/icons/pilcrow-right.svg +++ b/icons/pilcrow-right.svg @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/icons/scooter.svg b/icons/scooter.svg index c0d71ca91..21b2ac734 100644 --- a/icons/scooter.svg +++ b/icons/scooter.svg @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/icons/search-alert.svg b/icons/search-alert.svg index 310cb5c47..d78c1c05e 100644 --- a/icons/search-alert.svg +++ b/icons/search-alert.svg @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/icons/spline-pointer.svg b/icons/spline-pointer.svg index 1c6ba848c..8ae62d18a 100644 --- a/icons/spline-pointer.svg +++ b/icons/spline-pointer.svg @@ -13,4 +13,4 @@ - \ No newline at end of file + diff --git a/icons/square-arrow-right-enter.svg b/icons/square-arrow-right-enter.svg index 530df0415..91c409af0 100644 --- a/icons/square-arrow-right-enter.svg +++ b/icons/square-arrow-right-enter.svg @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/icons/square-arrow-right-exit.svg b/icons/square-arrow-right-exit.svg index 352aad17c..9dd4958a3 100644 --- a/icons/square-arrow-right-exit.svg +++ b/icons/square-arrow-right-exit.svg @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/icons/square-off.svg b/icons/square-off.svg index 9c0edb834..c8023273d 100644 --- a/icons/square-off.svg +++ b/icons/square-off.svg @@ -12,4 +12,4 @@ - \ No newline at end of file + diff --git a/icons/squares-exclude.svg b/icons/squares-exclude.svg index f22b12464..e2569c64f 100644 --- a/icons/squares-exclude.svg +++ b/icons/squares-exclude.svg @@ -11,4 +11,4 @@ > - \ No newline at end of file + diff --git a/icons/squares-intersect.svg b/icons/squares-intersect.svg index 36449b9b2..485f30cbe 100644 --- a/icons/squares-intersect.svg +++ b/icons/squares-intersect.svg @@ -20,4 +20,4 @@ - \ No newline at end of file + diff --git a/icons/squares-subtract.svg b/icons/squares-subtract.svg index 6fff715d5..8dbd9db10 100644 --- a/icons/squares-subtract.svg +++ b/icons/squares-subtract.svg @@ -15,4 +15,4 @@ - \ No newline at end of file + diff --git a/icons/squares-unite.svg b/icons/squares-unite.svg index f70bdc2b2..b8b0c25b9 100644 --- a/icons/squares-unite.svg +++ b/icons/squares-unite.svg @@ -10,4 +10,4 @@ stroke-linejoin="round" > - \ No newline at end of file + diff --git a/icons/toilet.svg b/icons/toilet.svg index 9ce94841f..102497183 100644 --- a/icons/toilet.svg +++ b/icons/toilet.svg @@ -11,4 +11,4 @@ > - \ No newline at end of file + diff --git a/icons/truck.svg b/icons/truck.svg index cef64e21b..57e03d6c9 100644 --- a/icons/truck.svg +++ b/icons/truck.svg @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/icons/van.svg b/icons/van.svg index e605e5f4b..d3e54102e 100644 --- a/icons/van.svg +++ b/icons/van.svg @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/lint-staged.config.mjs b/lint-staged.config.mjs index 2b580d645..d1afb395d 100644 --- a/lint-staged.config.mjs +++ b/lint-staged.config.mjs @@ -6,9 +6,10 @@ const filenamesToAjvOption = (filenames) => filenames.map((filename) => `-d ${fi /** @satisfies {import('lint-staged').Config} */ const config = { - 'icons/*.svg': [ + 'icons/*.svg': (filenames) => [ 'node ./scripts/optimizeStagedSvgs.mts', 'node ./scripts/generateNextJSAliases.mts', + `prettier --write ${filenames.join(' ')}`, ], 'icons/*.json': (filenames) => [ `ajv --spec=draft2020 -s icon.schema.json ${filenamesToAjvOption(filenames)}`, diff --git a/package.json b/package.json index bc7a72480..c12a290d6 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,12 @@ "lint:es": "eslint .", "lint:format": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --check", "lint:format-fix": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --write", + "lint:icons": "prettier \"icons/*.svg\" --check", + "lint:icons-fix": "prettier \"icons/*.svg\" --write", "lint:json:icons": "ajv --spec=draft2020 -s icon.schema.json -d 'icons/*.json' > /dev/null", "lint:json:categories": "ajv --spec=draft2020 -s category.schema.json -d 'categories/*.json' > /dev/null", "lint:json": "pnpm run lint:json:icons && pnpm run lint:json:categories", - "lint": "pnpm lint:es && pnpm lint:format && pnpm lint:json", + "lint": "pnpm lint:es && pnpm lint:format && pnpm lint:json && pnpm lint:icons", "format": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --write", "prepare": "husky install", "gi": "node ./scripts/generate/generateIcons.mts", diff --git a/prettier-plugin-lucide-svg.mjs b/prettier-plugin-lucide-svg.mjs new file mode 100644 index 000000000..ed614dd3d --- /dev/null +++ b/prettier-plugin-lucide-svg.mjs @@ -0,0 +1,74 @@ +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( + /]+>/, + ``, + ) + .replace(/"\/>/g, `" />`); + }, + }, + }, +}; + +export default plugin; diff --git a/prettier.config.mjs b/prettier.config.mjs index ecdf22fcd..03d8f34f3 100644 --- a/prettier.config.mjs +++ b/prettier.config.mjs @@ -1,5 +1,6 @@ /** @satisfies {import('prettier').Config} */ const config = { + plugins: ['./prettier-plugin-lucide-svg.mjs'], singleQuote: true, trailingComma: 'all', printWidth: 100, @@ -11,6 +12,12 @@ const config = { printWidth: 0, }, }, + { + files: ['icons/*.svg'], + options: { + parser: 'lucide-svg', + }, + }, ], };