WiseTechGlobal / WTG.Analyzers

Analyzers from WiseTech Global to enforce our styles, behaviours, and prevent common mistakes.
Other
16 stars 3 forks source link

Analyzer to request named parameters for bool literals in method arguments. #123

Closed yaakov-h closed 4 years ago

yaakov-h commented 4 years ago

I feel like I've covered pretty much everything here, though I haven't yet given it a twirl with BulkAnalysisRunner.

If we find a method invocation where a parameter is explicitly typed as bool (i.e. not a generic parameter), then we require that the method be invoked as a named parameter to aid in clarity when reading the code.

If the codebase is C# 7.1 or lower then we skip warnings for all parameters except the last one, since C# 7.2 introduced the ability to name any parameter.

I didn't think it was wise to require users to also name all their parameters after the boolean literal, or to upgrade to C# 7.2. Though, at this point, I'd be surprised if any of our code wasn't on C# 7.3 or 8.0 yet (with 9.0 scheduled for release next month!!).