Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect ambiguity in function calls without parentheses #1145

Open
Artur-Sulej opened this issue Aug 2, 2024 · 1 comment
Open

Detect ambiguity in function calls without parentheses #1145

Artur-Sulej opened this issue Aug 2, 2024 · 1 comment

Comments

@Artur-Sulej
Copy link

Precheck

Environment

  • Credo version (mix credo -v): 1.7.3
  • Erlang/Elixir version (elixir -v): 1.16.2/OTP 26
  • Operating system: MacOS

What were you trying to do?

I'm running mix credo --strict and getting this warning:

warning: missing parentheses for expression following "do:" keyword. Parentheses are required to solve ambiguity inside keywords.

This error happens when you have function calls without parentheses inside keywords. For example:

    function(arg, one: nested_call a, b, c)
    function(arg, one: if expr, do: :this, else: :that)

In the examples above, we don't know if the arguments "b" and "c" apply to the function "function" or "nested_call". Or if the keywords "do" and "else" apply to the function "function" or "if". You can solve this by explicitly adding parentheses:

    function(arg, one: if(expr, do: :this, else: :that))
    function(arg, one: nested_call(a, b, c))

Ambiguity found at:
└─ nofilename:5

It happens because of this piece of code:

foo do: rename table(:bar), :baz, to: :qux

Expected outcome

I'd like credo to detect this ambiguity issue and add a suggestion about it to its output. That would be especially useful because the warning doesn't contain a correct path to the problematic code.

Actual outcome

This issue doesn't appear in the output.

@rrrene
Copy link
Owner

rrrene commented Aug 2, 2024

The fact that the filename is nofilename on this is definitely bad and we should fix that 👍 (this is completely Credo's fault, I believe). Could you provide an Elixir module that produces this warning?

I'd like credo to detect this ambiguity issue and add a suggestion about it to its output.

On this I am sorry, because we can not re-implement compiler checks/warnings as standard checks in Credo. Doubling the compiler's functionality would be like implementing our own formatter.

This of course does not say that this wouldn't be a great custom check or plugin, which we could also feature in the docs on how to implement custom checks 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants