fix(migrate): emit a single --check when rewriting prettier scripts#2044
Merged
fengmk2 merged 3 commits intoJul 4, 2026
Merged
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
fengmk2
approved these changes
Jul 4, 2026
…_rewriting_prettier_scripts
…_rewriting_prettier_scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When migrating a
package.jsonscript, prettier flags are rewritten tovp fmt, converting--list-different/-l/-cto--check. If the script also contained a literal--check, the result depended on the flag order:prettier --check --list-different .vp fmt --check .vp fmt --check .prettier --list-different --check .vp fmt --check --check .❌vp fmt --check .prettier --check --check .vp fmt --check --check .❌vp fmt --check .strip_flags_from_suffix(inscript_rewrite.rs) converts source flags to the target flag and dedups against a literaldedup_flag. But the dedup branch only setconversion_emitted— it did not drop the literal token orbreak, so a literal--checkthat came after a converted flag still fell through tosuffix.0.push(item)and was emitted a second time. Only the reverse order (--checkfirst) worked, because the literal was pushed once and the later conversion was suppressed.Fix
Make the dedup branch symmetric — when the token is the literal
dedup_flag:Now the target flag is emitted exactly once regardless of order. The added
breakis safe: prettier is the only config with aflag_conversionsrule and it has exactly one (eslint's is empty), so nothing later in the loop is skipped.Test
Extended
test_rewrite_prettier_list_different_to_checkwith the two previously-broken orderings —--list-different --checkand the double-literal--check --check— both asserting a singlevp fmt --check .. They fail on the old code (duplicate--check) and pass on the fix. The fullvite_migrationsuite stays green (293 passed).Reproduce
cargo test -p vite_migration --lib \ prettier::tests::test_rewrite_prettier_list_different_to_checkTo see the bug: revert the
dedup_flagbranch toconversion_emitted[ci] = true;(nobreak) and rerun — the test fails withleft: "vp fmt --check --check .".