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

AbcSize does not exclude method declarations. #1176

Open
noizu opened this issue Jan 19, 2025 · 0 comments
Open

AbcSize does not exclude method declarations. #1176

noizu opened this issue Jan 19, 2025 · 0 comments

Comments

@noizu
Copy link

noizu commented Jan 19, 2025

I am getting ABC errors for defmacro deriving calls, it appears that the logic does not exclude the method declarations themselves only calls within logic to other methods.

https://github.com/rrrene/credo/blob/master/lib/credo/check/refactor/abc_size.ex#L73-L99

A crude patch like the following addressing the issue but this needs to be thought out to avoid headaches with existing users. Possibly a new param is needed? There is already a similiar ex ception above line L73 for :using macros.

  for op <- @def_ops do
    defp traverse(
           {unquote(op), meta, arguments} = ast,
           issues,
           issue_meta,
           max_abc_size,
           excluded_functions
         )
         when is_list(arguments) do
      
      # Exclude declarations of methods included in excluded_function list.
      with [{f,_,_}|_] <- arguments,
           true <- is_atom(f),
           true <- Enum.member?(excluded_functions, Atom.to_string(f)) do
        {ast, issues}
      else
        _ ->
          abc_size =
            ast
            |> abc_size_for(excluded_functions)
            |> round
          
          if abc_size > max_abc_size do
            fun_name = Credo.Code.Module.def_name(ast)
            
            {ast,
              [
                issue_for(issue_meta, meta[:line], fun_name, max_abc_size, abc_size)
                | issues
              ]}
          else
            {ast, issues}
          end
      
      end
      
    end
  end

Additionally this might be faster with

    defp traverse(
           {op, meta, arguments} = ast,
           issues,
           issue_meta,
           max_abc_size,
           excluded_functions
         )
         when is_list(arguments) and op in @def_ops do

to reduce the amount of generated code while replacing with guard checks. (although we'd have to run benchee to verify).

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

1 participant