SA1200 How to suppress it for a few files (namespaces)?
See original GitHub issueHi everyone, I meet this scenario when I try to disable rules for auto-generated files of EF Core. I can suppress a few other messages for the scope namespaceanddescendants
, targeting migration files’ namespaces.
However, I cannot suppress SA1200 for some reasons (bug, or by design?).
Auto-generated code:
using System;
using Microsoft.EntityFrameworkCore.Migrations; // These 2 using statements throw warning
namespace My.Data.Migrations.Parent.Namespace
{
...
}
In my GlobalSupressions.cs
file, I have:
[assembly: SuppressMessage(
"StyleCop.CSharp.OrderingRules",
"SA1200:UsingDirectivesMustBePlacedWithinNamespace",
Justification = "Auto-generated by EF Core.",
Scope = "namespaceanddescendants",
Target = "My.Data.Migrations.Parent.Namespace")]
This does not work. I have also tried “member”, “resource”, “module”, “type”, “method”, “namespace”. Nothing works.
Moreover, the way that the document suggests is not really suitable for me because I don’t want to suppress the message for the whole assembly.
So, my question is that can we suppress SA1200 for files/namespaces? (and how?) Thank you all.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
SA1200 is firing for global usings · Issue #3404
It's clear that Microsoft has been working hard to reduce boilerplate with file-scoped namespaces, implied Main method, record types and ...
Read more >StyleCopAnalyzers/documentation/SA1200.md at master
When multiple namespaces are defined within a single file, placing using directives within the namespace elements scopes references and aliases.
Read more >c# - Stop Visual Studio from putting using directives outside ...
You can set this in Re-sharper. Re-sharper > Options > C# > Namespace Imports > Add using directive to the deepest scope.
Read more >Using statements inside or outside of namespace? : r/csharp
Rule SA1200 - A C# using directive is placed outside of a namespace ... I've seen some "enterprisey" code have it inside the...
Read more >CA1020: Avoid namespaces with few types - Visual Studio ...
It is safe to suppress a warning from this rule when the namespace does not contain types that are used with the types...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Are these new files with new names, or do they overwrite files? Put another way, after the pragma lines are added, will the code generator ever overwrite the file and remove them?
If each file is only generated one time, my suggestion would be:
More of “repeatedly”. When the devs make changes to the database models, they run the CLI. A few new files (one is the example I gave above) will be generated. So, our current workflow after each CLI run like that is to go into the files and put
#pragma warning disable
to every file that is generated.Using GlobalSupressions, I was able to suppress other warnings. The only left is SA1200.