Credence.Pattern.NoPipedRegexReplace
(credence v0.4.4)
Copy Markdown
Detects Regex.replace used as a pipe target and replaces it with
String.replace, which accepts the string as its first argument.
Regex.replace/3 expects (regex, string, replacement) — regex first.
When used in a pipeline, the pipe injects the left-hand value as the
first argument, putting the string where the regex should be:
input |> Regex.replace(~r/[^a-z0-9]/, "")
# becomes: Regex.replace(input, ~r/[^a-z0-9]/, "")
# ^^^^^ string in regex position — crashString.replace/3 takes (string, pattern, replacement) and accepts
regex patterns, so it is a drop-in replacement that works in pipelines:
input |> String.replace(~r/[^a-z0-9]/, "")