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

Super skips to next line even if it fits to one line with constructor #1107

Closed
AndreevIlya opened this issue Apr 18, 2022 · 1 comment
Closed

Comments

@AndreevIlya
Copy link

What i have:

abstract class SomeClassA {
  SomeClassA({
    required this.property1,
    required this.property2,
    required this.complexProperty,
  });

  final String property1;
  final String property2;

  final SomeClassB complexProperty;
}

class SomeClassB {
  SomeClassB(this.property1, this.property2, this.property3);

  final String property1;
  final String property2;
  final String property3;
}

class SomeClassC extends SomeClassA {
  SomeClassC({required final String property1})
      : super(
          property1: property1,
          property2: "abc",
          complexProperty: SomeClassB(
            "sdf",
            "dfg",
            "fgh",
          ),
        );
}

What i want (don't know how many spaces should have indentation of super's params, but 2 seems to me the most reasonnable):

class SomeClassC extends SomeClassA {
  SomeClassC({required final String property1}) : super(
    property1: property1,
    property2: "abc",
    complexProperty: SomeClassB(
      "sdf",
      "dfg",
      "fgh",
    ),
  );
}

Compare this to

class SomeClassC extends SomeClassA {
  SomeClassC({
    required final String property1,
  }) : super(
          property1: property1,
          property2: "abc",
          complexProperty: SomeClassB(
            "sdf",
            "dfg",
            "fgh",
          ),
        );
}

Here format is good because we've trailing comma but setting trailing comma after the only item in a constructor is strange.

@munificent
Copy link
Member

I ran class C through the forthcoming tall style and got:

class SomeClassC extends SomeClassA {
  SomeClassC({required final String property1})
    : super(
        property1: property1,
        property2: "abc",
        complexProperty: SomeClassB("sdf", "dfg", "fgh"),
      );
}

That isn't exactly what you're asking for, but is what I expect. There is a formatting rule that if the contents of the super() clause split, then we also split at the :. Otherwise, I feel like it's too easy to lose track of where the constructor's parameter list ends and the initializer list ends.

The above output looks pretty good to me, so I'm going to go ahead and close this issue.

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

No branches or pull requests

2 participants