6

I'm setting up stylelint for a project, everything works as expected when run from the cli:

$ stylelint 'css/**/*.css' --fix

css/style.css
 20:18  ×  Expected newline after ":" with a multi-line declaration declaration-colon-newline-after
...
...

However, when run as an npm script no output appears (beyond logging the command) and the errors seem to be ignored:

$ npm run stylelint

> project lint:css path/project
> stylelint 'css/**/*.css' --fix    

package.json

  "scripts": {
    ...
    "stylelint": "stylelint 'css/**/*.css' --fix"
  },

Any idea how to get the console output AND exit on errors when stylelint is run as an npm script?

Vinnie James
  • 5,763
  • 6
  • 43
  • 52
  • It actually seems `> stylelint 'css/**/*.css' --fix` doesnt run at all via `npm` regardless of the fact it logs out to the console – Vinnie James Aug 22 '18 at 20:00
  • The issue is with the globstar pattern, as `"stylelint": "stylelint 'css/file.css' --fix"` runs as expected via npm – Vinnie James Aug 22 '18 at 20:07

2 Answers2

8

The issue turned out to be the quotes around the globstar pattern. Most other scripts allow you to wrap the globstar in single quotes ', however stylelint seems to require escaped double quotes:

"stylelint": "stylelint \"src/**/*.css\" --fix"

Vinnie James
  • 5,763
  • 6
  • 43
  • 52
0

Seems like appending ; exit 0 also does the trick:

"stylelint": "stylelint 'css/**/*.css' --fix; exit 0"
sn3p
  • 726
  • 4
  • 13