dotnet / dotnet/roslyn

Invalid code-style option values silently disable IDE0058/IDE0059 and change IDE0060 behavior

Open
#84,797 3 comments 0 reactions 0 assignees View on GitHub
Area-IDE
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Version Used**:

.NET SDK 10.0.110

**Steps to Reproduce**:

1. Create a console project and enable code style enforcement:

```xml

true

```

2. Add this source file:

```csharp
// Program.cs
public class Program
{
public static void Main()
{
M(1); // IDE0058: Expression value is never used
int x = 1; // IDE0059: Unnecessary assignment of a value to 'x'
x = 2; // IDE0059: Unnecessary assignment of a value to 'x'
}
public static int M(int y) => 1; // IDE0060: Remove unused parameter 'y'
}
```

3. Apply one of the following `.editorconfig` variants:

```ini
[*.cs]
dotnet_diagnostic.IDE0058.severity = warning
dotnet_diagnostic.IDE0059.severity = warning
dotnet_diagnostic.IDE0060.severity = warning
csharp_style_unused_value_expression_statement_preference = discard_variable
```

```ini
[*.cs]
dotnet_diagnostic.IDE0058.severity = warning
dotnet_diagnostic.IDE0059.severity = warning
dotnet_diagnostic.IDE0060.severity = warning
csharp_style_unused_value_expression_statement_preference = abc # invalid value
```

```ini
[*.cs]
dotnet_diagnostic.IDE0058.severity = warning
dotnet_diagnostic.IDE0059.severity = warning
dotnet_diagnostic.IDE0060.severity = warning
csharp_style_unused_value_assignment_preference = abc # invalid value
```

```ini
[*.cs]
dotnet_diagnostic.IDE0058.severity = warning
dotnet_diagnostic.IDE0059.severity = warning
dotnet_diagnostic.IDE0060.severity = warning
dotnet_code_quality_unused_parameters = abc # invalid value
```

```ini
[*.cs]
dotnet_diagnostic.IDE0058.severity = suggestion
dotnet_diagnostic.IDE0059.severity = suggestion
dotnet_diagnostic.IDE0060.severity = suggestion
csharp_style_unused_value_expression_statement_preference = abc # invalid value
```

4. Run `dotnet build -t:Rebuild` / `dotnet build -t:Rebuild -p:ErrorLog=err.sarif`.

**Diagnostic Id**:

- `IDE0058: Expression value is never used` (option `csharp_style_unused_value_expression_statement_preference`)
- `IDE0059: Unnecessary assignment of a value to 'x'` (option `csharp_style_unused_value_assignment_preference`)
- `IDE0060: Remove unused parameter 'y'` (option `dotnet_code_quality_unused_parameters`)

**Expected Behavior**:

An unrecognized value should behave like every other code-style option: fall back to the option's default and keep the rule functional. With `= discard_variable` (valid) the build reports IDE0058, IDE0059 and IDE0060; with `= abc` it should report the same defaults (`discard_variable` / `discard_variable` / `all` respectively).

**Actual Behavior**:

Setting `csharp_style_unused_value_expression_statement_preference = abc` silently and completely disables the IDE0058 rule, despite having `severity = warning` and `EnforceCodeStyleInBuild=true`; the only signal is an analyzer crash reported as `AD0001: The given key '(0, False, False)' was not present in the dictionary`. Similarly, `csharp_style_unused_value_assignment_preference = abc` silently and completely disables IDE0059 (`AD0001: The given key '(0, True, True)' was not present in the dictionary`). In the case of `dotnet_code_quality_unused_parameters = abc` there is no crash at all: the rule silently shifts to `non_public` behavior instead of the expected default `all` (a public method's unused parameter is no longer flagged), giving absolutely no signal that an invalid configuration was used.

The `AD0001` crash reports are only surfaced when the affected rule's severity is at least `warning` (or when an error log is requested, e.g. `-p:ErrorLog=err.sarif`, then `AD0001` appears even at `suggestion` severity). At `suggestion` severity (as used by the .NET default templates and most configs), the compiler's usual swallowing of crash reports makes this bug completely invisible: a plain `dotnet build` completes with zero warnings and zero errors, and the rules are disabled with no trace in console output or the IDE.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the supplied Program.cs, each .editorconfig variant, and `dotnet build -t:Rebuild`; compare the IDE0058, IDE0059, IDE0060, and AD0001 results. Trace how the three named options parse invalid values and verify that invalid settings fall back to their documented defaults without disabling diagnostics or changing rule behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.