Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
String interpolation check not applied to first key/value pair of hash. #24
Foodcritic will normally warn if one uses unnecessary variable interpolation, such as:
The generated error looks like this:
For some reason, food critic does not apply this check to the first key/value pair in hashes. See below:
Foodcritic only reports the second hash entry as having the problem:
Now, observe what happens when we insert a new entry, as first entry, that doesn't have unnecessary interpolation:
Here is the new foodcritic output:
This time, foodcritic sees both occurrences. Just to be sure, let's change the first entry of the hash to contain unnecessary interpolation, so that we have three straight entries containing unnecessary interpolation:
Confirmed. The first key/value pair is apparently not checked for unnecessary interpolation. Looks like a bug.
Thanks a lot for raising this and for the very thorough steps to reproduce.
I think this may have been fixed in a unreleased change in 23ed692. This change has not been released to the gem yet, but if you're able to build from head I'd expect it to give the correct result.
I'm planning to release an updated gem with this fix and others this week.
I was wrong - this bug was still there in master. The earlier commit had fixed the AST up, but this rule needed to be updated (in 76303d8) to reflect that. It should now be working correctly in master.
Thanks again for the great steps to reproduce and for taking the time to contribute to foodcritic.