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

Ignore code analysis warnings in extension files #21

Closed
basilfx opened this issue Jan 20, 2021 · 4 comments
Closed

Ignore code analysis warnings in extension files #21

basilfx opened this issue Jan 20, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request resolved Request has been resolved v0.3.0

Comments

@basilfx
Copy link

basilfx commented Jan 20, 2021

I'm using the 0.1.0-preview version in a C# Azure Functions V3 project, running on Linux with .NET Core SDK 3.1

Our project uses Roslyn-based code analysis during the build. This extension adds some source files for compilation, but unfortunately, these are also picked up for analysis. I cannot find a way to ignore them (tried the .editorconfig approach, but that only works for files inside the repository).

/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(29,121): warning MEN002: Line must be no longer than 120 characters (now 130). [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(48,121): warning MEN002: Line must be no longer than 120 characters (now 122). [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(66,121): warning MEN002: Line must be no longer than 120 characters (now 130). [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(86,121): warning MEN002: Line must be no longer than 120 characters (now 127). [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(23,60): warning SA1311: Static readonly fields should begin with upper-case letter [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(23,26): warning SA1206: The 'static' modifier should appear before 'readonly' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTriggerContext.cs(31,13): warning SX1101: Do not prefix local calls with 'this.' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTriggerContext.cs(32,13): warning SX1101: Do not prefix local calls with 'this.' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTriggerContext.cs(38,13): warning SX1101: Do not prefix local calls with 'this.' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTriggerContext.cs(39,13): warning SX1101: Do not prefix local calls with 'this.' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTriggerContext.cs(78,20): warning SX1101: Do not prefix local calls with 'this.' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTriggerContext.cs(99,20): warning SX1101: Do not prefix local calls with 'this.' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(19,30): warning CA1823: Unused field 'V3' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(20,30): warning CA1823: Unused field 'JSON' [/path/to/my/Project.csproj]
/home/basilfx/.nuget/packages/microsoft.azure.webjobs.extensions.openapi/0.1.0-preview/contentFiles/any/netstandard2.0/OpenApi/OpenApiHttpTrigger.cs(21,30): warning CA1823: Unused field 'YAML' [/path/to/my/Project.csproj]

I manually modified the files and added // <auto-generated> on the first line, which solves it 'temporary'.

@basilfx basilfx changed the title Roslyn-based code analysis Ignore code analysis warnings in extension files Jan 20, 2021
@danielabbatt
Copy link
Contributor

You can also use the global suppression file technique to suppress any messages from files you don't want to edit, i.e. linked ones like this.

@basilfx
Copy link
Author

basilfx commented Jan 25, 2021

Took me some time to get this right. The trick was to set the Scope to namespaceanddescendants. Here is how I suppressed the warnings (note that this depends on your own set of code analysis rules):

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage(
    "Design",
    "CA1823",
    Justification = "Auto-generated code.",
    Scope = "namespaceanddescendants",
    Target = "~N:Microsoft.Azure.WebJobs.Extensions")]
[assembly: SuppressMessage(
    "Design",
    "MEN002",
    Justification = "Auto-generated code.",
    Scope = "namespaceanddescendants",
    Target = "~N:Microsoft.Azure.WebJobs.Extensions")]
[assembly: SuppressMessage(
    "Design",
    "SA1206",
    Justification = "Auto-generated code.",
    Scope = "namespaceanddescendants",
    Target = "~N:Microsoft.Azure.WebJobs.Extensions")]
[assembly: SuppressMessage(
    "Layout Rules",
    "SA1311",
    Justification = "Auto-generated code.",
    Scope = "namespaceanddescendants",
    Target = "~N:Microsoft.Azure.WebJobs.Extensions")]
[assembly: SuppressMessage(
    "Layout Rules",
    "SA1500",
    Justification = "Auto-generated code.",
    Scope = "namespaceanddescendants",
    Target = "~N:Microsoft.Azure.WebJobs.Extensions")]
[assembly: SuppressMessage(
    "Readability Rules",
    "SX1101",
    Justification = "Auto-generated code.",
    Scope = "namespaceanddescendants",
    Target = "~N:Microsoft.Azure.WebJobs.Extensions")]

Still, I would consider this a workaround (which I'm fine with for now).

@justinyoo
Copy link
Contributor

Thanks for raising this issue! It's being merged and will be shipped in the next iteration. Once it's shipped, I'll close this issue for you to have a look on your end.

@justinyoo justinyoo added the resolved Request has been resolved label Jan 29, 2021
@justinyoo justinyoo self-assigned this Jan 29, 2021
@justinyoo justinyoo mentioned this issue Feb 2, 2021
@justinyoo
Copy link
Contributor

It's been released to NuGet. Please have a look.

@justinyoo justinyoo added the enhancement New feature or request label Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request resolved Request has been resolved v0.3.0
Projects
None yet
Development

No branches or pull requests

3 participants