Skip to content

Instantly share code, notes, and snippets.

@zoten
Last active July 29, 2022 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoten/623d46d20f2ae4d3a48f46bd59d2ca1b to your computer and use it in GitHub Desktop.
Save zoten/623d46d20f2ae4d3a48f46bd59d2ca1b to your computer and use it in GitHub Desktop.
Credo complaining public spec missing on a macro-generated function
# Save this file as example.exs in the root of a mix project with credo installed
# and [Credo.Check.Readability.Specs](https://hexdocs.pm/credo/Credo.Check.Readability.Specs.html) check enabled
# and run a
# ``` bash
# mix credo example.exs
# ```
# command to trigger the error
# or
# get a .credo.exs file with the check enabled and
# uncomment the last line and run this as an escript with
# ``` bash
# elixir example.exs
# ```
Mix.install([
{:credo, "~> 1.6"}
])
defmodule SpecMe do
defmacro __using__(attrs) do
for attr <- attrs do
quote do
def unquote(attr)(attr = unquote(attr)), do: Atom.to_string(attr)
def unquote(attr)(attr), do: attr |> Atom.to_string() |> String.reverse()
end
end
end
end
defmodule UseSpec do
use SpecMe, [:ab, :bc, :cd]
end
# uncomment and run
# elixir example.exs
# to see this stuff working
# UseSpec.ab(:ab) |> IO.inspect()
# UseSpec.ab(:bc) |> IO.inspect()
# UseSpec.bc(:bc) |> IO.inspect()
# UseSpec.bc(:cd) |> IO.inspect()
# Mix.Tasks.Credo.run(["example.exs"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment