Rustfmt: [unstable option] enum_discrim_align_threshold

Created on 13 Feb 2019  路  2Comments  路  Source: rust-lang/rustfmt

Tracking issue for unstable option: enum_discrim_align_threshold

unstable option

Most helpful comment

I was looking at the vertical alignment options of rustfmt. I was suprised by this.

20:

enum Foo {
    A   = 0,
    Bb  = 1,
    RandomLongVariantGoesHere = 10,
    Ccc = 2,
}

enum Bar {
    VeryLongVariantNameHereA = 0,
    VeryLongVariantNameHereBb = 1,
    VeryLongVariantNameHereCcc = 2,
}

I would expect this:

enum Foo {
    A   = 0,
    Bb  = 1,
    RandomLongVariantGoesHere = 10,
    Ccc = 2,
}

enum Bar {
    VeryLongVariantNameHereA   = 0,
    VeryLongVariantNameHereBb  = 1,
    VeryLongVariantNameHereCcc = 2,
}

I think it would make more sense if the threshold would refer to the maximum number of spaces to insert to make things align. The length of the actual text doesn't seem to be very relevant here. It's just when one starts to align very long items with very short items it looks a bit weird to people, but personally I still prefer it most of the times. Another reason to limit vertical alignment might be the resulting total line length, as aligning wrapped lines doesn't make much sense.

I suppose the same issue might exist on other vertical alignment options like struct_field_align_threshold.

Maybe this could fall into a more general category of "align assignment operator"? Or maybe even a vertical_align_max_spaces which could apply to all vertical alignment?

All 2 comments

I was looking at the vertical alignment options of rustfmt. I was suprised by this.

20:

enum Foo {
    A   = 0,
    Bb  = 1,
    RandomLongVariantGoesHere = 10,
    Ccc = 2,
}

enum Bar {
    VeryLongVariantNameHereA = 0,
    VeryLongVariantNameHereBb = 1,
    VeryLongVariantNameHereCcc = 2,
}

I would expect this:

enum Foo {
    A   = 0,
    Bb  = 1,
    RandomLongVariantGoesHere = 10,
    Ccc = 2,
}

enum Bar {
    VeryLongVariantNameHereA   = 0,
    VeryLongVariantNameHereBb  = 1,
    VeryLongVariantNameHereCcc = 2,
}

I think it would make more sense if the threshold would refer to the maximum number of spaces to insert to make things align. The length of the actual text doesn't seem to be very relevant here. It's just when one starts to align very long items with very short items it looks a bit weird to people, but personally I still prefer it most of the times. Another reason to limit vertical alignment might be the resulting total line length, as aligning wrapped lines doesn't make much sense.

I suppose the same issue might exist on other vertical alignment options like struct_field_align_threshold.

Maybe this could fall into a more general category of "align assignment operator"? Or maybe even a vertical_align_max_spaces which could apply to all vertical alignment?

I agree with the above, and would be happy to look into making a PR if it's something that's wanted.

Was this page helpful?
0 / 5 - 0 ratings