Search code examples
c#ridereditorconfig

Can't suppress CA1307 warning in Rider


We have an .editorconfig file which has coding style requirements for all our projects. Part of the team use Rider, another part use VS. I'm trying to suppress CA1307 warning like this:

dotnet_diagnostic.CA1307.severity = none

Visual Studio recognizes it just fine, but Rider still shows this as a warning. It's getting suppressed though when I'm using

#pragma warning disable CA1307

and such weird behavior is only with this particular rule, other work ok. Is there something special about it or am I doing something wrong?


Solution

  • I figured what's the problem was so want to share my findings in case someone will run across the same issue. It appears that this rule and some other, like 1304, 1305, 1309, 1311 etc. are global, and therefore cannot be suppressed in .editorconfig. There are multiple ways to do it though:

    1. <NoWarn>1304,1305 ...</NoWarn> in .csproj file

    2. Adding .globalconfig file along with .editorconfig

      is_global = true
      
      dotnet_diagnostic.CA1304.severity = none
      dotnet_diagnostic.CA1305.severity = none
      dotnet_diagnostic.CA1307.severity = none
      dotnet_diagnostic.CA1309.severity = none
      dotnet_diagnostic.CA1311.severity = none
      

    Bad thing about these 2 options is that they work just fne in VS, but Rider does not support both and keeps highlighting these warnings (they have pending tickets for this, but still not fixed). So, because we share these settings and devs are using both Rider and VS, I ended up wit option

    1. GlobalSuppressions.cs file. It has to be placed in the root of the project and looks like this:

      using System.Diagnostics.CodeAnalysis;
      
      [assembly: SuppressMessage("Globalization", "CA1304:Specify CultureInfo", Justification = "Not needed in context of our projects", Scope = "module")]
      [assembly: SuppressMessage("Globalization", "CA1311:Specify a culture or use an invariant version", Justification = "Not needed in context of our projects", Scope = "module")]
      [assembly: SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "Not needed in context of our projects", Scope = "module")]
      [assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Not needed in context of our projects", Scope = "module")]
      [assembly: SuppressMessage("Globalization", "CA1309:Use ordinal StringComparison", Justification = "Not needed in context of our projects", Scope = "module")]
      

    This way it works both in Rider and VS. Hope it'll help someone.