audaciaconsulting / Audacia.CodeAnalysis

MIT License
1 stars 4 forks source link

Raise a SA1404 (or equivalent) if helper attributes are used without a justification #52

Open OwenLacey28 opened 1 month ago

OwenLacey28 commented 1 month ago

Attributes like MaxParmeterCount and MaxMethodLength provide a Justification parameter, but don't enforce it.

I would like it so that a lack of this parameter raises a diagnostic, like with SuppressMessage: image

We could equally make the justification parameter required, but that would be a breaking change.

jackpercy-acl commented 1 month ago

Agreed, it is all too easy to use those attributes, when a lot of times you could refactor.

Looks like the code of SA1404 is very specific to SuppressMessage so would would need our own implementation, but that can at least cover both of our attributes and more in the future - https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/StyleCop.Analyzers/StyleCop.Analyzers/MaintainabilityRules/SA1404CodeAnalysisSuppressionMustHaveJustification.cs

We could perhaps include SuppressMessage in our attribute, and disable SA1404 in our configs? That feels more consistent with how we have enhanced other existing rules? Plus it means one warning code for all violations?

OwenLacey28 commented 1 month ago

@jackpercy-acl nice idea. An alternative is whether we can raise diagnostics that aren't ours e.g can we manually raise a SA1400?