Closed frerich closed 1 year ago
@rrrene I believe the 'reproducing test-case detector' check is a false negative: it would pass if the test/test_if_tests_fail_after_resetting_lib.sh
script would pass --no-overlay
to the git checkout
invocation.
As it is, git checkout is used in "overlay" mode, i.e. checking out the lib/
directory as it is in the master
branch will not remove any files. Thus, the new lib/credo/check/refactor/filter_count.ex
added by this PR does not get removed and consequently the new test/credo/check/refactor/filter_count_test.exs
test won't fail.
@frerich This is by design. The mentioned action is used to see if a bugfix is coming with a reproducing test.
The fail is not relevant for this PR.
This is part of Credo v1.7.0-rc.1 :+1:
This extends Credo such that it looks for use cases for Enum.count/2. Alas, I only learned about https://github.com/rrrene/credo-proposals after creating these commits so this PR is 'out of the blue'. 😔 However, I hope that it's not too controversial since the proposed refactoring is much like the one for
Enum.map_join/3
.Using
Enum.count/2
instead of composingEnum.filter/2
withEnum.count/1
is preferable sinceEnum.count/2
requires just a single pass, so it's a little more efficientThe check ID
EX4030
was determined by checking the other IDs and simply picking the next larger value; the largest check ID for refactoring checks appears to beEX4029
, so that's how I ended up withEX4030
. 😊The test suite exercises various ways of composing
Enum.filter/2
andEnum.count/1
, making sure that uses of the|>
operator don't confuse the check and that e.g. usingEnum.filter/2
withEnum.count/2
does not trigger.