Skip to content

doctor calls a final newline change a line endings change #3524

Closed

Description

@nojaf

fantomas doctor reports a file whose only change is its final newline as a line endings change.

Repro

printf 'let a = 1' > NoFinalNewline.fs
dotnet fantomas doctor NoFinalNewline.fs

With the default insert_final_newline = true and end_of_line = lf, the file's endings are already LF. Fantomas 8.0.5 says:

! Format      Not formatted: every line is as it should be and the line endings are not, so the whole file would be rewritten.

and --json gives "format": { "status": "line-endings" }.

The line endings are fine: formatting only adds the final newline. The same happens the other way round, with insert_final_newline = false and a file that ends in one.

Cause

walkFormatting in src/Fantomas/DoctorCommand.fs compares the file and the result line by line. lines folds away both the line endings and whether the text ends in a newline, so when no line differs and the text still does, it picks FormatChange.LineEndingsOnly without checking which of the two it was.

Fix

Tell the two apart, for example by comparing the texts with \r\n replaced by \n: the same means line endings, different means the final newline. Give the final newline its own case and its own sentence in the text report and the JSON report.

Activity

  1. added
    clitool
    on Oct 8, 2026
  2. added 2 commits that reference this issue on Nov 18, 2026
    d3f2d18
    24e93ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    clitool

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions