Oct 1, 2010 at 8:14 PM
Edited Oct 1, 2010 at 8:17 PM
I recommend adding an issue to Issue Tracker for this. I believe default parameters are new to C# 4.0 so this issue was probably just missed with the upgrade to support it.
I took a quick stab at debugging this issue, but have run out of time, and won't be able to continue (at least not today and may be a few days before I could reasonably attack it again)... if someone else wants to pick up from here, please do.
In CheckEmptyString in ReadabilityRules.cs, @string.FindParentElement() is returning null. (As a side note, "@string" really? I think I'll add a request later for a rule to not use such characters in variable names, as there is
always something better you can name it. Off the top of my head, "tokenString" here works. "@string.Something()" can mislead a coder to think "Is there some extension method of the "string" class AND some usage
of the @ operator, that I'm unaware of?")
Anyway, my gut feeling, looking at the following statement, is that we need to add code to handle the default parameters cases:
if (previousToken == null || (previousToken.Value.CsTokenType != CsTokenType.Case && !IsConstVariableDeclaration(previousToken)))
Can be logic something like:
if (previousToken == null || (previousToken.Value.CsTokenType != CsTokenType.Case && !(IsConstVariableDeclaration(previousToken) || IsDefaultParameterization(previousToken))))
(At this point, it would make sense to add statements to simplify the if statement itself.) Add an IsDefaultParameterization(Node<CsToken> assignmentOperator) method to follow the IsConstVariableDeclaration method which operates as
you'd expect and I think that's all there is to it.