Skip to content

chore: avoid Fantomas comment loss on else if lines - #4773

Merged
dbrattli merged 1 commit into
mainfrom
chore/fantomas-else-if-comment-flake
Jul 13, 2026
Merged

dbrattli merged 1 commit into
mainfrom
chore/fantomas-else-if-comment-flake

Conversation

@dbrattli

Copy link
Copy Markdown
Collaborator

Problem

The verify-linting CI job fails on roughly every other run, always with:

[INF] ./src/fable-library-dart/Map.fs needs formatting

Fantomas 7.0.5 nondeterministically drops the trailing comment on an else if ... then // comment line when formatting a directory:

-        else if t1h > t2h + tolerance then // left is heavier than right
+        else if t1h > t2h + tolerance then

Only that trivia position is affected — trailing comments on plain if ... then and on else survive. It reproduces only in a whole-directory run (dotnet fantomas . --check), never single-file, which points at a concurrency bug in Fantomas' trivia handling. A fix on the Fantomas side is realistically months out.

Despite CI always naming the Dart Map.fs, the file isn't special: the pattern is duplicated in the Map/Set implementations of the ts, py, dart and rust libraries, and any of those eight files can lose the race (my local repro mangled fable-library-ts/Map.fs). Adding the Dart file to .fantomasignore would therefore have fixed nothing and would have dropped format checking for the file.

Change

Move the comment to its own line above the else if, in all eight files, so the trivia Fantomas mishandles no longer exists. The comments are preserved; nothing semantic changes.

Verification

Repeated repo-wide dotnet fantomas . --check:

failures
before 1 / 30
after 0 / 150

🤖 Generated with Claude Code

Fantomas 7.0.5 nondeterministically drops the trailing comment on an
`else if ... then // comment` line when formatting a directory, which
makes the `verify-linting` CI job fail on roughly every other run. Only
that specific trivia position is affected: trailing comments on plain
`if ... then` and on `else` survive.

The pattern is duplicated in the Map/Set implementations of the ts, py,
dart and rust libraries; CI happened to name `fable-library-dart/Map.fs`
every time, but any of the eight files can lose the race.

Move the comment to its own line above the `else if` so the trivia
Fantomas mishandles is gone. Reproduced 1 failure in 30 repo-wide
`fantomas . --check` runs before the change, 0 in 150 after.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dbrattli
dbrattli requested a review from nojaf July 13, 2026 21:33
@github-actions

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 34
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

@dbrattli
dbrattli merged commit c6455f4 into main Jul 13, 2026
32 checks passed
@dbrattli
dbrattli deleted the chore/fantomas-else-if-comment-flake branch July 13, 2026 21:51
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.

1 participant