OptimumCredo.Check.Warning.CallerModuleAttributes (OptimumCredo v0.5.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of normal and works with any version of Elixir.

Explanation

Avoid injecting generic module attributes such as @opts, @pos, or @app into the caller from a quote. Those attributes belong to the caller's module and can collide with another macro. Use an owner-specific name, optionally wrapped in leading/trailing underscores, or explicitly allow intentional caller configuration.

Built-in language and compiler attributes (including @before_compile, @on_definition, @doc, and @spec) are allowed. A defmodule nested in a quote owns its own attributes and is ignored.

This check only reads literal quote AST. It does not expand arbitrary macros or infer dynamic Module.* targets. It also does not inspect AST returned by unquote or unquote_splicing.

Bad

defmacro __using__(opts) do
  quote do
    @opts unquote(opts)
    @app :demo
  end
end

Good

defmacro __using__(opts) do
  quote do
    @__my_library_opts__ unquote(opts)
    @__my_library_app__ :demo
  end
end

If the attribute is part of a documented caller API, add it to allow_attributes in the Credo configuration.

Check-Specific Parameters

Use the following parameters to configure this check:

:required_prefix

Optional owner prefix. Attributes beginning with this prefix and _ are accepted.

This parameter defaults to nil.

:allow_attributes

Attribute names that are intentional documented caller configuration, as atoms or strings.

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.