casey / just

🤖 Just a command runner
https://just.systems
Creative Commons Zero v1.0 Universal
22.48k stars 491 forks source link

Enforce/respect a maximum line length when using "just --fmt" command to reformat a justfile #2387

Open JohnstonJ opened 2 months ago

JohnstonJ commented 2 months ago

The just --fmt command will take nicely formatted code with a reasonable maximum line length, and turn it into a very long unreadable line.

For example, if I try to format this using just --fmt:

SETUP_DEBUG_ENV := if os_family() == "windows" {
    "$env:PKG_CONFIG = \"" + justfile_directory() +
        "\\vcpkg_installed\\x64-windows-release\\tools\\pkgconf\\pkgconf.exe\"\n" +
    "$env:PKG_CONFIG_PATH = \"" + justfile_directory() +
        "\\vcpkg_installed\\x64-windows-static\\debug\\lib\\pkgconfig\"\n"
} else {
    "exit 1"
}

it will get reformatted to this mess:

SETUP_DEBUG_ENV := if os_family() == "windows" { "$env:PKG_CONFIG = \"" + justfile_directory() + "\\vcpkg_installed\\x64-windows-release\\tools\\pkgconf\\pkgconf.exe\"\n" + "$env:PKG_CONFIG_PATH = \"" + justfile_directory() + "\\vcpkg_installed\\x64-windows-static\\debug\\lib\\pkgconfig\"\n" } else { "exit 1" }

Many other reformatting tools (black, rustfmt, etc) provide a configurable option for maximum line length. Maybe just needs something similar, and then it could make better decisions about whether to place statements like the above one onto one line or multiple lines.

casey commented 2 months ago

I definitely agree that the current situation is not great. --fmt is pretty bad, which is why it's still --unstable. I have a feeling that making it better would be pretty complicated, and require a lot of concerted effort.