Svgo: run svgo in lint-staged

Created on 28 Mar 2017  Â·  12Comments  Â·  Source: svg/svgo

I have error when start "*.svg": "imgmin" in lint-staged. Only if more than one svg file has been uncommitted.
"scripts": { "imgmin": "svgo -f mySvgFolder", }

How i should add svgo task to lint-staged?
Error appears only if more than one svg file has been uncommitted. With one svg file everything works.

Running tasks for *.svg
→ Unknown argument: ~\mySvgFolder\attention.svg

Most helpful comment

Ah, I get it. Currently SVGO has syntax

svgo <input> <output>

Thus meaning that first file is treated as input, second as output and all other as options. But I wanna change it and now is a good moment for this.

All 12 comments

@GreLI this question is important for my project too

There is no lint option as for now.

@GreLI nope, we didn’t ask about lint option. We said that current CLI API doesn’t allow you to use svgo with lint-staged.

lint-staged is a tool to run any CLI on changed and staged files. The best practice is to use it with ESLint and Stylelint. But linters is not only one way.

For example, you can use lint-staged to sort your CSS properties on commit. Or to unify JS syntax with prettier.

Or, to minify new or changed SVG with svgo.

So we use lint-staged not for linting. But to minify SVG in pre-commit hook.

lint-staged is very popular right now. For example, create-react-app uses it.

CLI problem:

lint-staged runs command -- file1 file2. So of I will change a.svg it will execute svgo -- a.svg. But by some reason svgo will not work as ESLint, Stylelint, postcss-sorting or prettier. By some reason, svgo will not see a.svg and falls with:

Running tasks for *.svg
→ Unknown argument: a.svg

@GreLI is it a error? And how I can integrate SVGO with lint-staged in this case?

I note that if one file is changed, everything is ok. I think we have error because if more than one file they detected like svgo options and we have Unknown argument.

Ah, I get it. Currently SVGO has syntax

svgo <input> <output>

Thus meaning that first file is treated as input, second as output and all other as options. But I wanna change it and now is a good moment for this.

Was also surprized, that I cannot combine svgo and lint-staged.

@GreLI Great, that you wanna change it, maybe you can give a hint, where to start, that I could help.

+1

yay, it works well: 🥇

"public/**/*.svg": [
  "svgo",
  "git add"
],
Was this page helpful?
0 / 5 - 0 ratings

Related issues

SebKay picture SebKay  Â·  5Comments

niftylettuce picture niftylettuce  Â·  4Comments

onlymega picture onlymega  Â·  6Comments

mahnunchik picture mahnunchik  Â·  3Comments

ai picture ai  Â·  5Comments