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

IDE0005 not reported as build warning #58103

Closed
fabio-muramatsu opened this issue Dec 3, 2021 · 3 comments
Closed

IDE0005 not reported as build warning #58103

fabio-muramatsu opened this issue Dec 3, 2021 · 3 comments

Comments

@fabio-muramatsu
Copy link

I have a simple project where I'm trying to enforce code style rules in build. It seems to be mostly working, but for some reason I noticed that IDE0005 warning doesn't show up when building the project, even though it is set as warning in my editorconfig file.

Here's what my csproj looks like:

<Project Sdk="Microsoft.NET.Sdk">
  
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <AnalysisLevel>latest-Recommended</AnalysisLevel>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
  </PropertyGroup>
  
</Project>

Here's my editorconfig file. I've followed the instruction from this thread and set the severities using the IDExxxx code so they can be recognized by the compiler. I'm explicitly covering IDE0005 in my editorconfig:

dotnet_diagnostic.IDE0005.severity = warning # Remove unnecessary import

And here's a Program.cs file that triggers a bunch of code style warnings:

using System;
using System.Threading.Tasks;

namespace CSSandbox
{
    class Program
    {
        static async Task Main(string[] args)
        {

        }
    }
}

Building this, the compiler reports many IDExxxx warnings, which indicates that my editorconfig file is being at least partially taken into account when building:

Program.cs(8,27,8,31): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
Program.cs(4,1,4,20): warning IDE0161: Convert to file-scoped namespace
Program.cs(8,41,8,45): warning IDE0060: Remove unused parameter 'args'
Program.cs(8,27,8,31): warning IDE0040: Accessibility modifiers required
Program.cs(6,11,6,18): warning IDE0040: Accessibility modifiers required

IDE0005 is missing from that list, though. I can see it being detected in the VS UI:
image

Is there anything I'm missing here? When I change the severity of IDE0005 in my editorconfig file, it reflects in the VS UI, but the build doesn't seem to catch it. It tried both building this from VS and from the command line, and the results are the same. I'd appreciate any pointers here.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 3, 2021
@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.

@Youssef1313
Copy link
Member

cc @mavasani

@mavasani
Copy link
Contributor

mavasani commented Dec 5, 2021

Duplicate of #41640 (comment)

@mavasani mavasani marked this as a duplicate of #41640 Dec 5, 2021
@jinujoseph jinujoseph removed the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 9, 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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants