csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Generic Property Breaking

Open belav opened this issue 4 years ago • 2 comments

Currently a generic property will break like this

    public virtual ICollection<
        SomeObject
    > SomeLongNameThatForcesALineBreak { get; set; } =
        new HashSet<SomeObject>();

Which is modeled after how prettier breaks the following typescript.

  public SomeName: SomeLongGenericClassThatBreaks<
    SomeRandomType,
    SomeOtherRandomType
  > = new SomeLongGenericClassThatBreaks(someValue, someOtherValue);

Should we do something different?

    public virtual ICollection<SomeObject>
        SomeLongNameThatForcesALineBreak { get; set; } =
            new HashSet<SomeObject>();

Or maybe this if we decide to break before the =

    public virtual ICollection<SomeObject>
        SomeLongNameThatForcesALineBreak { get; set; }
            = new HashSet<SomeObject>();

Would we ever want to break after the modifiers?

public virtual 
    ICollection<SomeLooooooooooooooooooooooooooongType>
        SomeLongNameThatForcesALineBreak { get; set; } = 
            HashSet<SomeLooooooooooooooooooooooooooongType>

belav avatar May 31 '21 15:05 belav

One heuristic that prettier uses is that if there is only type parameter, it isn't broken up, ever. Maybe, we can incorporate that.

More specifically, prettier keeps the LHS part of a declaration with at most one type parameter on a single line. If more than one, it may be broken up as you mentioned.

In a similar vein, we can also keep the LHS part of a declaration on a single line if there's at most one type parameter.

public virtual ICollection<SomeObject> SomeLongNameThatForcesALineBreak { get; set; } =
    new HashSet<SomeObject>();

And if there's more than one, we can split along similar lines to prettier.

public virtual ICollection<
    SomeObject, 
    ReallyLongTypeParameter> SomeLongNameThatForcesALineBreak { get; set; } =
        new HashSet<SomeObject>();

respel avatar Jun 01 '21 22:06 respel

I think

Group(
    Group("public virtual", "ICollection<SomeLooooooooooooooooooooooooooongType>"),
    Group("SomeLongNameThatForcesALineBreak", "{ get; set; } ="),
    "HashSet<SomeLooooooooooooooooooooooooooongType>"
)

(with the contents in "" being printed recursively by syntax printers, of course) would achieve the # 3, right?

shocklateboy92 avatar Jun 03 '21 02:06 shocklateboy92