just icon indicating copy to clipboard operation
just copied to clipboard

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

Open JohnstonJ opened this issue 1 year ago • 1 comments

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.

JohnstonJ avatar Sep 22 '24 04:09 JohnstonJ

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.

casey avatar Sep 22 '24 13:09 casey