-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add diff in output of --check (for CI use cases) #6885
Comments
"Forgot to run Prettier?" is really not a very helpful message... |
The message contains the file names. What else do you need to run Prettier on those files? |
I personally like the output of CI: "Forgot to run Prettier?" Me: "Oh yeah, I guess I did!" Runs Prettier. CI: "All good!" |
I like to point again to:
That means they have no local IDE installed. That's why they can not run prettier on the file. |
Expected behavior would be a detailed error message or a diff
|
Why not run |
thx. I would try on monday the output of |
@muescha I think this proposal might be solving your problem the wrong way. Forcing people to click into a CI build log, find diffs of expected output and then manually applying them does no sound very friendly. I think we could try several other things:
|
thats much overhead :(
it should run normal prettier
this is only the solution for one user, and not for all
this changes the PR - the user should have information about the problems
to much overhead to checkout a branch etc
also prettier is a good help the only thing is that there should be an more verbose error message :/ |
Thanks for the responses! You didn’t seem to respond to this one, though:
Thoughts? |
since they edit the PR on github and check why the CI build is failing they already looking into the CI logs. and then when they only find a not helpful message - that is frustrating. example gatsbyjs/gatsby#18719 (comment)
|
I was making changes to a repository that'd had prettier added to it without me realising, but I had not installed it in my local development environment. So naturally it blew up in CI and asked if I'd "forgotten to run prettier". But that message came from a program called "prettier", which was pretty confusing - yes I suppose I'd "forgotten" to run prettier (I hadn't actually, I didn't even know I had to. Unnecessarily snarky error message, if you ask me...) but even more annoying was that the prettier program was printing that message!
|
@dylannz-sailthru Would you really prefer to get a diff instead like @muescha has proposed and apply it manually instead of running the formatter? |
I admit, I've now set up my IDE with prettier and now it doesn't bother me. But it seems there is a use case where someone wants to make a small change and doesn't have prettier installed (either on GitHub or in a local development environment), adds an extra space somewhere, and now has to install a 3rd party program and run it instead of just fixing a small error. And while I'll admit it's a narrow use case, I can't see much of a downside to being more verbose (or at least having a configurable verbose flag). Most CI tools will collapse each CI step so you can view the logs of each one in isolation. |
example where i used the GitHub editor and i get for this change gatsbyjs/gatsby@7b78781 in gatsbyjs/gatsby#19822 this CI log message: now i have to checkout ~500MB data from pull request, install prettier only just to see whats wrong in this commit and i can change the file? |
@dylannz-sailthru Locally, extra setup isn't needed. Prettier is installed as a dev dependency and there is usually a command in the project to run all the linters, formatters, etc. (e.g. |
Sorry, the message is actually not supposed to be snarky, but friendly! Do you have ideas for better wording?
I don’t think that’s a good example. That’s not a markdown change, but a code change! Is that really something people do in the browser? That sounds terrible to me – how do you debug and test then? Here’s yet one idea: When editing a markdown file in the GitHub editor and are about to hit the Commit button – first copy-paste the entire file into https://prettier.io/playground/ and then copy back the output. |
yes - people do it. so why not also on all files.
that maybe a workaround but not a solution and also not fit with the project settings for prettier |
Sure! Something like: This way it's telling me more specifically what I need to do to get past the error. I think it doesn't matter so much for people who have used
Actually that'd be a great thing to link to in the error message as well - I'd have found it really useful at the time :) |
This comment has been minimized.
This comment has been minimized.
I would also like to see a diff or more detailed information about why prettier thinks a file isn't formatted. I currently don't run |
@grncdr It tells you which files aren’t formatted, so all you need to do is run Prettier on those files. Or on your whole project – probably |
I found, that sometimes there are false positives or new situations where you do not want the code formatted like that. There is no way, that #12598 would solve the conflict. It does not modify the default "way" of prettier. |
Struggling with an issue where locally running I think this is definitely an example of a legit use case for getting a diff printout straight from Prettier. Yes, it can be achieved with a combination of |
Oh man, this is happening to me now. It only happens for tsconfig.json files too! Not sure why. EDIT: looks like it's been fixed in 3.2.5, thanks! @joonashak |
I don't even want this for CI usecases, I'm just trying out prettier and want to see what it'll do to my code before I clobber it all. I could try to figure out the right incantations to get git to stash the changes I'm working on atm without stashing the prettier config itself, etc etc, so that git can revert --write's changes if I don't like them but it's a little silly that there's not just a dry run option in prettier itself. :x |
@mesmere have you considered to opt out prettier? |
@alexey-sh BLASPHEMER!! 😂🙃 Another option would be to use the eslint plugin, which I think will show the errors when you run it through that? https://github.com/prettier/eslint-plugin-prettier |
I want to note that some folks feel that integrating Prettier into your linter is suboptimal:
IMHO, whatever works best for your workflow is what you should do. I don't know if there's a perfect answer here, but using the eslint-plugin-prettier, as suggested above, will get you what you're looking for. I would not expect the Prettier team to integrate this functionality; it feels quite intentional. |
Is there at least an explanation why the Prettier team doesn't want to add I understand that Prettier is built with certain philosophy in mind, but there were some pretty valid points in this thread why one would benefit from verbose explanation of style errors. |
The normal output is not helpful, see also: prettier/prettier#6885
The normal output is not helpful, see also: prettier/prettier#6885
Hello @lydell, It appears that @muescha has stopped the fight... In one of your reply you said :
There are plenty of people who work in this way, what's the matter? But this is not the only one use case. When you use a linter collection app like the GitHub super-linter. What if you would rather not install it in your environment for security reason or simply to not handle updates... What if you check not yet committed code, you may not want to have some changes done from a linter. |
@lvjp I wrote that 5 years ago. Since then I’ve changed my mind: #6885 (comment) (You might also have noticed that I’m not actively involved with this project anymore.) |
I remain ready to rebase and fix up the PR for this once someone with merge access commits to reviewing it 🫡 |
@Osmose > can you add the link to the PR here ? |
Bumping @george-gca's solution from January 2024 as it works great for me, seems to be the best workaround available, and didn't get any attention. I adapted the PR pipeline as that fits my workflow best. In my case, the issue was that git was replacing LF with CRLF. I should've figured as much, but without this tool it was a blind search (git wasn't warning me on my local machine). Ref sample run: https://github.com/mark-wiemer-org/vscode-autohotkey2-lsp/actions/runs/11063073280/job/30738602614?pr=29. I've also adapted the code to my repo and removed some emojis and shopify stuff for simplicity and better practice: https://github.com/mark-wiemer-org/vscode-autohotkey2-lsp/actions/runs/11063073280/workflow?pr=29
|
In short, the best workaround I've found is to run |
@mark-wiemer out of curiosity, what's the benefit of doing to do a git diff over just using one of the prettier lint plugins? |
I'm fine to add diff, but better to implement it as a "report", user can choose how the result to be reported. |
@webark I'm no prettier expert--if you find something that works and you like it, go for it. Personally I lint my code for everything except formatting, so I'm not the guy to ask. I found (same person, now my work acct) |
If you need Prettier for CI cases, one option I just found out is pr-prettier. Apparently it can add a commit to a PR with the prettified code. |
More people submit PR for documents in Markdown files or other things via Github web editor. If they make a mistake then the CI fails but there is no chance to inform the user whats wrong.
I see some infos should be with the
--debug-check
but currently there is no output with this option.Environments:
Steps to reproduce:
Expected behavior:
Show each error and the changes like with
--debug-check
here in #4415Actual behavior:
Show nothing about the errors:
Also there are no more infos available with this commands:
The text was updated successfully, but these errors were encountered: