I have a script defined in package.json
:
"scripts": {
"prettierCheck": "./node_modules/.bin/prettier --check ./app/javascript/**/*.js"
}
If I run this script using yarn run prettierCheck
, Prettier does not find any formatting issues with my files. However, if I run the Prettier command directly, it finds violating files.
Output of yarn run prettierCheck
:
~/Projects/tome $ yarn run prettierCheck
yarn run v1.19.0
$ ./node_modules/.bin/prettier --check ./app/javascript/**/*.js
Checking formatting...
All matched files use Prettier code style!
Done in 0.20s
Output of ./node_modules/.bin/prettier --check ./app/javascript/**/*.js
:
~/Projects/tome $ ./node_modules/.bin/prettier --check ./app/javascript/**/*.js
Checking formatting...
{... several files listed here ...}
Code style issues found in the above file(s). Forgot to run Prettier?
Why does this happen? What is the difference between running the command directly vs. through a Yarn script?
I had the same issue or at least I thought I had the same issue. I tried a few things like adding quotes to the file/dir/glob in my command, changing my paths/globs & it started working for me because now I could see some useful output. Try these & maybe it'll work for you guys as well.
This is what prettier CLI documentation has to say about paths & file/dir/globs.
Don't forget the quotes around the globs! The quotes make sure that Prettier CLI expands the globs rather than your shell, which is important for cross-platform usage.
So try something like this in your scripts (Note: -c is short for --check)
scripts": {
"pretty-check": "prettier -c 'src/**/*.ts'",
}
Notice the quotes around 'src/**/*.ts'
I'm not sure if this would work for everyone but I'm hoping that it does as it did for me.
And if you are wondering What is file/dir/glob
It's basically the part where you define the regex for your files like the part 'src/**/*.ts'
in the command prettier -c 'src/**/*.ts'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With