Styler-ify Credo rules: FilterFilter, RejectReject, ExpensiveEmptyEnumCheck, and RaiseInsideRescue#14
Merged
JesseHerrick merged 2 commits intomainfrom May 6, 2026
Merged
Conversation
- Refactor.FilterFilter: Enum.filter |> Enum.filter => single filter combined with && - Refactor.RejectReject: Enum.reject |> Enum.reject => single reject combined with || - Warning.ExpensiveEmptyEnumCheck: length(x) == 0 => x == []; Enum.count(x) == 0 => Enum.empty?(x) - Warning.RaiseInsideRescue: raise foo inside a rescue clause => reraise foo, __STACKTRACE__
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refactor.FilterFilter:Enum.filter |> Enum.filter=> single filter combined with &&Refactor.RejectReject: Enum.reject |> Enum.reject => single reject combined with ||Warning.ExpensiveEmptyEnumCheck:length(x) == 0=> x == [];Enum.count(x) == 0=> Enum.empty?(x)Warning.RaiseInsideRescue:raise fooinside a rescue clause =>reraise foo, __STACKTRACE__Note
Medium Risk
Adds new AST rewrite rules that change emitted code for common patterns (pipes, empty checks, rescue re-raises) and adjusts directive alias-lifting behavior, which could affect formatting/output in edge cases.
Overview
Styler now enforces four additional Credo rules by rewriting code: it merges chained
Enum.filter/2andEnum.reject/2pipes into a single call with a combined predicate, replaces expensive emptiness checks likelength(x) == 0/Enum.count(x) == 0withx == []orEnum.empty?/1, and rewritesraiseinsiderescueclauses toreraise ..., __STACKTRACE__to preserve stacktraces.It also changes alias-lifting so
requiredirectives are no longer rewritten via aliases (avoiding invalid ordering whererequire Barwould appear beforealias Foo.Bar), updates documentation to recommend disabling the newly covered Credo checks, and adds targeted tests for all new rewrite behaviors.Reviewed by Cursor Bugbot for commit 0462740. Bugbot is set up for automated code reviews on this repo. Configure here.