Skip to content

fix(migrate): emit a single --check when rewriting prettier scripts#2044

Merged
fengmk2 merged 3 commits into
mainfrom
07-04-fix_migrate_emit_a_single_--check_when_rewriting_prettier_scripts
Jul 4, 2026
Merged

fix(migrate): emit a single --check when rewriting prettier scripts#2044
fengmk2 merged 3 commits into
mainfrom
07-04-fix_migrate_emit_a_single_--check_when_rewriting_prettier_scripts

Conversation

@shulaoda

@shulaoda shulaoda commented Jul 4, 2026

Copy link
Copy Markdown
Member

Problem

When migrating a package.json script, prettier flags are rewritten to vp fmt, converting --list-different / -l / -c to --check. If the script also contained a literal --check, the result depended on the flag order:

input before after
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 (in script_rewrite.rs) converts source flags to the target flag and dedups against a literal dedup_flag. But the dedup branch only set conversion_emitted — it did not drop the literal token or break, so a literal --check that came after a converted flag still fell through to suffix.0.push(item) and was emitted a second time. Only the reverse order (--check first) 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:

if val == conv.dedup_flag {
    // Drop a duplicate if the target flag was already emitted;
    // otherwise keep this one and mark it emitted.
    if conversion_emitted[ci] {
        converted = true;
    } else {
        conversion_emitted[ci] = true;
    }
    break;
}

Now the target flag is emitted exactly once regardless of order. The added break is safe: prettier is the only config with a flag_conversions rule 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_check with the two previously-broken orderings — --list-different --check and the double-literal --check --check — both asserting a single vp fmt --check .. They fail on the old code (duplicate --check) and pass on the fix. The full vite_migration suite stays green (293 passed).

Reproduce

cargo test -p vite_migration --lib \
  prettier::tests::test_rewrite_prettier_list_different_to_check

To see the bug: revert the dedup_flag branch to conversion_emitted[ci] = true; (no break) and rerun — the test fails with left: "vp fmt --check --check .".

@netlify

netlify Bot commented Jul 4, 2026

Copy link
Copy Markdown

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit 5ac7239
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a48ed938b9f350008972bcc

@fengmk2 fengmk2 added test: e2e Auto run e2e tests test: create-e2e Run `vp create` e2e tests labels Jul 4, 2026
@fengmk2 fengmk2 self-assigned this Jul 4, 2026
@fengmk2 fengmk2 merged commit 01360d3 into main Jul 4, 2026
96 checks passed
@fengmk2 fengmk2 deleted the 07-04-fix_migrate_emit_a_single_--check_when_rewriting_prettier_scripts branch July 4, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test: create-e2e Run `vp create` e2e tests test: e2e Auto run e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants