Tuesday 4 November 2014

FXCop and built-in rules: CA1723 and "Use preferred terms" for Canceling

FXCop has some built-in rules for complaining about a UK spelling of "Canceled", e.g. "Cancelled".

If you override the section

<Term PreferredAlternate="Cancelled">canceled</Term>

it doesn't work and it still complains about the word "Cancelled".

However if you set it to

<Term PreferredAlternate="Andy">canceled</Term>

it then raises CA1723 and suggest you change it to "Andy".
If you remove the line completely it still complains about the word "Cancelled" and suggests "Canceled".

So the behavior is relying upon a default rule and error cannot be configured out using the PreferredAlternate section of the CustomDictionary; it looks like it can only changed to an alternative spelling.

However there is a way! Looking at the FX Cop IL, it can be seen that if you set the US spelling as an unrecognized term


then it overrides the built-in rule and the error disappears!

No comments:

Post a Comment