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

Warnings are not treated as errors even if all settings are set correctly #57539

Closed
hasrthur opened this issue Nov 3, 2021 · 1 comment
Closed

Comments

@hasrthur
Copy link

hasrthur commented Nov 3, 2021

Hi! Hope you are doing great!

I faced a problem with my project where I wanted all analyzers warnings to be errors. I simply can't make all warnings into errors.

To reproduce an issue I created a simple project: https://github.com/hasrthur/DotNetCoreWarningsTest.

Version Used: 6.0.100-rc.2.21505.57

Steps to Reproduce:

.editorconfig has a settings to treat all analyzers violations as errors.

dotnet_analyzer_diagnostic.severity = error

*.csproj file has the same setting set

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AnalysisMode>AllEnabledByDefault</AnalysisMode>
    <AnalysisLevel>latest</AnalysisLevel>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <NoWarn>CA1014,CA1812</NoWarn>
  </PropertyGroup>

</Project>

Program.cs contains redundant using statement

using System; // <- this should trigger error
// See https://aka.ms/new-console-template for more information
Console.WriteLine(42);

Rider shows that line as error.

But when I build a project either via rider or console the build succeeds.

Even if I add

dotnet_diagnostic.IDE0005.severity = error

to .editorconfig it has no effect at build time but when I add

dotnet_diagnostic.IDE0005.severity = none

the warning/error disappears in rider

Expected Behavior:
Build fails with error

Actual Behavior:
Build is successful without any warning

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 3, 2021
@jinujoseph jinujoseph added Bug Investigation Required and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 4, 2021
@jinujoseph jinujoseph added this to the 17.1 milestone Nov 4, 2021
@mavasani
Copy link
Contributor

Duplicate of #41640 (comment)

@mavasani mavasani marked this as a duplicate of #41640 Dec 22, 2021
mavasani added a commit to mavasani/roslyn that referenced this issue Jan 13, 2022
…ngs) on build

Due to dotnet#41640, enabling IDE0005 on build requires users to enable generation of XML documentation comments. Even though this is documented with a note on IDE0005's [doc page](https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0005), we have had numerous reports of users not figuring this out and spending lot of cycles fighting with this, especially given other IDE diagnostics work just fine on build. We have had many user reports of the same: dotnet#58103, dotnet#53720, dotnet#57539, OpenRA/OpenRA#19747 and numerous other offline queries.

This change enhances the IDE0005 analyzer to now detect the case when IDE0005 is being reported as a warning or an error in the IDE, but `GenerateDocumentationFile` is `false` for the project, which would mean IDE0005 wouldn't be reported on build. The analyzer reports a special helper diagnostic for this case, which recommends  the user to set this property to `true` in their project file to enable IDE0005 on build. This should reduce the pain for customers who try to enforce IDE0005 on build and get hit by this issue.
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

3 participants