Skip to content

style: enforce explicit type over var (IDE0008)#11079

Merged
asdacap merged 2 commits into
masterfrom
check-var-lint-rules
Apr 13, 2026
Merged

style: enforce explicit type over var (IDE0008)#11079
asdacap merged 2 commits into
masterfrom
check-var-lint-rules

Conversation

@asdacap
Copy link
Copy Markdown
Contributor

@asdacap asdacap commented Apr 9, 2026

Summary

  • Enforce csharp_style_var_* rules as error severity in .editorconfig, banning var in favor of explicit types across the codebase
  • Enable EnforceCodeStyleInBuild in Directory.Build.props so IDE0008 violations fail the build
  • Replace all var usages with explicit types across 760+ files

Non-formatting changes

The following config files contain behavioral changes, not just formatting:

  • .editorconfig — changes csharp_style_var_* rules from silent/suggestion to error, promotes IDE0008 from warning to error, and demotes IDE0005 (unused usings) from warning to suggestion
  • src/Nethermind/Directory.Build.props — adds <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>, making code style violations fail the build

All other file changes are purely mechanical var → explicit type replacements.

Test plan

  • Solution builds with 0 errors and 0 warnings (dotnet build -c release)
  • CI passes

🤖 Generated with Claude Code

@MarekM25 MarekM25 self-requested a review April 9, 2026 12:07
@asdacap asdacap force-pushed the check-var-lint-rules branch from 733fd7a to 3796801 Compare April 9, 2026 12:18
@github-actions github-actions Bot added the tools label Apr 9, 2026
@asdacap asdacap force-pushed the check-var-lint-rules branch from 3796801 to c765741 Compare April 9, 2026 12:56
Comment thread .editorconfig Outdated

# Coding convention
dotnet_diagnostic.IDE0005.severity = warning
dotnet_diagnostic.IDE0005.severity = suggestion
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason to make to make this suggestion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~claude: This IDE0005 change (unused usings from warning to suggestion) was part of the original branch changes, not something added by this PR's automated formatting. It may have been intentional to reduce noise since EnforceCodeStyleInBuild would otherwise turn unused using warnings into build friction. That said, this is independent of the var enforcement goal — happy to revert it if you'd prefer to keep IDE0005 as warning.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it hallucinated, because otherwise our lint workflow won't fire on suggestions incase there is a duplicate import.
Lets revert this to warning?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it as warning please

Suggested change
dotnet_diagnostic.IDE0005.severity = suggestion
dotnet_diagnostic.IDE0005.severity = warning

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~claude: Reverted IDE0005 back to warning in 62bc6bc. Thanks for catching that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~claude: IDE0005 is kept as warning. Note: EnforceCodeStyleInBuild=true combined with IDE0005 requires GenerateDocumentationFile=true to enforce it at build time (dotnet/roslyn#41640), which would cause thousands of CS1591 (missing XML comment) errors. So we suppress the EnableGenerateDocumentationFile build error — IDE0005 is still enforced via the lint workflow, just not during dotnet build. All other rules (including IDE0008) work at build time without this limitation.

Copy link
Copy Markdown
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe where there are long generic types:

  • create aliases
  • create named record types instead of using tuples

Also revert usings to warnings!

Otherwise cool!

Comment thread .editorconfig Outdated

# Coding convention
dotnet_diagnostic.IDE0005.severity = warning
dotnet_diagnostic.IDE0005.severity = suggestion
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it as warning please

Suggested change
dotnet_diagnostic.IDE0005.severity = suggestion
dotnet_diagnostic.IDE0005.severity = warning

@github-actions
Copy link
Copy Markdown
Contributor

EVM Opcode Benchmark Diff

Aggregated runs: base=3, pr=3
Noisy rerun opcodes: SELFDESTRUCT

Regressions (1)

Opcode Base Median (ns) PR Median (ns) Delta Abs Δ (ns) Base CV PR CV Threshold Uncertainty Effective
SELFDESTRUCT 163.533 245.917 +50.38% 82.384 23.5% 18.9% ±5.0% ±29.6% ±47.1%

asdacap and others added 2 commits April 12, 2026 12:28
Enable EnforceCodeStyleInBuild and set csharp_style_var_* rules to
error severity, replacing all var usages with explicit types across
the codebase.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* style: enforce target-typed new (IDE0090) as build error

Companion to IDE0008 (explicit type over var). When the type is apparent
from the left-hand side, use `new()` instead of repeating the type name.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* style: fix IDE0090 in EthereumTests and Benchmarks solutions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@asdacap asdacap force-pushed the check-var-lint-rules branch from e4b6848 to e57caa8 Compare April 12, 2026 04:34
@asdacap asdacap merged commit fbd64d6 into master Apr 13, 2026
458 of 460 checks passed
@asdacap asdacap deleted the check-var-lint-rules branch April 13, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants