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

Split argument lists that would otherwise fit #1660

Open
munificent opened this issue Feb 26, 2025 · 1 comment
Open

Split argument lists that would otherwise fit #1660

munificent opened this issue Feb 26, 2025 · 1 comment
Labels

Comments

@munificent
Copy link
Member

munificent commented Feb 26, 2025

The most consistent negative feedback we've gotten from the new formatting style is that it often puts an argument list on one line because it fits the page width when the user feels the resulting code would look better if split. For example (based on #1652):

// Current behavior:
Material(
  color: Colors.transparent,
  child: InkWell(
    customBorder: const CircleBorder(),
    child: Padding(padding: const EdgeInsets.all(2), child: child),
    onTap: () {
      context.read<ScGalleryVm>().crop();
    },
  ),
)

// Preferred:
Material(
  color: Colors.transparent,
  child: InkWell(
    customBorder: const CircleBorder(),
    child: Padding(
      padding: const EdgeInsets.all(2),
      child: child,
    ),
    onTap: () {
      context.read<ScGalleryVm>().crop();
    },
  ),
)

Even though the Padding(...) call fits on one line, many users feel the latter code is easier to read and maintain.

The new formatter's configurable page width exacerbates this issue. If you set a wider page width, you'll get even more of these nested long argument list lines.

I'm filing this issue to be the sort of "meta-issue" that discusses this problem. If you have examples of argument lists where you think the formatter should have split them and didn't, please include them here (as text, not screenshots!). Then we can discuss proposed solutions to this problem as separate issues:

@yakagami
Copy link

yakagami commented Feb 27, 2025

Another related example: Lists of widgets (Row, Column, ListView) read better when each item in the List has its own line.

Current:

Widget example() {
  return const Row(children: [Text("1"), Text("2"), Text("3")]);
}

Desired:

Widget example() {
    return const Row(
        children: [
            Text("1"),
            Text("2"),
            Text("3"),
        ]
    );
}

Not sure if this is technically an argument list though, because there is only one argument (the List literal).

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

No branches or pull requests

2 participants