Skip to content

prettier --check #4911

@jessevdp

Description

@jessevdp

Please 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.

image

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: lint-staged/lint-staged#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 lint-staged/lint-staged#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.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.type:questionQuestions and support requests. Please use Stack Overflow for them, not the issue tracker.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions