Skip to content

Commit 20cd6ff

Browse files
authored
chore: various wardening (#31)
* chore: various wardening * test: 100% coverage * ci: add dialyzer job * fix: formatting * docs: update changelog
1 parent ab601b5 commit 20cd6ff

File tree

17 files changed

+369
-123
lines changed

17 files changed

+369
-123
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
16-
with:
17-
ref: ${{ github.head_ref }}
15+
uses: actions/checkout@v4
1816
- name: Use Node.js 18.x
1917
uses: actions/setup-node@v3
2018
with:
@@ -27,12 +25,12 @@ jobs:
2725
name: Format/Credo
2826
runs-on: ubuntu-latest
2927
steps:
30-
- uses: actions/checkout@v3
28+
- uses: actions/checkout@v4
3129
- name: Set up Elixir
3230
uses: erlef/setup-beam@v1
3331
with:
34-
elixir-version: "1.18.0"
35-
otp-version: "27.0.1"
32+
elixir-version: "1.19"
33+
otp-version: "28"
3634
- name: Restore dependencies cache
3735
uses: actions/cache@v3
3836
with:
@@ -45,16 +43,42 @@ jobs:
4543
run: mix format --check-formatted
4644
- name: Run Credo
4745
run: mix credo
46+
dialyzer:
47+
name: Dialyzer
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
- name: Set up Elixir
52+
uses: erlef/setup-beam@v1
53+
with:
54+
elixir-version: "1.19"
55+
otp-version: "28"
56+
- name: Restore dependencies cache
57+
uses: actions/cache@v3
58+
with:
59+
path: deps
60+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
61+
restore-keys: ${{ runner.os }}-mix-
62+
- name: Restore dialyzer cache
63+
uses: actions/cache@v3
64+
with:
65+
path: priv/plts
66+
key: ${{ runner.os }}-mix-plts-${{ hashFiles('./priv/plts/') }}
67+
restore-keys: ${{ runner.os }}-mix-plts-
68+
- name: Install dependencies
69+
run: mix deps.get
70+
- name: Run dialyzer
71+
run: mix dialyzer
4872
test:
4973
name: Test
5074
runs-on: ubuntu-latest
5175
steps:
52-
- uses: actions/checkout@v3
76+
- uses: actions/checkout@v4
5377
- name: Set up Elixir
5478
uses: erlef/setup-beam@v1
5579
with:
56-
elixir-version: "1.18.0"
57-
otp-version: "27.0.1"
80+
elixir-version: "1.19"
81+
otp-version: "28"
5882
- name: Restore dependencies cache
5983
uses: actions/cache@v3
6084
with:

.tool-versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
elixir 1.18.0-otp-27
2-
erlang 27.0.1
1+
elixir 1.19.4-otp-28
2+
erlang 28.2

CHANGELOG.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,49 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## v0.11.0 - 2024-08-31
8+
## [Unreleased]
99

10-
**Added**
10+
### Added
11+
12+
- Better documented typespecs. ([#31](https://github.com/codedge-llc/scribe/pull/31))
13+
- Full unit test coverage. ([#31](https://github.com/codedge-llc/scribe/pull/31))
14+
15+
## [0.11.0] - 2024-08-31
16+
17+
### Added
1118

1219
- Center and right text alignment options ([#16](https://github.com/codedge-llc/scribe/pull/16)).
1320

14-
**Changed**
21+
### Changed
1522

1623
- Bumped minimum Elixir version to 1.13.
1724

18-
**Removed**
25+
### Removed
1926

2027
- Removed `Scribe.auto_inspect/1`.
2128
- Removed `Scribe.auto_inspect?/0`.
2229

23-
## v0.10.0 - 2019-05-29
30+
## [0.10.0] - 2019-05-29
2431

2532
- Added `:device` option to `Scribe.print/2` for printing to a specific device.
2633
Defaults to `:stdio`
2734

28-
## v0.9.0 - 2019-05-04
35+
## [0.9.0] - 2019-05-04
2936

3037
- `NoBorder` style added.
3138

32-
## v0.8.2 - 2019-01-17
39+
## [0.8.2] - 2019-01-17
3340

3441
- Support for Elixir `v1.8`
3542

36-
## v0.8.1 - 2018-07-25
43+
## [0.8.1] - 2018-07-25
3744

3845
- Support for Elixir `v1.7`
3946

40-
## v0.8.0 - 2019-03-15
47+
## [0.8.0] - 2019-03-15
4148

4249
- `:compile_auto_inspect` and `:auto_inspect` config options, both default
4350
to `false`.
@@ -61,23 +68,23 @@ true again.
6168
If auto-inspect is not compiled (or disabled), `Scribe.print/2` and similar
6269
functions will continue to work as normal.
6370

64-
## v0.7.0 - 2018-02-19
71+
## [0.7.0] - 2018-02-19
6572

6673
- Pseudographics style added.
6774

68-
## v0.6.0 - 2018-02-16
75+
## [0.6.0] - 2018-02-16
6976

7077
- Overrides Inspect protocol for `List` and `Map`. These types will now
7178
automatically return in Scribe's table format. Disabled by default.
7279
with `config :scribe, enable: false` in your Mix config.
7380
- `Scribe.enable`, `Scribe.disable`, and `Scribe.enabled?` added.
7481
- Minimum Elixir version bumped to `1.5`.
7582

76-
## v0.5.1 - 2018-01-06
83+
## [0.5.1] - 2018-01-06
7784

7885
- Bump pane dependency to v0.2.0.
7986

80-
## v0.5.0 - 2017-03-27
87+
## [0.5.0] - 2017-03-27
8188

8289
- `@behaviour Scribe.Style` implemented (See `/style` for example adapters)
8390
- Colorized output.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016-2024 Codedge LLC (https://www.codedge.io/)
3+
Copyright (c) 2016-2026 Codedge LLC (https://www.codedge.io/)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,6 @@ Git commit subjects use the [Karma style](http://karma-runner.github.io/5.0/dev/
283283

284284
## License
285285

286-
Copyright (c) 2016-2024 Codedge LLC (https://www.codedge.io/)
286+
Copyright (c) 2016-2026 Codedge LLC (https://www.codedge.io/)
287287

288288
This library is MIT licensed. See the [LICENSE](https://github.com/codedge-llc/scribe/blob/main/LICENSE) for details.

lib/scribe.ex

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ defmodule Scribe do
154154
- `:width` - Defines table width. Defaults to `:infinite`
155155
"""
156156
@type format_opts :: [
157-
alignment: atom,
158-
colorize: boolean,
157+
alignment: atom(),
158+
colorize: boolean(),
159159
data: [...],
160-
style: module,
161-
width: integer
160+
style: module(),
161+
width: integer()
162162
]
163163

164164
@doc ~S"""
@@ -177,21 +177,21 @@ defmodule Scribe do
177177
+----------+---------+
178178
:ok
179179
"""
180-
@spec print(data, format_opts) :: :ok
180+
@spec print(data(), format_opts()) :: :ok
181181
def print(_results, opts \\ [])
182182

183183
def print([], _opts), do: :ok
184184

185185
def print(results, opts) do
186-
dev = opts |> Keyword.get(:device, :stdio)
187-
results = results |> format(opts)
188-
dev |> IO.puts(results)
186+
dev = Keyword.get(opts, :device, :stdio)
187+
results = format(results, opts)
188+
IO.puts(dev, results)
189189
end
190190

191191
@doc ~S"""
192192
Paginates data and starts a pseudo-interactive console.
193193
"""
194-
@spec console(data, format_opts) :: no_return
194+
@spec console(data(), format_opts()) :: :ok
195195
def console(results, opts \\ []) do
196196
results
197197
|> format(opts)
@@ -216,7 +216,7 @@ defmodule Scribe do
216216
+----------+---------+
217217
%{test: 1234, key: :value}
218218
"""
219-
@spec inspect(data, format_opts) :: data
219+
@spec inspect(data(), format_opts()) :: data()
220220
def inspect(results, opts \\ []) do
221221
print(results, opts)
222222
results
@@ -233,7 +233,7 @@ defmodule Scribe do
233233
iex> format(%{test: 1234}, colorize: false)
234234
"+---------+\n| :test |\n+---------+\n| 1234 |\n+---------+\n"
235235
"""
236-
@spec format(data) :: String.t() | :ok
236+
@spec format(data(), format_opts()) :: String.t() | :ok
237237
def format(_results, opts \\ [])
238238
def format([], _opts), do: :ok
239239

@@ -251,24 +251,31 @@ defmodule Scribe do
251251
Table.format(table, Enum.count(table), Enum.count(keys), opts)
252252
end
253253

254+
@spec map_string_values([map()]) :: [term()]
254255
defp map_string_values(keys), do: Enum.map(keys, &string_value(&1))
256+
257+
@spec map_string_values(map() | struct(), [map()]) :: [term()]
255258
defp map_string_values(row, keys), do: Enum.map(keys, &string_value(row, &1))
256259

260+
@spec string_value(map()) :: term()
257261
defp string_value(%{name: name, key: _key}) do
258262
name
259263
end
260264

265+
@spec string_value(map() | struct(), map()) :: term()
261266
defp string_value(map, %{name: _name, key: key}) when is_function(key) do
262-
map |> key.()
267+
key.(map)
263268
end
264269

265270
defp string_value(map, %{name: _name, key: key}) do
266-
map |> Map.get(key)
271+
Map.get(map, key)
267272
end
268273

274+
@spec fetch_keys([map() | struct()], list() | nil) :: [map()]
269275
defp fetch_keys([first | _rest], nil), do: fetch_keys(first)
270276
defp fetch_keys(_list, opts), do: process_headers(opts)
271277

278+
@spec process_headers(list()) :: [map()]
272279
defp process_headers(opts) do
273280
for opt <- opts do
274281
case opt do
@@ -278,6 +285,7 @@ defmodule Scribe do
278285
end
279286
end
280287

288+
@spec fetch_keys(map() | struct()) :: [map()]
281289
defp fetch_keys(map) do
282290
map
283291
|> Map.keys()

lib/scribe/border.ex

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ defmodule Scribe.Border do
1313
+--------+
1414
```
1515
"""
16-
defstruct top_left_corner: "",
17-
top_edge: "",
18-
top_right_corner: "",
19-
right_edge: "",
20-
bottom_right_corner: "",
21-
bottom_edge: "",
16+
defstruct bottom_edge: "",
2217
bottom_left_corner: "",
23-
left_edge: ""
18+
bottom_right_corner: "",
19+
left_edge: "",
20+
right_edge: "",
21+
top_edge: "",
22+
top_left_corner: "",
23+
top_right_corner: ""
2424

2525
@type t :: %__MODULE__{
26-
top_left_corner: String.t(),
27-
top_edge: String.t(),
28-
top_right_corner: String.t(),
29-
right_edge: String.t(),
30-
bottom_right_corner: String.t(),
3126
bottom_edge: String.t(),
3227
bottom_left_corner: String.t(),
33-
left_edge: String.t()
28+
bottom_right_corner: String.t(),
29+
left_edge: String.t(),
30+
right_edge: String.t(),
31+
top_edge: String.t(),
32+
top_left_corner: String.t(),
33+
top_right_corner: String.t()
3434
}
3535

3636
@doc ~S"""
@@ -40,27 +40,27 @@ defmodule Scribe.Border do
4040
4141
iex> new("+", "|", "-")
4242
%Scribe.Border{
43-
top_left_corner: "+",
44-
top_edge: "-",
45-
top_right_corner: "+",
46-
right_edge: "|",
47-
bottom_right_corner: "+",
4843
bottom_edge: "-",
4944
bottom_left_corner: "+",
50-
left_edge: "|"
45+
bottom_right_corner: "+",
46+
left_edge: "|",
47+
right_edge: "|",
48+
top_edge: "-",
49+
top_left_corner: "+",
50+
top_right_corner: "+"
5151
}
5252
"""
53-
@spec new(String.t(), String.t(), String.t()) :: t
53+
@spec new(String.t(), String.t(), String.t()) :: t()
5454
def new(corner, v_edge, h_edge) do
5555
%__MODULE__{
56-
top_left_corner: corner,
57-
top_edge: h_edge,
58-
top_right_corner: corner,
59-
right_edge: v_edge,
60-
bottom_right_corner: corner,
6156
bottom_edge: h_edge,
6257
bottom_left_corner: corner,
63-
left_edge: v_edge
58+
bottom_right_corner: corner,
59+
left_edge: v_edge,
60+
right_edge: v_edge,
61+
top_edge: h_edge,
62+
top_left_corner: corner,
63+
top_right_corner: corner
6464
}
6565
end
6666
end

0 commit comments

Comments
 (0)