Skip to content

test: migrate print-code tests#43

Merged
fabiospampinato merged 1 commit intoprettier:mainfrom
43081j:test-print-code
Feb 23, 2025
Merged

test: migrate print-code tests#43
fabiospampinato merged 1 commit intoprettier:mainfrom
43081j:test-print-code

Conversation

@43081j
Copy link
Collaborator

@43081j 43081j commented Feb 18, 2025

Copies the print-code tests from prettier.

@fabiospampinato a difference to note here is that prettier ./ignored.js outputs the ignored file's contents in prettier. but in prettier-cli, we ignore it (i.e. output nothing).

it seems this is another special case for when !check && !write && !list

so if you pass a specific file with none of those flags, it should output the file as-is, if it is ignored

Copies the `print-code` tests from prettier.
@fabiospampinato
Copy link
Collaborator

It can make sense to me that if we are explicitly including a file then it shouldn't be ignored no matter what, but what's the point of not even trying to format it? That doesn't seem a useful thing v3 is doing 🤔

I think we could switch to force-enabling explicitly-included files, but still dumping the formatted version to the console, as that looks like a bug in v3 to me. What do you think?

@fabiospampinato
Copy link
Collaborator

Merging, I'll try to take care of that detail 👍

@fabiospampinato fabiospampinato merged commit a18016d into prettier:main Feb 23, 2025
2 checks passed
@fabiospampinato
Copy link
Collaborator

fabiospampinato commented Feb 23, 2025

Ok I've made some changes, in 8ad8648.

  • There's now this internal "dump" mode I had mentioned.
  • In that mode we don't ignore explicitly included files, to match v3.
  • Explicitly included files that are ignored are just included, previously there was this weird behavior where their contents would just get dumped to the terminal, for whatever reason, which seems pointless at best.
  • Updated snapshots to match prettier v3's output, as seen in manual executions, which for some reason the snapshot doesn't seem to match, I don't know what's going on there, but I checked manually and I can't reproduce seeing v3's output as seen in the snapshot 🤷‍♂️

@43081j 43081j deleted the test-print-code branch February 23, 2025 16:12
@43081j
Copy link
Collaborator Author

43081j commented Feb 23, 2025

previously there was this weird behavior where their contents would just get dumped to the terminal, for whatever reason, which seems pointless at best.

i imagine its so if you pipe a bunch of files from a shell glob into prettier, and write them back out, ignored files would be untouched

this kind of thing:

for file in ./src/*
do
  prettier $file > $file
done

and something like ./src/*.test.ts is ignored (but will still be looped through and have prettier executed against). so in those cases, it would've output the original untouched file

@fabiospampinato
Copy link
Collaborator

Interesting 🤔 maybe worth a second look, but that scenario seems a little too niche to me, compared to thinking about it as "if you explicitly tell me to format a file I'll format it", which seems much easier to udnerstand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants