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

Analysers should ignore code with [GeneratedCode] attribute #26

Open
afscrome opened this issue Aug 10, 2015 · 3 comments
Open

Analysers should ignore code with [GeneratedCode] attribute #26

afscrome opened this issue Aug 10, 2015 · 3 comments

Comments

@afscrome
Copy link

The diagnostics should ignore any code in classes/methods decorated with System.CodeDom.Compiler.GeneratedCodeAttribute.

The following two tests demonstrate this issue. I had a look through the code to see if I can fix it, found the Extensions.IsGeneratedcode method, but got stuck past that as I'm not sure how to determine if the node being analysed is in the context of a GeneratedCode attribute.

        [Test]
        public void VerifyNotAvailableInClassWithGeneratedCodeAttribute()
        {
            const string code = @"
using System;
[System.CodeDom.Compiler.GeneratedCode()]
class C
{
    void M(int x)
    {
        throw new ArgumentNullException(""x"");
    }
}";

            NoDiagnostic(code, DiagnosticIds.UseNameOf);
        }

        [Test]
        public void VerifyNotAvailableInMethodWithGeneratedCodeAttribute()
        {
            const string code = @"
using System;
class C
{
    [System.CodeDom.Compiler.GeneratedCode()]
    void M(int x)
    {
        throw new ArgumentNullException(""x"");
    }
}";

            NoDiagnostic(code, DiagnosticIds.UseNameOf);
        }
@DustinCampbell
Copy link
Owner

Great suggestion!

@DustinCampbell
Copy link
Owner

I've submitted PR #31 to consider files containing comment headers with as generated code. Would this address your particular scenario?

@afscrome
Copy link
Author

That would address my scenario. I have however been looking at this myself and came up with a way of using the attribute itself which I've submitted in PR #33.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants