dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Support K&R-Java brace style.

Open StevenDoesStuffs opened this issue 8 years ago • 7 comments

Please add support for this: https://en.wikipedia.org/wiki/Brace_style#Variant:_Java

StevenDoesStuffs avatar Feb 26 '17 19:02 StevenDoesStuffs

@StevenTheEVILZ What its differences from otbs?

georgy7 avatar Mar 06 '17 14:03 georgy7

@StevenTheEVILZ That is the .editorconfig I use.

[*.d]
indent_style = space
indent_size = 4
max_line_length = 100
dfmt_soft_max_line_length = 80
dfmt_brace_style = otbs
dfmt_split_operator_at_line_end = true

Sample result: https://github.com/georgy7/forgetter/blob/master/core/source/io.d

The only thing I don't like is the strange lines' concatenation. https://github.com/Hackerpilot/dfmt/issues/270

georgy7 avatar Mar 06 '17 14:03 georgy7

I found a difference:

}
catch (Exception e) {

Must be

} catch (Exception e) {

georgy7 avatar Mar 06 '17 14:03 georgy7

Also https://github.com/georgy7/forgetter/blob/master/core/source/image_dao.d

@Autowire private Io io;

certainly must be

@Autowire
private Io io;

But I am not sure about @safe, @nogc, etc.

This does not apply to annotations of method arguments. For instance, these both are correct:

@RequestMapping("/url")
public void someMethod(@RequestParam String a, @RequestParam String b) {
}

@RequestMapping("/url")
public void someMethod2(
        @RequestParam String a,
        @RequestParam String b) {
}

georgy7 avatar Mar 06 '17 14:03 georgy7

And this is correct too:

@RequestMapping("/url")
public void someMethod2(
        @RequestParam String a,
        @RequestParam String b
) {
    // ...
}

If a coder formats his/er code with one of acceptable variants, dfmt should not reformat it.

georgy7 avatar Mar 06 '17 14:03 georgy7

Yet another major correct variant:

@RequestMapping("/url")
public void someMethod(@RequestParam String a,
                       @RequestParam String b) {
}

public void orEven(int a,
                   int b, int c, int d,
                   int e,
                   int f) {
    // ...
}

georgy7 avatar Mar 06 '17 14:03 georgy7

@georgy7 The main reasons are the annotations and the catch/else statements that pair up with others. Also this: if (x()) y(); and

if (x())
    y();

should both be correct (I think) in java but not OTBS

StevenDoesStuffs avatar Mar 06 '17 23:03 StevenDoesStuffs