-
Notifications
You must be signed in to change notification settings - Fork 122
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
Shorter code creates more lines #1605
Comments
In general, neither the old nor the new style have rules that try to minimize the number of lines. They try to minimize the cost but a single point of cost may mean one or more newlines getting inserted depending on how each formatting rule behaves. In cases like your examples, there are a number of valid ways the code could be line split to fit in the page width and determining which to prefer over others is a pretty delicate game of heuristics. I agree that your expected output looks nicer than the actual output in these examples. I'm less sure that tweaking the rules to yield that wouldn't end up make even more other examples look worse. We might be able to improve this, but I'll have to do some experimentation and try it out on a corpus to see if I can find anything that seems like an overall improvement. In general, deciding when to split as |
Another example that leaves me puzzled where the new tall style adds an additional new line. var robots = input.split('\n').map((line) {
- final matches =
- RegExp(r'p=(-?\d+),(-?\d+) v=(-?\d+),(-?\d+)').allMatches(line);
+ final matches = RegExp(r'p=(-?\d+),(-?\d+) v=(-?\d+),(-?\d+)').allMatches(
+ line,
+ );
final px = matches.first.group(1)!;
final py = matches.first.group(2)!;
final vx = matches.first.group(3)!;
final vy = matches.first.group(4)!;
assert(int.parse(px) < gridWidth);
assert(int.parse(py) < gridHeight);
return Robot(
velocity: (dx: int.parse(vx), dy: int.parse(vy)),
position: (x: int.parse(px), y: int.parse(py)),
);
}).toList(); |
Hey Bob,
Some feedback on the new proposed style for Dart 3.7. I tested it with my
spot
package and found this interesting case I can't explain. It looks like a bug to me.Before
unformatted, does not fit within 80 characters
Actual
What's unclear is why the first
appBar.spotIcon
line creates 4 LOC, whereas the second only requires 3.It is possible to format the first line, like the second, without any problem. Why do they behave differently?
Expected
The text was updated successfully, but these errors were encountered: