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

rebar3_lint running on umbrella project #26

Closed
joaohf opened this issue Mar 9, 2021 · 11 comments
Closed

rebar3_lint running on umbrella project #26

joaohf opened this issue Mar 9, 2021 · 11 comments

Comments

@joaohf
Copy link

joaohf commented Mar 9, 2021

Hi there!

I'm trying to use rebar3_lint in a umbrella project. I'm using rebar3_lint 0.3.2.

The following elvis.config seems to not work because elvis is not able to find any erl file:

 #{dirs => ["apps/*/src"],
        filter => "*.erl",
        ruleset => erl_files,
        rules => [{elvis_style, line_length,
                      #{limit => 80,
                        skip_comments => false
                       }},
                  {elvis_style, no_tabs},
                  {elvis_style, no_trailing_whitespace}]
       },
Warning: Searching for files in ["apps/*/src"] yielded none. Update your configuration.                                                                             │
Warning: Searching for files in ["apps/*/test/*"] yielded none. Update your configuration.

On the other hand, the following elvis.config works. But that is not what I would like to do:

 #{dirs => ["apps/fancontrol/src"],
        filter => "*.erl",
        ruleset => erl_files,
        rules => [{elvis_style, line_length,
                      #{limit => 80,
                        skip_comments => false
                       }},
                  {elvis_style, no_tabs},
                  {elvis_style, no_trailing_whitespace}]
       },
# apps/fancontrol/src/fancontrol.erl [FAIL]                                                                                                                         
Error: 'undef' while applying rule 'line_length'.                                                                                                                   
  - dont_repeat_yourself                                                                                                                                            
    - The code in the following (LINE, COL) locations has the same structure: (250, 1), (260, 1).                                         
  - no_spec_with_records                                                                                                                                            
    - The spec in line 87 uses a record, please define a type for the record and use that instead.                                     
    - The spec in line 99 uses a record, please define a type for the record and use that instead.                                
  - state_record_and_type                                                                                                                                           
    - This module implements an OTP behavior but is missing a 'state' record.

Am I missing some configuration here ? Could you try running rebar3_lint in a umbrella project ?

Thanks.

@paulo-ferraz-oliveira
Copy link
Collaborator

Quick reply (just from looking at the top of the message): did you try ** instead of *?

@joaohf
Copy link
Author

joaohf commented Mar 9, 2021

Hello, thanks for the quick reply.

I tried and it didn't work.

[
 {
   elvis,
   [
    {config,
     [
       #{dirs => ["apps/**/src"],
        filter => "*.erl",
        ruleset => erl_files,
        rules => [{elvis_style, line_length,
                      #{limit => 80,
                        skip_comments => false
                       }},
                  {elvis_style, no_tabs},
                  {elvis_style, no_trailing_whitespace}]
       },
       #{dirs => ["apps/**/test"],
         filter => "*.erl",
         rules => [{elvis_style, line_length,
                       #{limit => 80,
                         skip_comments => false
                        }}]
         },
       #{dirs => ["."],
        filter => "rebar.config",
        ruleset => rebar_config
       },
      #{dirs => ["."],
        filter => "elvis.config",
        ruleset => elvis_config
       }
     ]
    }
   ]
 }
].

Then, running DEBUG=1 rebar3 lint

===> Looking for Elvis in rebar.config                                                                                                                              │
===> Looking for Elvis in /home/joao.freitas/xpto/elvis.config                                                                     │
Warning: Searching for files in ["apps/**/src/**"] yielded none. Update your configuration.                                                                         │
Warning: Searching for files in ["apps/**/test"] yielded none. Update your configuration.

@paulo-ferraz-oliveira
Copy link
Collaborator

paulo-ferraz-oliveira commented Mar 9, 2021

This is master, right?

@paulo-ferraz-oliveira
Copy link
Collaborator

This is how we're finding files

-spec find_files([string()], string()) -> [file()].
find_files(Dirs, Pattern) ->
    Fun = fun(Dir) ->
              filelib:wildcard(filename:join(Dir, Pattern))
          end,
    [#{path => Path} || Path <- lists:usort(lists:flatmap(Fun, Dirs))].

Might be a bug there, lemme check closer.

@paulo-ferraz-oliveira
Copy link
Collaborator

As a potential workaround can you try **/src/**?

@paulo-ferraz-oliveira
Copy link
Collaborator

What does the following return (if you can share) when you do

(fun (Dirs, Pattern) -> Fun = fun(Dir) -> filelib:wildcard(filename:join(Dir, Pattern)) end, [#{path => Path} || Path <- lists:usort(lists:flatmap(Fun, Dirs))] end(["src/**"], "*.erl")).

@paulo-ferraz-oliveira
Copy link
Collaborator

Hm... fun stuff. I just create a template umbrella, and doing the previous with "apps/*/src/**" I get

[#{path => "apps/myapp/src/myapp_app.erl"},
 #{path => "apps/myapp/src/myapp_sup.erl"}]

as expected, so I'm probably looking in the wrong place.

@joaohf
Copy link
Author

joaohf commented Mar 10, 2021

This is master, right?

Yes, it is master.

As a potential workaround can you try **/src/**?

That works. But it is too wide and all files from _build are going to be linted.

What does the following return (if you can share) when you do

(fun (Dirs, Pattern) -> Fun = fun(Dir) -> filelib:wildcard(filename:join(Dir, Pattern)) end, [#{path => Path} || Path <- lists:usort(lists:flatmap(Fun, Dirs))] end(["src/**"], "*.erl")).
3> (fun (Dirs, Pattern) -> Fun = fun(Dir) -> filelib:wildcard(filename:join(Dir, Pattern)) end, [#{path => Path} || Path <- lists:usort(lists:flatmap(Fun, Dirs))] end(["src/**"], "*.erl")).
[]

5> (fun (Dirs, Pattern) -> Fun = fun(Dir) -> filelib:wildcard(filename:join(Dir, Pattern)) end, [#{path => Path} || Path <- lists:usort(lists:flatmap(Fun, Dirs))] end(["apps/*/src/**"], "*.erl")).
[#{path => "apps/app1/src/a.erl"},
 #{path => "apps/app1/src/b_app.erl"},
 #{path => [...]},
 #{...}|...]
6> 

In the rebar.config file, I've added the rebar3_lint like this:

{project_plugins, [
  erlfmt,
  {rebar3_lint, {git, "https://github.com/project-fifo/rebar3_lint", {branch, "master"}}},
  rebar3_hank,
  covertool
]}.

@paulo-ferraz-oliveira
Copy link
Collaborator

Side note: if you always want to get master you only need the atom rebar3_lint there, really.

@paulo-ferraz-oliveira
Copy link
Collaborator

Still looking at it, but I think this is the changed that messed the results up: inaka/elvis_core@cf8f4f0.

@paulo-ferraz-oliveira
Copy link
Collaborator

@joaohf, I'm transferring this issue over to https://github.com/inaka/elvis_core/, because that's where the fix should take place.

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