Last active
July 29, 2022 07:04
-
-
Save zoten/623d46d20f2ae4d3a48f46bd59d2ca1b to your computer and use it in GitHub Desktop.
Credo complaining public spec missing on a macro-generated function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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