Can you prevent the usage of #pragma warning disable?

191 Views Asked by At

Recently, our team has tried to become more strict about enforcing certain code style and quality guidelines. I'm trying to automate this as much as possible, using .editorconfig files to enforce certain rules--in many cases preventing a build instead of generating a warning that will just be ignored.

Of course, not everyone is super enthusiastic about this, and now people are just adding #pragma disable directives to get around the rules we are trying to enforce. Is there any way to prevent people from doing this? I can't seem to find any info on preventing the usage of #pragma disable. I know the best way to solve this would be to foster a culture where people wouldn't even think of doing this, but I am a bit jaded about that ever happening with my team.

1

There are 1 best solutions below

2
On BEST ANSWER

Been there, done that. In the beginning, a lot of programmers will be arguing over the new rules or try to work around them, even if they where agreed on in the team. But this will eventually calm down when people get used to the rules. You should make sure that at least new code follows the rules (i.e. by consistent reviews). Old code can be adapted over time or when it needs touching. Also consider reviewing the rules after some time, maybe there are some which are not useful in your scenario and can be disabled again. When enabling the full set of StyleCop rules, there are some where I personally don't see that they help in improving readability or consistency of the code. So questioning the use of a certain rule must be legitimate.