Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Commit db05251

Browse files
committed
use nimble_options to document schema
1 parent 6ed0eb7 commit db05251

File tree

6 files changed

+135
-12
lines changed

6 files changed

+135
-12
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a
66
Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
77
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## 0.0.7 - 2021-01-25
10+
11+
### Added
12+
13+
- The schema is now validated and documented by `:nimble_options`
14+
915
## 0.0.6 - 2020-12-22
1016

1117
### Changed

fixture/harness.lock

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%{
2+
"nimble_options": {:hex, :nimble_options, "0.3.5", "a4f6820cdcb4ee444afd78635f323e58e8a5ddf2fbbe9b9d283a99f972034bae", [:mix], [], "hexpm", "f5507cc90033a8d12769522009c80aa9164af6bab245dbd4ad421d008455f1e1"},
3+
}

lib/harness_dotfiles.ex

+122-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,112 @@
11
defmodule HarnessDotfiles do
2+
@schema [
3+
coveralls_skip_files: [
4+
doc: """
5+
A list of file regex patterns to ignore for coveralls coverage checking.
6+
""",
7+
type: {:list, :string},
8+
default: ["^test", "^deps", "^.harness"]
9+
],
10+
coveralls_minimum_coverage: [
11+
doc: """
12+
The minimum percentage of coverage to require for a successful coveralls
13+
coverage report.
14+
""",
15+
type: {:custom, __MODULE__, :parse_number, []},
16+
default: 100
17+
],
18+
explicit_credo_checks: [
19+
doc: """
20+
A list of explicit checks to pass to the credo `:checks` configuration.
21+
Checks in this list will merge on top of the defaults provided in the
22+
`.credo.exs` template provided by this harness package. To disable a
23+
check, add an element to the list: `{CheckName, false}`.
24+
""",
25+
type: {:list, {:custom, __MODULE__, :parse_tuple, []}},
26+
default: []
27+
],
28+
excluded_paths_for_modulename_matches_filename: [
29+
doc: """
30+
A list of elixir Regexs used to ignore files and directories from the
31+
Convene ModulenameMatchesFilename check. Useful for ignoring directories
32+
containing modules with Phoenix naming conventions.
33+
""",
34+
type: {:list, {:custom, __MODULE__, :parse_regex, []}},
35+
default: []
36+
],
37+
asdf_elixir_version: [
38+
doc: """
39+
The version of elixir to use, as passed to `asdf`.
40+
""",
41+
type: :string,
42+
default: "1.11.2-otp-23"
43+
],
44+
asdf_erlang_version: [
45+
doc: """
46+
The version of erlang to use, as passed to `asdf`.
47+
""",
48+
type: :string,
49+
default: "23.2"
50+
],
51+
asdf_other_versions: [
52+
doc: """
53+
Other versions to include in the local `.tool-versions` file used by
54+
`asdf`. E.g. `["nodejs 12.13.1"]` will add Node to the local `asdf`
55+
requirements.
56+
""",
57+
type: {:list, :string},
58+
default: []
59+
],
60+
formatter_deps: [
61+
doc: """
62+
The list of dependencies from which to import formatter config. Some
63+
dependencies like `:projection` or `:phoenix` export formatter
64+
configuration, like which functions or macros should be allowed to not
65+
have parentheses.
66+
""",
67+
type: {:list, :atom},
68+
default: []
69+
],
70+
formatter_locals_without_parens: [
71+
doc: """
72+
A keyword list of function/macro names and arities allowed to not have
73+
parentheses in the local project. E.g. `[foo: 2]` will allow calls to
74+
`foo/2` to not need parentheses, as in `foo :bar, :baz`.
75+
""",
76+
type: :keyword_list,
77+
default: []
78+
]
79+
]
80+
281
@moduledoc """
382
A harness for a common collection of dotfiles
83+
84+
The options are:
85+
86+
#{NimbleOptions.docs(@schema)}
487
"""
588

689
@behaviour Harness.Pkg
790

8-
defstruct coveralls_skip_files: ["^test", "^deps", "^.harness"],
9-
coveralls_minimum_coverage: 100,
10-
explicit_credo_checks: [],
11-
excluded_paths_for_modulename_matches_filename: [],
12-
asdf_elixir_version: "1.11.2-otp-23",
13-
asdf_erlang_version: "23.2",
14-
asdf_other_versions: [],
15-
formatter_deps: [],
16-
formatter_locals_without_parens: []
91+
defstruct ~w[
92+
coveralls_skip_files
93+
coveralls_minimum_coverage
94+
explicit_credo_checks
95+
excluded_paths_for_modulename_matches_filename
96+
asdf_elixir_version
97+
asdf_erlang_version
98+
asdf_other_versions
99+
formatter_deps
100+
formatter_locals_without_parens
101+
]a
17102

103+
@doc false
18104
@impl Harness.Pkg
19105
def cast(opts) do
20-
struct(__MODULE__, opts)
106+
struct(__MODULE__, NimbleOptions.validate!(opts, @schema))
21107
end
22108

109+
@doc false
23110
@impl Harness.Pkg
24111
def links(_config) do
25112
~w[
@@ -29,4 +116,29 @@ defmodule HarnessDotfiles do
29116
coveralls.json
30117
]
31118
end
119+
120+
@doc false
121+
def parse_number(number) when is_number(number) do
122+
{:ok, number}
123+
end
124+
125+
def parse_number(unknown) do
126+
{:error, "must be a number (integer or float), got: #{inspect(unknown)}"}
127+
end
128+
129+
@doc false
130+
def parse_tuple(tuple) when is_tuple(tuple) do
131+
{:ok, tuple}
132+
end
133+
134+
def parse_tuple(unknown) do
135+
{:error, "must be a tuple, got: #{inspect(unknown)}"}
136+
end
137+
138+
@doc false
139+
def parse_regex(%Regex{} = regex), do: {:ok, regex}
140+
141+
def parse_regex(unknown) do
142+
{:error, "must be a regex, got: #{inspect(unknown)}"}
143+
end
32144
end

mix.exs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ defmodule HarnessDotfiles.MixProject do
4444

4545
defp deps do
4646
[
47+
{:nimble_options, "~> 0.1"},
4748
# docs
4849
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
4950
# test

mix.lock

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"},
1515
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
1616
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
17+
"nimble_options": {:hex, :nimble_options, "0.3.5", "a4f6820cdcb4ee444afd78635f323e58e8a5ddf2fbbe9b9d283a99f972034bae", [:mix], [], "hexpm", "f5507cc90033a8d12769522009c80aa9164af6bab245dbd4ad421d008455f1e1"},
1718
"nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"},
1819
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
1920
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},

test/harness_dotfiles_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ defmodule HarnessDotfilesTest do
66
[opts: []]
77
end
88

9-
test "casting the configuration produces the default struct", c do
10-
assert HarnessDotfiles.cast(c.opts) === %HarnessDotfiles{}
9+
test "casting the configuration produces a struct", c do
10+
assert %HarnessDotfiles{} = HarnessDotfiles.cast(c.opts)
1111
end
1212
end
1313

0 commit comments

Comments
 (0)