Search code examples
visual-studio-coded

Configuring dfmt to allow one element per line


With dfmt, the source code formatter for D language, the following code:

auto carModels = [
    "alpha", 
    "bravo", 
    "charlie", 
    "delta"
];

gets re-formatted into:

auto carModels = ["alpha", "bravo", "charlie", "delta"];

Is there a way to make the formatter keep the elements one per line as specified in the original, without turning off dfmt for that line?

I am using the vs-code D language extension called code-d, it invokes dfmt when formatting files.


Solution

  • This has now been added to dfmt with a new flag called keep_line_breaks

    https://github.com/dlang-community/dfmt/pull/471