An actionable rant on .NET linting rules.
References:
- As a developer is working, they naturally create "bugs" as they type which will be resolved by the time they finish typing. It is distracting and counter-productive to display errors that are likely to be fixed in a moment while the developer is working.
Default: error
π
This is a reasonable rule and should be raised to the developer. However, it makes no sense to have this be an error. It is very common for a method to be implemented during a development cycle which does not use any instance data yet but will in the immediate future - even within the same dev cycle. It also boxes the programmer into an API corner. The performance benefit could be real, and I am certainly a fan of pure functional programming when possible, therefore this rule should never be higher than a suggestion.
dotnet_diagnostic.CA1822.severity = suggestion
Default: error
π
This should be cleaned up but there is no way this should be an error.
dotnet_diagnostic.IDE0005.severity = warning
Default: error
β£οΈ
This breaks C# and causes you to add _ =
all over your code base. The people who created this rule hate you and especially hate your tidy code base.
dotnet_diagnostic.IDE0058.severity = none
Default: error
β£οΈ
This is an insane rule - any new variable that you create will have this "error" immediately. This rule makes C# more like Golang which means it makes it worse.
dotnet_diagnostic.IDE0059.severity = suggestion
Default error
π
The rule is generally a good one but the default severity is completely unreasonable because it gets in the way while a developer is working. It is also a duplicate with SA1507.
dotnet_diagnostic.IDE2000.severity = warning
Default error
π
The rule is generally a good one but the default severity is unreasonable because it gets in the way while a developer is working.
dotnet_diagnostic.IDE2003.severity = suggestion
Default error
π
This rule in particular causes breaks while using hot reload with modern .NET. It is well intentioned but should be a warning. This is implemented by the SonarAnalyzer.
dotnet_diagnostic.S1854.severity = warning
Default error
π
This rule can make sense if you're doing a fire and forget sort of thing (aka not await
ing on the Task) but it's generally not interesting and can lead to code sprawl.
dotnet_diagnostic.S4457.severity = suggestion
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1009.severity = suggestion
Default error
π
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1028.severity = warning
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1111.severity = suggestion
SA1116: The parameters should begin on the line after the declaration, whenever the parameter spans across multiple lines
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1116.severity = suggestion
SA1117: The parameters should all be placed on the same line or each parameter should be placed on its own line
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1117.severity = suggestion
Default error
β£οΈ
This is literally from a performance bug in .NET 1.0 where the compiler couldn't optimize uses of "" and so many empty strings would get allocated. This was fixed in .NET 1.1 more than 20 years ago, and there is no benefit to use string.Empty
except to make your code longer. It is toxic to make this an error.
dotnet_diagnostic.SA1122.severity = none
Default error
β£οΈ
This is a completely unreasonable rule in C#. This is a holdover from other programming languages where there was a line which separated public from private. This is a completely useless rule and it should be suppressed.
dotnet_diagnostic.SA1204.severity = none
Default error
π
This is a completely unreasonable rule in C# and harms the ability to follow differences in a file in source control. One might want their IDE to auto-implement this change, in theory, so this rule can be allowed to exist as a suggestion only.
dotnet_diagnostic.SA1204.severity = suggestion
Default error
β£οΈ
This is a preposterous idea that came over from JavaScript. The idea is that in future commits you will only have one line to change if you add something to a list. It is optimizing a theoretical future for the actual present.
dotnet_diagnostic.SA1413.severity = none
Default error
π
This is a fine idea but it is insane to make this an error while a developer is working.
dotnet_diagnostic.SA1505.severity = suggestion
Default error
π
The rule is generally a good one but the default severity is completely unreasonable because it gets in the way while a developer is working. It is also a duplicate with IDE2000.
dotnet_diagnostic.SA1507.severity = suggestion
Default error
π
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1508.severity = suggestion
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error. This one also has a bad interaction with the new collection syntax in C# ([]
), so it should just be disabled.
dotnet_diagnostic.SA1513.severity = none
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error. This is particularly toxic in multi-property object initializers when trying to explain why something is set to the value it is.
dotnet_diagnostic.SA1516.severity = none
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1516.severity = suggestion
Default error
β£οΈ
This is a whitespace opinion and can be implemented automatically - therefore it should not be an error.
dotnet_diagnostic.SA1518.severity = suggestion
Default error
β£οΈ
This is an outrage. This is not Golang which requires stupid comments even on obvious code, and of course it's not smart enough to understand URLs or other technical things that might get corrupted by the addition of a period. Utterly trash.
dotnet_diagnostic.SA1518.severity = none
Default error
β£οΈ
This could be even worse than SA1629. It's a constructor - obviously it creates an instance of the relevant class or struct. What bloat!! This is not Golang.
dotnet_diagnostic.SA1642.severity = none
There was a bug in the ASP.NET Templates for a while which caused else and finally blocks to want to collapse. While in my opinion, } else {
, which is preferred in the JS world is totally fine, having a line feed after the else, but not before it pleases no one. I think C# should use the tall formatting that it has always had.
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
It should be noted that I believe this problem is somewhat widespread due to the settings in the default .editorconfig distributed with the Visual Studio templates. In the ASP.NET repo at least, this issue has been corrected at least.