inaka / elvis_core

The core of an Erlang linter
Other
61 stars 56 forks source link

Wildcards in no_call_functions MFA #325

Closed attah closed 1 year ago

attah commented 1 year ago

Is your feature request related to a problem? Please describe

Wildcards in no_call_functions MFA, i.e. rules that applies regardless of module name and/or function name and/or arity.

Describe the solution you'd like

Being able to do:

#{dirs => ["."],
       filter => "*tests.erl",
       rules =>
           [{elvis_style, no_call,
             #{no_call_functions => [{'*', handle_event, 4}]]
      }

Describe alternatives you've considered

Dynamically generating rule definitions... too much work.

Additional Context

It is ridiculous to test a state machine without a running process, and with state data that it has not produced itself. Running the statem/server callbacks explicitly from tests is the biggest antipattern i know in testing.

elbrujohalcon commented 1 year ago

I think this is a great idea. I would use '_' as the "anything" pattern and maybe consider accepting {module_name, function_name} tuples to indicate "any arity", but I do like the idea.

attah commented 1 year ago

Right, underscore is a lot more "Erlang". Not sold on the two-tuple though; why not just wildcard arity?

elbrujohalcon commented 1 year ago

Yeah, wildcard ariity is fine.

attah commented 1 year ago

Looks like your two-tuple may already work. https://github.com/inaka/elvis_core/blob/361e26f6c0d0a990dce412b8bcf768cb27c9ae48/src/elvis_style.erl#L1974

And it looks like it will be very easy to add what i want... let's see if i can't get some time for this soon.