prettier / prettier

Prettier is an opinionated code formatter.
https://prettier.io
MIT License
49.51k stars 4.38k forks source link

`--write` to output names of unchanged files in `--log-level debug` only #15480

Open ADTC opened 1 year ago

ADTC commented 1 year ago

Note: This issue was split from #15396.

The output of --write is too verbose, as it lists all files being read, instead of files being written.

Suggestion: Reduce verbosity.

I believe in --log-level log (the default level), the log should only output names of files that actually changed. So if a file remains the same and isn't overwritten with a formatted version, its file name should only be output in --log-level debug.

This will reduce the default verbosity of the --write option unless the full verbosity is requested using --log-level debug. Most times the users would only want to know what files were rewritten using the --write command, not the full list of files read. Only those trying to debug why a given file is not being formatted by Prettier would want to inspect the debug output which includes the list of files being read.

Example demonstrating suggestion

Take two exact copies of a project with three files, only the second of which will change in formatting.

With the current version of Prettier, running npx/yarn prettier --write . on first copy:

path/to/file1.ext 1ms
path/to/file2.ext 5ms
path/to/file3.ext 0ms (cached)

(can't show color but you can imagine it: file1 and file3 will be grey)

With a fixed version of Prettier, running npx/yarn prettier --write . on second copy:

path/to/file2.ext 5ms

Relevant information

Relevant code:

https://github.com/prettier/prettier/blob/f7959cccbfaf38f685b660f39eed061f5eec5ec2/src/cli/format.js#L432-L441

Relevant issues:

This was kind of hinted before in #3525 but apparently misunderstood. I believe the original author there possibly couldn't see the grey vs white distinction because the terminal didn't support colors, and everything was in the same color. This may have led to the false impression that all files are being overwritten when in reality, all filenames were being output to log, but only changed files were overwritten.

Discussions about verbosity have also occurred recently, such as in #13480.

I can open a pull request

I believe both suggestions can be achieved with a simple change:

Just let me know if the suggestions are acceptable.

bobby-driggs commented 10 months ago

Love this - Another option / avenue would be to include a separate verbosity flag for the write option, that would include all touched / read files, vs written.

jebarpg commented 10 months ago

I would like this implemented as well.. when will we see this added?

jebarpg commented 10 months ago

my current solution for this is prettier --write . | grep -v \"unchanged\" | xargs if anyone needs a solution without this feature being added to the main repo.

ADTC commented 10 months ago

Seems like this is popular. What could be blocking us from adding this feature? @sosukesuzuki

AncientSwordRage commented 5 months ago

Came looking to raise this as well, I'd be happy with either option (change the existing cli option, or add a new one)

mironbalcerzak commented 2 weeks ago

bump

Sicria commented 2 weeks ago

I've found adding --log-level warn has resolved this for me.

ADTC commented 2 weeks ago

@Sicria I think that doesn't show changed files as well.

Guilderm commented 2 weeks ago

--log-level warn

same here, "prettier --write . --log-level warn" partialy solves the problem for me in that it is not as noisy, however files that are formatead are not log. I ask ChatGTP, and this works for me on my windows box " "prettier --write . | findstr /V \"(unchanged)\"""

I do believe that @ADTC observation are correct, and the default level should only log files that are changed.

Guilderm commented 2 weeks ago

--log-level warn

same here, "prettier --write . --log-level warn" partialy solves the problem for me in that it is not as noisy, however files that are formatead are not log. I ask ChatGTP, and this works for me on my windows box " "prettier --write . | findstr /V \"(unchanged)\"""

I do believe that @ADTC observation are correct, and the default level should only log files that are change.