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

[ResxSourceGenerator] Add a NoWarn attribute #7489

Merged

Conversation

dvoituron
Copy link
Contributor

[ResxSourceGenerator] Add a NoWarn attribute

See #7478

Analyzer

Microsoft.CodeAnalysis.ResxSourceGenerator

Describe the improvement

Currently, a number of problems with Code Analyzers are being reported by developers, related to the generated file.
For example, the requirement for comments on public members (CS1591).

It would be possible to correct each request individually, but a more “global” solution would allow Warnings code to be ignored. Like C# Compiler or csproj propose with its NoWarn attribute (see doc), this attribute provides the same solution.

Describe suggestions on how to achieve the rule

I added a new NoWarn attribute to list all Warning code to ignore (ex. CS1591),
added #pragma warning disable CS1591 at the top of the file
and #pragma warning restore CS1591 at the end of the file

<ItemGroup>   
  <EmbeddedResource Update="Localization\Resources.resx">
    <Public>true</Public>
    <NoWarn>CS1591, IDE0010</NoWarn>
  </EmbeddedResource>
</ItemGroup>
// <auto-generated/>

#pragma warning disable CS1591, IDE0010

#nullable enable
using System.Reflection;


namespace TestProject
{
    public static partial class Resources
    {
        private static global::System.Resources.ResourceManager? s_resourceManager;
        public static global::System.Resources.ResourceManager ResourceManager => s_resourceManager ?? (s_resourceManager = new global::System.Resources.ResourceManager(typeof(Resources)));
        public static global::System.Globalization.CultureInfo? Culture { get; set; }
        [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        [return: global::System.Diagnostics.CodeAnalysis.NotNullIfNotNull("defaultValue")]
        internal static string? GetResourceString(string resourceKey, string? defaultValue = null) =>  ResourceManager.GetString(resourceKey, Culture) ?? defaultValue;
        /// <summary>value</summary>
        public static string @Name => GetResourceString("Name")!;

    }
}

#pragma warning restore CS1591, IDE0010

Unit Tests

New unit tests are added to verify this new feature (C# and VB)

@dvoituron dvoituron requested a review from a team as a code owner November 28, 2024 11:11
Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 96.20253% with 3 lines in your changes missing coverage. Please review.

Project coverage is 96.50%. Comparing base (5435ba7) to head (4cec831).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7489      +/-   ##
==========================================
- Coverage   96.50%   96.50%   -0.01%     
==========================================
  Files        1450     1450              
  Lines      347319   347392      +73     
  Branches    11409    11413       +4     
==========================================
+ Hits       335184   335251      +67     
- Misses       9244     9248       +4     
- Partials     2891     2893       +2     

@Youssef1313
Copy link
Member

@sharwell if you can review this one

@sharwell sharwell merged commit 9e2b9b8 into dotnet:main Dec 3, 2024
11 checks passed
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.

3 participants