inaka / elvis_core

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

Problem with atom on line -1 related to maybe ... end clause #344

Closed Pedro-Giorgiano closed 5 months ago

Pedro-Giorgiano commented 5 months ago

Bug Description

During rebar3 lint I got a warning on line -1 which is related to the maybe ... end clause

To Reproduce

-module(test_maybe).

-feature(maybe_expr, enable).

-export([sum_numbers/2]).

sum_numbers(Number1, Number2) ->
    maybe
        ValidNumber1 ?= validate_number(Number1),
        ValidNumber2 ?= validate_number(Number2),
        Result = ValidNumber1 + ValidNumber2,
        io:format("Results: ~p~n", [Result])
    else
        {error, invalid_number} ->
            {error, "One or both inputs are invalid numbers"}
    end.

validate_number(Number) when is_number(Number) ->
    Number;
validate_number(_) ->
    {error, invalid_number}.

Expected Behavior

no warning on line -1

rebar3 Logs

===> elvis analysis starting, this may take a while...
# src/test_maybe.erl [FAIL]
  - atom_naming_convention (https://github.com/inaka/elvis_core/tree/main/doc_rules/elvis_style/atom_naming_convention.md)
    - Atom [] on line -1 does not respect the format defined by the regular expression '"^[a-z]([a-z0-9@]*_?)*(_SUITE)?$"'.
===> Linting failed

Additional Context

paulo-ferraz-oliveira commented 5 months ago

👋

What elvis.config are you using?

I cannot replicate your issue by doing:

  1. create a rebar3 lib, using rebar3 new lib
  2. adding rebar3_lint to plugins in rebar.config
  3. adding your example code to the lib.
  4. running rebar3 lint

Maybe an example repo. where the issue is apparent in e.g. CI would help us debug further.

Edit: I can partially replicate your issue if I introduce an elvis.config. On the other hand, removing -feature( makes the issue go away. Do you need to run the code under OTP 25, or any other specific version?

Pedro-Giorgiano commented 5 months ago

Hello!! I created a repository to exemplify the problem, the elvis.config is there if you want to take a look: https://github.com/Pedro-Giorgiano/maybeEndExample

Apparently if we add the match with empty strings in the atom related regex, the warning disappears "^$|^[a-z]([a-zA-Z0-9@]*_?)*(_SUITE)?$"

paulo-ferraz-oliveira commented 5 months ago

This is katana-code giving us this result, as an atom node:

{line,#{type=>atom,attrs=>#{value=>non_reversible_form,location=>{-1,-1},text=>[]}}}

from which we extract line -1 (from location) and text [].

elbrujohalcon commented 5 months ago

First time I see that non_reversible_form thingy. (Not happening in the near future, but) I'll have to update my knowledge on Erlang's AST at some point.