Fix All and Rule Enforcement

Apply a quick fix across an entire member, type, document, project, or solution in one step, and optionally enforce the associated rule so the fixed style becomes mandatory in both your editor and dotnet build.

Supported scopes

Scope F# engine (FCS) C# engine (Roslyn)
Containing member / type AST range of the enclosing binding or type FixAllScope.ContainingMember / ContainingType
Document Every finding in the current file FixAllScope.Document
Project Every file in the owning FSharpProjectOptions FixAllScope.Project
Solution Every F# project in the loaded solution FixAllScope.Solution

Only scopes the underlying provider supports are offered. Project- and solution-wide edits carry needsConfirmation: true change annotations so editors that support refactoring preview let you inspect and undo everything atomically.

F# batch fixes

Rule Fix Build enforcement
SLSPF0102 Remove unused open dotnet_diagnostic.SLSPF0102.severity = error in [*.{fs,fsi,fsx}]
SLSPF0103 Simplify redundant qualified name dotnet_diagnostic.SLSPF0103.severity = error in [*.{fs,fsi,fsx}]
SLSPF0101 Remove unused declaration dotnet_diagnostic.SLSPF0101.severity = error; sharplsp.toml [diagnostics] dead_code = true
FS1182 Prefix unused value with _ Directory.Build.props OtherFlags += --warnon:1182, WarningsAsErrors += FS1182
FS0760 Add new for IDisposable Directory.Build.props WarningsAsErrors += FS0760

C# Fix All and opposing rules

Every Roslyn CodeFixProvider exposing a FixAllProvider supports Fix All across its advertised scopes. When you choose Fix and enforce, SharpLsp writes the style options, promotes the diagnostic to error, sets <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> in Directory.Build.props, and disables opposing rules automatically:

  • Enforcing IDE0007 (use var) sets IDE0008 (use explicit type) to none, and vice versa.
  • Enforcing IDE0161 (file-scoped namespaces) sets IDE0160 (block-scoped) to none, and vice versa.
  • Enforcing IDE0003 (remove this.) sets IDE0009 (require this.) to none.

Existing .editorconfig comments, ordering, and unrelated keys are preserved through SharpLsp's lossless .editorconfig CST writer, and Directory.Build.props list properties (WarningsAsErrors, OtherFlags) are merged through an XML DOM rather than overwritten.

Vulnerable NuGet packages

On .fsproj, .csproj, Directory.Packages.props, and shared .props files, source.fixAll.sharplsp and sharplsp.nuget.fixAllVulnerable update every vulnerable package in the project or solution to its lowest known-good version (preferring a parent update over a direct or central pin). Choosing and enforce in build writes NU1903;NU1904 into WarningsAsErrors in Directory.Build.props and sets [nuget.vulnerabilities] enforce_in_build = true in sharplsp.toml.

Fix on save

Configure your editor to run source.fixAll.sharplsp on save for non-enforcing, document-scoped fixes:

{
  "editor.codeActionsOnSave": {
    "source.fixAll.sharplsp": "explicit"
  }
}