just icon indicating copy to clipboard operation
just copied to clipboard

Format request: Align variables that are next to each other

Open nogweii opened this issue 1 year ago • 3 comments

Given the following example Justfile:

version := "0.2.7"
foo1    := / "tmp"
foo2_3 := "a/"
foo2_bar  := "a/"

tmpdir      := `mktemp`
project_tardir := tmpdir / "awesomesauce-" + version
prj_tarball := tardir + ".tar.gz"

Current Behavior

When you run just --unstable --format --check you get this diff, where every variable only has a single space around the assignment operator and the blank line between them removed:

 version := "0.2.7"
-foo1    := / "tmp"
+foo1 := / "tmp"
 foo2_3 := "a/"
-foo2_bar  := "a/"
-
-tmpdir      := `mktemp`
+foo2_bar := "a/"
+tmpdir := `mktemp`
 project_tardir := tmpdir / "awesomesauce-" + version
 prj_tarball := project_tardir + ".tar.gz"

Wanted Behavior

My preference would be to have the formatted output preserve the blank line and add spacing to the left of the operator to visually align them vertically, resulting in the following:

version  := "0.2.7"
foo1     := / "tmp"
foo2_3   := "a/"
foo2_bar := "a/"

tmpdir         := `mktemp`
project_tardir := tmpdir / "awesomesauce-" + version
prj_tarball    := project_tardir + ".tar.gz"

Where each blank-separated block of variables has it's own alignment, and there are n spaces to cause the := to be vertically aligned.

(Just version 1.25.2 on MacOS)

nogweii avatar Mar 12 '24 18:03 nogweii

I think that aligning variables looks better, but it would produce large diffs when variable names change.

casey avatar May 15 '24 02:05 casey

Every VCS I'm aware of has a way to produce diffs ignoring whitespace changes. I think the aesthetics are worth it.

Perhaps paired with some documentation mentioning that around --fmt?

nogweii avatar May 15 '24 02:05 nogweii

I think this isn't something which has an objective answers. I agree the aesthetics are nicer, but I don't think the larger diffs are worth it. There are a bunch of tools which produce diffs, GitHub, version control, diff, etc, which would have to be configured, which is not trivial.

I'd be fine with it as an optional flag though.

casey avatar May 15 '24 02:05 casey