Open nguyenlamlll opened 4 years ago
StyleCop Analyzers does not enable rules in generated code files. Can you provide some additional information about the files where you want to disable it?
I'm talking about migration files generated by EF Core (or EF In general) in code-first approach.
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Migrations
{
public partial class Name: Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{ ... }
protected override void Down(MigrationBuilder migrationBuilder)
{ ... }
}
}
They are generated with using statements outside of namespace scopes.
Are these files generated once (e.g. the way a new file gets created from a template), or repeatedly (e.g. the way .xaml files generate a code file in the obj directory during each build)?
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.
...A few new files...
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:
They are completely new each time. Saying, 2 files per time. So, after we run CLI things 3 times, we have 6 files.
I see that your suggestions might be alright for us. Thank you.
Besides that, I don't know if I can suppress SA1200 for a whole file or namespace? Just curious now.
File a bug for EF requesting that the code template honor the .editorconfig setting that instructs the IDE to place using directives inside namespaces
I assume it would also suffice if they'd prepend // <auto-generated />
to the migration file? They also don't place trailing commas, which is another source of warnings.
I don't know if it's possible to disable rules per namespace, but you can disable them per path in editorconfig file:
[{Folder1/*.cs,**/Folder2/*.cs}]
dotnet_diagnostic.SA1200.severity = none
Hi 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:
In my
GlobalSupressions.cs
file, I have: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.