Skip to content

Commit

Permalink
docs: add documentation about using predicate filters
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Feb 2, 2022
1 parent cefd0b9 commit 1360fd5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
10 changes: 7 additions & 3 deletions lib/mix/tasks/compile.unused.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ defmodule Mix.Tasks.Compile.Unused do
To ignore warnings about unused structs you need to use "special" syntax in
form of `{StructModule, :__struct__, 0}`.
The pattern list can also take the predicate function which can be either
unary or binary function. First argument will be `t:mfa/0` and second argument
(in case of the binary function) will be `t:MixUnused.Meta.t/0`.
### Documentation metadata
Functions that have `export: true` in their metadata will be automatically
Expand All @@ -77,9 +81,9 @@ defmodule Mix.Tasks.Compile.Unused do
## Options
- `severity` - severity of the reported messages, defaults to `hint`.
- `--severity` - severity of the reported messages, defaults to `hint`.
Other allowed levels are `information`, `warning`, and `error`.
- `warnings-as-errors` - if the `severity` is set to `:warning` and there is
- `--warnings-as-errors` - if the `severity` is set to `:warning` and there is
any report, then fail compilation with exit code `1`.
"""

Expand Down Expand Up @@ -152,7 +156,7 @@ defmodule Mix.Tasks.Compile.Unused do
end
end

def update_manifest(data, manifest) do
defp update_manifest(data, manifest) do
cache =
case File.read(manifest) do
{:ok, data} -> :erlang.binary_to_term(data)
Expand Down
5 changes: 2 additions & 3 deletions lib/mix_unused/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ defmodule MixUnused.Filter do

@type pattern() :: predicate() | mfa_pattern()

@doc """
Reject values in `exports` that match any pattern in `patterns`.
"""
# Reject values in `exports` that match any pattern in `patterns`.
@doc false
@spec reject_matching(exports :: Exports.t(), patterns :: [pattern()]) ::
Exports.t()
def reject_matching(exports, patterns) do
Expand Down
10 changes: 10 additions & 0 deletions lib/mix_unused/meta.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ defmodule MixUnused.Meta do
Metadata of the functions
"""

@typedoc """
Struct describing function metadata.
- `:signature` - stringified representation of the function call. Used for display purposes.
- `:file` - path to the file that contains definition of given function.
- `:line` - integer line number where the function is located within file
(currently, it can point to the line where documentation is defined, not
exactly to function head).
- `:doc_meta` - documentation metadata of the given function.
"""
@type t() :: %__MODULE__{
signature: String.t(),
file: String.t(),
Expand Down
6 changes: 2 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ defmodule MixUnused.MixProject do
docs: [
extras: [
"CHANGELOG.md": [],
LICENSE: [title: "License"],
"README.md": [title: "Overview"]
LICENSE: [title: "License"]
],
# main: "Mix.Tasks.Compile.Unused",
main: "readme",
main: "Mix.Tasks.Compile.Unused",
source_url: @source_url,
source_url: "v#{@version}",
formatters: ["html"]
Expand Down

0 comments on commit 1360fd5

Please sign in to comment.