prettier --check
See original GitHub issuePlease forgive me if this issue turns out to be a duplicate. I did a couple of searches through other issues (both closed and opened) with some keywords that came to mind and found nothing relevant.
Question
Is there a way to run prettier in a “diagnostic” sort of way where it outputs the issues it finds with your code? The desired result would be something along the lines of what ESLint does. Consider the following screenshot.

Background Info
The reason I’m asking this? I want to make sure all code in my repository is run through a linter and/or style checks pre-commit. However simply running prettier with the --write flag comes with one big issue: https://github.com/okonet/lint-staged/issues/62. In short: Running prettier --write changes the code if it finds an error, this fixed code should be added to the same commit. Simply running git add on the changed file adds all of the contents of that file to the commit, even if you only wanted to commit a part of that file. (Read https://github.com/okonet/lint-staged/issues/62 for details…)
As a workaround I decided that just running all the linters and style-checks would be good enough. If a linter or style check fails the commit won’t be made and the developer can then manually deal with the problems.
I got this part working. Turns out running prettier with the --list-different flag will exit with a non-zero exit code if it finds any problems. On top of that the command will (as the flag suggests) list all of the files that have style problems in them.
But this doesn’t make for the best developer experience. Telling the developer “prettier found some problems” and then just listing a some file(s) seems a bit confusing. Consider the following screenshot.
Hopes and Dreams
In a perfect world I would want prettier to have the option to provide a detailed report of the issues it has found and the rules that are broken.
prettier --check
Alternative
Alternatively I think you could improve the developer experience by adding some format & extra information to what --list-different already does and call that --check. The following code snippet would be an example printout.
prettier --check
Prettier found some issues in the following files:
- somefile.js
- css/styles.css
- README.md
Run 'prettier --fix' to automatically fix these issues.
I know it is possible to add prettier as a plugin for ESLint—but that doesn’t work for all cases, since ESLint only works for JavaScript files (as far as I know) and prettier does more than that.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Related StackOverflow Question
Added in #4914. I guess this issue can be closed then?
precise-commitsdoesn’t solve all my problems—it does solve the problems related to prettier, but not the other linters (that too have--fixlike options). And since I want a unified approach…Anyway,
prettylintseems to do the trick indeed! Thanks! I did a quick search both through the README and the related projects page. Neither of them seems to mentionprettylint. Perhaps it should be added somewhere?