You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
doctor calls a final newline change a line endings change #3524
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
Tell a final newline change apart from a line endings change in doctor
Report the final newline and the line endings each on its own in doctor
Bump the packages group with 5 updates (#290)