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

Dirty macro warning + auto arity support #110

Merged
merged 11 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions lib/unifex/specs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,39 @@ defmodule Unifex.Specs do

functions_docs = parse_docs(config, specs_file)

dirty_functions =
config
|> Keyword.get_values(:dirty_functions)
|> List.flatten()
|> Enum.flat_map(fn {dirty_func, type} ->
dirty_name =
case dirty_func do
{name, _arity} -> name
name -> name
end

{matched_name, matched_args} = List.keyfind(functions_args, dirty_name, 0, {nil, []})

if dirty_func in [matched_name, {matched_name, length(matched_args)}] do
[{{dirty_name, length(matched_args)}, type}]
else
Logger.warning(
"Function #{dirty_name} marked as dirty does not match any function defined in spec (#{specs_file})."
)

[]
end
end)
|> Map.new()

%__MODULE__{
name: name,
module: Keyword.get(config, :module),
functions_args: functions_args,
functions_results: functions_results,
functions_docs: functions_docs,
sends: Keyword.get_values(config, :sends),
dirty_functions:
config |> Keyword.get_values(:dirty_functions) |> List.flatten() |> Map.new(),
dirty_functions: dirty_functions,
callbacks: config |> Keyword.get_values(:callback) |> Map.new(),
interface: Keyword.get(config, :interface),
state_type: Keyword.get(config, :state_type, nil),
Expand Down