Fix Credo 1.7.14 ExpensiveEmptyEnumCheck warningsFix Credo 1.7.14 ExpensiveEmptyEnumCheck warnings #5800
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.
This PR fixes the Credo 1.7.14 warnings introduced by the
ExpensiveEmptyEnumCheckcheck.Changes
Replaced expensive
length/1checks withEnum.empty?/1in 4 test files:test/elixir/test/replication_test.exs- Line 1674test/elixir/lib/couch/dbtest.ex- Line 199test/elixir/test/partition_size_limit_test.exs- Line 231test/elixir/test/basics_test.exs- Line 67Rationale
The
Enum.empty?/1function is more performant thanlength/1for checking if a list is empty because:Enum.empty?/1only needs to check if there's at least one elementlength/1must traverse the entire list to count all elementsThese changes are semantically equivalent:
length(list) > 0≡not Enum.empty?(list)length(list) >= 1≡not Enum.empty?(list)Testing
All changes are in test files and maintain the same logical behavior. The modifications follow Elixir best practices for performance optimization.
Fixes #5799Replace expensive length/1 checks with Enum.empty?/1 in test files to resolve Credo warnings introduced in version 1.7.14.
Changes:
These changes are semantically equivalent but more performant as Enum.empty?/1 only checks for the first element instead of traversing the entire list.
Fixes #5799
Overview
Testing recommendations
Related Issues or Pull Requests
Checklist
rel/overlay/etc/default.inisrc/docsfolder