Fix prefer-to-have-count rule for expect arguments that need dereferencing #292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ISSUE #293:
The current prefer-to-have-count rule has a problem where any expect checks that take a variable argument will not check to make sure the value is not originating from a .count call.
For example the following code would not be flagged as an error:
The current code misses this case because we are not dereferencing the last assigned value of
filesCount
at the moment of verifying the expect argument. The rule should flag the error and return the following as a fix:SOLUTION:
This PR updates the
prefer-to-have-count
code to re-use thedereference
method previously used by theprefer-web-first-assertion
rule. To make this method available to other files I moved it, along with all its related methods, to theast.ts
file which looked to me like the best place to centralize it (curious to know if there is a better place for these methods though).I have added multiple new tests to check for other edge cases like variable re-assignment.