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

Consider disabling require_trailing_commas lint if language version of file is >= 3.7 #60119

Open
parlough opened this issue Feb 12, 2025 · 9 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug

Comments

@parlough
Copy link
Member

It will conflict with tall style formatting.

@parlough parlough added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Feb 12, 2025
@FMorschel
Copy link
Contributor

FMorschel commented Feb 12, 2025

if there is no comma:

  • in case the content fits the line, the formatter will choose one line
  • else, the formatter will choose what it believes best, which most of the time will be "long style" formatting, without adding any comma.

This would work, and would avoid the problem with the formatter not being able to distinguish hand-inserted commas from formatter-inserted commas. Unfortunately, as far as I can tell, virtually zero users actually want code that looks like this without a trailing comma:

noTrailingComma(
  longArgument,
  anotherLongArgument
);

From all of the hand-formatted Dart code I've seen and from the large number of users who manually opted in to writing trailing commas before this proposal, it seems like almost all users who want the ) on the next line also want a trailing comma after the last argument.

Originally posted by @munificent in dart-lang/dart_style#1253 (comment)

So I'm unsure if removing the lint is what we want, but I'll leave to the team to decide.

@bwilkerson
Copy link
Member

... which most of the time will be "long style" formatting, without adding any comma.

The final decision was that the formatter will add or remove trailing commas based on whether or not the list is split across multiple lines. It will not honor the presence or absence of a trailing comma.

That means that this lint is pointless for users that use the formatter. If we have enough users that don't use the formatter then it might make sense to keep this lint, but I, and several others, are hoping that most users will use the new formatter so that this lint is no longer helpful.

@parlough parlough changed the title Disable require_trailing_commas lint if language version of file is >= 3.7 Consider disabling require_trailing_commas lint if language version of file is >= 3.7 Feb 13, 2025
@parlough
Copy link
Member Author

I didn't really consider projects not using the formatter, but I suppose that's a potential reason to keep it working with a language version after 3.7.

However, in its docs, the rule says it assumes code is formatted with dart format. So perhaps it's fine to assume that users of the lint wouldn't want it triggering with a 3.7 language version?

@bwilkerson
Copy link
Member

That makes sense to me.

@FMorschel
Copy link
Contributor

users of the lint wouldn't want it triggering with a 3.7 language version?

That makes sense to me too.

I'll just note that:

but I, and several others, are hoping that most users will use the new formatter so that this lint is no longer helpful.

It doesn't seem to be the case. If you open the above mentioned issue, it has been less than one day since Dart 3.7 is out and we have five different comments asking for the trailing commas to not get removed.

@bwilkerson
Copy link
Member

... but I, and several others, are hoping that most users will use the new formatter ...

Those comments are all related to the behavior of the formatter, which means that they're coming from users that use the formatter. They don't address the question of what percentage of users use the formatter (irrespective of whether or not they like the change).

... so that this lint is no longer helpful.

The lint is no longer useful to users that use the formatter because the formatter no longer honors the use of a trailing comma as a way of deciding how to format the code. It simply formats the code the way it wants and then it adds or removes commas based on the format.

In other words: using the formatter and enabling this lint are mutually exclusive options.

The hope is that there are (or will be) few enough users that enable this lint that it would make sense to retire it.

@FMorschel
Copy link
Contributor

I understand your point now. Thanks!

@srawlins
Copy link
Member

CC @pq looking at lints we may no longer want to maintain.

@srawlins
Copy link
Member

There's so much activity over at dart-lang/dart_style, I'd strongly consider a cherry-pick to disable require_trailing_commas when lang version is 3.7.

@srawlins srawlins added P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug labels Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants