Skip to content

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

@brianrourkeboll

Description

@brianrourkeboll

(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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions