Skip to content

Non-idempotent formatting #78

@shwestrick

Description

@shwestrick

This is an example of non-idempotent formatting, which seems to be due to how comments are handled. We should fix this.

Original:

if offset i + j + 1 < offset (i+1) then
(* innerIdx := j+1 *) ()
else
( outerIdx := advanceUntilNonEmpty (i+1)
(* ; innerIdx := 0 *)
);

Here's the diff between running the formatter once and twice. This seems to happen because the comment crosses the max width.

                 if offset i + j + 1 < offset (i + 1) then
                   ()
                 else
-                  (outerIdx := advanceUntilNonEmpty (i + 1)(* ; innerIdx := 0 *) );
+                  (outerIdx
+                   := advanceUntilNonEmpty (i + 1) (* ; innerIdx := 0 *));

Note that smlfmt catches this when run with --check:

$ ./smlfmt --check src/lib/github.com/mpllang/mpllib/OldDelayedSeq.sml 
WARNING: src/lib/github.com/mpllang/mpllib/OldDelayedSeq.sml: non-idempotent formatting detected. 
Don't worry! The output is still correct; this is only an aesthetic issue. To help improve `smlfmt`, 
please consider submitting a bug report: https://github.com/shwestrick/smlfmt/issues
overwrite src/lib/github.com/mpllang/mpllib/OldDelayedSeq.sml [y/N]?

Metadata

Metadata

Assignees

No one assigned

    Labels

    aestheticsImprovement to code formatter outputbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions