Skip to content

Conversation

@trolleyman
Copy link

@trolleyman trolleyman commented Jan 6, 2026

Warnings in #pragma warning disable can be non-numeric (and I think can be any alphanumeric value for source analyzers, doesn't even just start with alphabetic and then ends with numeric). I've updated the regex to support this, and also tweak it so that it supports >2 warnings at once. I've kept it as constant.numeric.decimal.cs, but might be good for this to be changed also? Maybe constant.other.warning-id.cs? Something else entirely?

I encounter this issue a lot, and had thought it was something to do with comments after #pragma, so that's why there are a few tests that check that this works.

Demo:

public class Program
{
#pragma warning disable IDE1000 // Comment
    private int m_test1 = 1;
    private string m_test2 = 1; // Sort of fine, though tokens are wrong. If a comment is added above, this breaks.
#pragma warning disable CS0101, IDE001, ABC031, ERROTHER // >2 errors, and non-ABC123 error name

    public static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");    
    }

#region Static // Comment
    void ThisFunctionIsOk()
    {
        // This function is tokenized ok
    }
#endregion // This comment breaks things again
    private int m_something;
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant