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

Analyzer & code fix for ~IDE0047~ FS3583: remove unnecessary parentheses #16078

Closed
1 of 7 tasks
brianrourkeboll opened this issue Oct 4, 2023 · 3 comments · Fixed by #16079
Closed
1 of 7 tasks

Analyzer & code fix for ~IDE0047~ FS3583: remove unnecessary parentheses #16078

brianrourkeboll opened this issue Oct 4, 2023 · 3 comments · Fixed by #16079

Comments

@brianrourkeboll
Copy link
Contributor

brianrourkeboll commented Oct 4, 2023

(See #15408.)

Edit: I ended up using FS3583 as the diagnostic ID in #16079 for now, due to the current limitations called out in #16079 (comment). That means that most of the questions below are moot for the time being.

We should add a code fix for removing unnecessary parentheses, i.e., a fix for the IDE0047 diagnostic—see https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048. This implies that we also need an analyzer that emits that diagnostic.

While such a thing could in theory be provided by a separate tool like Fantomas instead—ocamlformat offers similar functionality, for example—I think it probably makes sense to add the logic for it to the F# compiler service, which the VS tooling, Fantomas, etc., can then use.

I have a provisional implementation of the analyzer and code fix in #16079.

Questions

IDE0047 and IDE0048 already exist along with documentation and implementations for C# and VB. Some of the .editorconfig preferences, and the assumptions behind them, don't have obvious answers when applied to F#, since F# supports user-defined custom operators. For example, while the existing documentation for IDE0047 lists specific sets of binary operators to which the various preferences apply, (1) some of these operators have a different shape in F# (e.g., >>> instead of >> for right shift), and (2) in F#, infix operators with an arbitrary number of leading . or ? characters and an arbitrary number of valid trailing punctuation characters are parsed with the same precedence and associativity as the first one or two characters (depending).

@psfinaki
Copy link
Member

psfinaki commented Oct 5, 2023

Hi @brianrourkeboll - I think it would be cool to have this in F#.

We'll need to discuss the implementation probably since AFAIU Fantomas does take .editorconfig into the account so we need to be careful. @nojaf what are your thoughts?

@brianrourkeboll
Copy link
Contributor Author

We'll need to discuss the implementation probably since AFAIU Fantomas does take .editorconfig into the account so we need to be careful. @nojaf what are your thoughts?

To be fair, there are existing code fixes that don't necessarily heed style config: ImplementInterfaceCodeFixProvider isn't aware of Fantomas's fsharp_multiline_bracket_style, fsharp_space_before_colon, or fsharp_space_before_member, for example.

Luckily the spacing question is pretty minor and can be part of the fix itself, not the logic that determines whether parens are needed in the first place.

@nojaf
Copy link
Contributor

nojaf commented Oct 5, 2023

While such a thing could in theory be provided by a separate tool like Fantomas instead

Fantomas historically lacked stability for this feature. Nowadays, it might be more feasible, but I'd prefer to delegate it to a commercial product to avoid a flood of bug reports.

Regarding Fantomas settings, they're likely irrelevant in this case. I don't believe Fantomas is part of the vanilla product, so there's no need to burden @brianrourkeboll with it in this PR. He's doing an excellent job, and we shouldn't overwhelm him with stylistic concerns. We can address this in future PRs.

@0101 0101 removed the Needs-Triage label Oct 9, 2023
@brianrourkeboll brianrourkeboll changed the title Analyzer & code fix for IDE0047: remove unnecessary parentheses Analyzer & code fix for ~IDE0047~ FS3583: remove unnecessary parentheses Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants