Skip to content

Commit afaca70

Browse files
cknittclaude
andauthored
Leave files untouched when no migration applies (#8922)
* Leave files untouched when no migration applies `rescript-tools migrate` and `migrate-all` reprinted every file whose printed form differed from the source, so files without any migration were reformatted and reported as migrated. A file is now reprinted only when the migration mapper changed its AST; otherwise it stays byte-identical, is reported as not needing migration, and `--stdout` prints the source as is. Example (rescript): let add = (a, b) => a + b Before (rescript): let add = (a, b) => a + b After (rescript): let add = (a, b) => a + b Review: Why compare ASTs instead of checking for deprecated uses? A deprecation without a migration template rewrites nothing, and the `todo_` extension rename applies without any deprecation; the AST comparison covers both. Area: tools tests scripts Output: unchanged Tests: +tests/tools_tests/src/migrate/NoMigration.res +tests/tools_tests/src/migrate/NoMigration.resi +tests/tools_tests/src/expected/NoMigration.res.expected +tests/tools_tests/src/expected/NoMigration.resi.expected ~tests/tools_tests/test.sh (in-place migrate must keep the files unchanged) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo Signed-off-by: Christoph Knittel <ck@cca.io> * Print migrate --stdout output without an extra newline `rescript-tools migrate --stdout` printed its result with `print_endline`, so every output ended with one newline more than the file would contain: an unchanged file was not printed as is, and a migrated file gained a trailing blank line. The output is now printed unchanged, so it equals the file `migrate` would write. Area: tools tests Output: unchanged Tests: ~tests/tools_tests/test.sh (NoMigration --stdout output must equal the input byte for byte) ~tests/tools_tests/src/expected/*.expected (migrate fixtures lose the extra trailing newline) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo Signed-off-by: Christoph Knittel <ck@cca.io> --------- Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 32edc0a commit afaca70

33 files changed

Lines changed: 59 additions & 33 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Make `rescript-tools migrate` leave files untouched when no migration applies instead of reformatting them.

‎scripts/format.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ echo Formatting OCaml code...
88
opam exec -- dune build @fmt --auto-promote
99

1010
echo Formatting ReScript code...
11-
files=$(find packages tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/build_tests/super_errors/fixtures/break_keyword_binding.res" ! -path "tests/build_tests/super_errors_multi/fixtures/Iface_not_compiled/*" ! -path "tests/syntax_tests*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
11+
files=$(find packages tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/build_tests/super_errors/fixtures/break_keyword_binding.res" ! -path "tests/tools_tests/*/NoMigration.res*" ! -path "tests/build_tests/super_errors_multi/fixtures/Iface_not_compiled/*" ! -path "tests/syntax_tests*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
1212
./cli/rescript.js format $files
1313

1414
echo Formatting JS code...

‎scripts/format_check.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ case "$(uname -s)" in
1717
fi
1818

1919
echo "Checking ReScript code formatting..."
20-
files=$(find packages tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/build_tests/super_errors/fixtures/break_keyword_binding.res" ! -path "tests/build_tests/super_errors_multi/fixtures/Iface_not_compiled/*" ! -path "tests/syntax_tests*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
20+
files=$(find packages tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/build_tests/super_errors/fixtures/break_keyword_binding.res" ! -path "tests/tools_tests/*/NoMigration.res*" ! -path "tests/build_tests/super_errors_multi/fixtures/Iface_not_compiled/*" ! -path "tests/syntax_tests*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*")
2121
if ./cli/rescript.js format --check $files; then
2222
printf "${successGreen}✅ ReScript code formatting ok.${reset}\n"
2323
else

‎tests/tools_tests/src/expected/ApplyTransforms.res.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ let make = executor => makeTask((resolve, reject) => executor(~resolve, ~reject)
1111
let sum = (~a, ~b) => a + b
1212

1313
let add = (~x, ~y, ()) => sum(~a=x, ~b=y)
14-

‎tests/tools_tests/src/expected/ApplyTransforms.resi.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ let makeTask: ((int => unit, string => unit) => unit) => task<int>
1919
let add: (~x: int, ~y: int, unit) => int
2020

2121
let sum: (~a: int, ~b: int) => int
22-
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
let task = ApplyTransforms.makeTask((resolve, _) => resolve(1))
22

33
let total = ApplyTransforms.sum(~a=1, ~b=2)
4-

‎tests/tools_tests/src/expected/DeprecatedStuff.res.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ module Constants = {
99
}
1010

1111
let deprecatedThing = [1, 2]
12-

‎tests/tools_tests/src/expected/DeprecatedStuff.resi.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ module Constants: {
2424
migrate: DeprecatedStuff.Constants.otherThing,
2525
})
2626
let deprecatedThing: array<int>
27-

‎tests/tools_tests/src/expected/FileToMigrate.res.expected‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ let shift1 = Array.shift([1, 2, 3])
88
let shift2 = [1, 2, 3]->Array.shift
99

1010
let deprecatedThing1 = DeprecatedStuff.Constants.otherThing
11-
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// No migrations apply here, so the file must stay byte-identical
2+
// even though it is not formatted the way the printer would format it.
3+
let add = (a, b) => a + b
4+
5+
6+
let numbers = [1,2,3]->Array.map(x => add(x, 1))
7+
let other = DeprecatedStuff.Constants.otherThing

0 commit comments

Comments
 (0)