Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Property Breaking #243

Open
belav opened this issue May 31, 2021 · 2 comments
Open

Generic Property Breaking #243

belav opened this issue May 31, 2021 · 2 comments

Comments

@belav
Copy link
Owner

belav commented May 31, 2021

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>
@respel
Copy link

respel commented Jun 1, 2021

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>();

@shocklateboy92
Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants