Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

behaviour of sdk 5.0.2 and higher with .editorconfig differs from previous sdks #55115

Closed
askazakov opened this issue Jul 26, 2021 · 3 comments
Closed
Assignees
Milestone

Comments

@askazakov
Copy link

askazakov commented Jul 26, 2021

Version Used:

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.302
 Commit:    c005824e35

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.0
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/5.0.302/

Host (useful for support):
  Version: 5.0.8
  Commit:  35964c9215

.NET SDKs installed:
  3.1.102 [/usr/local/share/dotnet/sdk]
  3.1.409 [/usr/local/share/dotnet/sdk]
  5.0.104 [/usr/local/share/dotnet/sdk]
  5.0.205 [/usr/local/share/dotnet/sdk]
  5.0.302 [/usr/local/share/dotnet/sdk]

Steps to Reproduce:

  1. dotnet new console
  2. Add <TreatWarningsAsErrors>True</TreatWarningsAsErrors> to .csproj
  3. Add Directory.Build.props with
<Project>
    <ItemGroup>
        <PackageReference Include="SonarAnalyzer.CSharp" Version="8.26.0.34506">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
    </ItemGroup>
</Project>
  1. Add .editorconfig with
[*.cs]
# Remove unnecessary 'using' https://rules.sonarsource.com/csharp/RSPEC-1128
dotnet_diagnostic.S1128.severity = warning
  1. Replace Program.cs with
using System;

namespace example
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            // Method intentionally left empty.
        }
    }
}

6a. Add global.json with

  "sdk": {
    "version": "5.0.104"
  }
}

or
6b. Add global.json with

  "sdk": {
    "version": "5.0.205"
  }
}
  1. dotnet build

Expected Behavior:
Build output will the same
Actual Behavior:
for sdk 5.0.104 I've got

Program.cs(1,1): warning S1128: Remove this unnecessary 'using'. [...]
    1 Warning(s)
    0 Error(s)

for sdk 5.0.205 I've got

Program.cs(1,1): error S1128: Remove this unnecessary 'using'. [...]
    0 Warning(s)
    1 Error(s)

Sdk 5.0.3xx acts like 5.0.2xx

Which one is correct? Is it introduced or fixed bug between 5.0.1 and 5.0.2?

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 26, 2021
@Youssef1313
Copy link
Member

This should have been fixed in #48125. Not sure if 5.0.2 has the fix or not. cc @mavasani

@jinujoseph jinujoseph added Area-Analyzers Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 28, 2021
@jinujoseph jinujoseph added this to the 17.0 milestone Jul 28, 2021
@jmarolf
Copy link
Contributor

jmarolf commented Aug 3, 2021

as @Youssef1313 says 5.0.3xx behavior is correct. placing <TreatWarningsAsErrors>True</TreatWarningsAsErrors> in your project overrides all other options meaning all warnings are errors.

@jmarolf jmarolf closed this as completed Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants