-
Notifications
You must be signed in to change notification settings - Fork 120
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
Tall style: Keep => closer to the function call for one-arg functions #1532
Comments
I don't like that. It feels odd to me that a trailing comma after a parameter wouldn't cause the parameter to start on a newline. The way I'd deal with those specific cases is to not use So I'd do: void main() {
complex.components.any((component) {
return component.combinators.length > 1 || component.selector.accept(this);
});
} IMO switching between => and {} is like adding/removing a trailing comma. It's one of my core formatting tools. |
The point of adding the tall style is that commas don't cause anything. I'd be just as happy with the last example being void main() {
complex.components.any((component) =>
component.combinators.length > 1 || component.selector.accept(this)
);
} which matches a single-argument function with a block callback not having a comma.
I don't want "formatting tools", I want an opinionated formatter that ends debates about style issues in code reviews. If I get a code review comment like "if you make this a bracketed function it'll get the formatter to reduce indentation" that's purely negative value. I'd prefer that the formatter be in charge of choosing between |
Without a comma there, I don't mind as much.
You can achieve the exact same thing with lint rules instead of baking it in the formatter. Formatting the file already can apply quick fixes, so it'd remove unused imports, along with fixing whatever style issue you have based on your lints. IMO having the formatter do it wlll be hurtful:
A formatter cannot fix the problem either. That's way out of the scope of the formatter. And not fixing those means style issues are still a thing. |
If I understand the logic, the formatting without a trailing comma would be: void main() {
complex.components.any((component) =>
component.combinators.length > 1 || component.selector.accept(this));
} if that is at all possible with an argument taking more than one line, and void main() {
complex.components.any(
(component) =>
component.combinators.length > 1 || component.selector.accept(this),
);
} with a trailing comma.comma (each argument on its own line(s)). (Making argument lists "tall" is an anti-goal for me. I want my code as I want my gmail, "compact"!) |
Generally, for a single-argument function that takes a callback, I expect the callback argument to be tightly bound to the call site. For example, I get:
where I would expect
although even
would be preferable.
I similarly dislike cases like
which I would prefer to have as
(This is also more consistent with how the same function call would be structured if it used a bracketed callback, which to my mind is a benefit.)
The text was updated successfully, but these errors were encountered: