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

IDE0305 fix description/make configurable #7259

Open
bzd3y opened this issue Mar 21, 2024 · 0 comments
Open

IDE0305 fix description/make configurable #7259

bzd3y opened this issue Mar 21, 2024 · 0 comments

Comments

@bzd3y
Copy link

bzd3y commented Mar 21, 2024

Analyzer

Diagnostic ID: IDE0305

Describe the improvement

The documentation for this rule says :

This rule flags places where a collection is built in a fluent manner, that is, where methods like Add(), AddRange(), AsSpan(), ToList(), and ToArray() are chained.

But the rule is triggered when there is no fluent/chaining of methods.

Describe suggestions on how to achieve the rule

The documentation/description should probably be changed to indicate that it is just triggered by using any methods that can be chained. (But why are these methods even there or can be used fluently if we aren't supposed to use them that way?)

Or, ideally, I think that it would help if it was just made to be configurable with an option to trigger like it does now or to only trigger for actual fluent code with chained methods. Right now if it sees something like someList.ToArray() it will suggest something like [.. someList] even though that isn't really fluent or any chaining. Sure, that is fewer characters to type, if you don't count Intellisense helping you. But it isn't nearly as readable. Now, if it does encounter some chain of multiple methods then it might make more sense to refactor that to use collection expressions.

So it would be nice to have something like:

dotnet_style_prefer_collection_expression = when_multiple_methods

Honestly, ideally it might just take an integer and if the chain is that long or longer it triggers. So something like one/both of:

dotnet_style_prefer_collection_expression_chain_length = 2
dotnet_style.IDE0305.chain_length = 2
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

1 participant