credo icon indicating copy to clipboard operation
credo copied to clipboard

FunctionNames readability check does not recognize an acronym when followed by a symbol

Open nickgnd opened this issue 3 years ago • 0 comments

Hey 👋 First of all thanks for all the work and effort you put in Credo 🙇

Precheck

  • For bugs, please do a quick search and make sure the bug has not yet been reported here ✅

Environment

  • Credo version (mix credo -v): 1.6.6
  • Erlang/Elixir version (elixir -v): 1.13.4-otp-24 (erlang 24.0.6)
  • Operating system: OSx Monterey

What were you trying to do?

Allow acronyms for the check Credo.Check.Readability.FunctionNames

{Credo.Check.Readability.FunctionNames, [allow_acronyms: true]},

Expected outcome

No Code Readability issue if there is a function with an acronym.

Specifically, this is the function

defp is_JA?(…) do
end

Actual outcome

Code Readability error

[R] ↗ Function/macro/guard names should be written in snake_case.

As far as I can see the issue is in this function:

https://github.com/rrrene/credo/blob/2e0c540fddd8021a8cca15f5d4b2cd99473b82f7/lib/credo/code/name.ex#L116-L122

Specifically in the regex: ~r/^([[:lower:][:digit:]]+|[[:upper:][:digit:]]+)$/u

I does not allow ? (or !).

I think this should work ~r/^([[:lower:][:digit:]]+|[[:upper:][:digit:]]+[\?!]?)$/u

Let me know if it is clear. Happy to open a PR if you prefer.

nickgnd avatar Aug 25 '22 20:08 nickgnd