Search code examples
static-analysisstylecopsuppress-warnings

StyleCop - Suppress rule only for method name


For example, My naming rule for a method is SampleName and for parameter it is sampleName. In the following code I do not have control over method name as it is public and virtual so I can't change it to GetIds to match my naming rule.

public override void GetIDs(ref string[] availableDefinitionElementIDs)
{
}

In order to build my program successfully I have to suppress following rule.

[SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Justification = "?")]

But problem here is that it also suppresses warnings for parameter list and any code within the method.

Is it possible suppress rule only for specific element of a method?


Solution

  • I believe you can not suppress message only for the method declaration line in StyleCop.

    As for your particular StyleCop+ issue, you could

    • add "IDs" to the "Compound words / abbreviations" StyleCop+ setting

    or

    • add "GetIDs" in method naming rules (as an exception)
    • add "availableDefinitionElementIDs" in parameter naming rules (as an exception)