Skip to content

Commit f937a7a

Browse files
authored
ci: add dialyzer (#61)
refactor: precedence is guaranteed to not be nil Co-authored-by: Lukasz Samson <[email protected]> fix: correctly match on successful tokenize refactor: remove unused clauses
1 parent 6fa3f04 commit f937a7a

File tree

7 files changed

+46
-13
lines changed

7 files changed

+46
-13
lines changed

.dialyzer_ignore.exs

Whitespace-only changes.

.github/workflows/ci.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ jobs:
121121
restore-keys: |
122122
${{ runner.os }}-mix-${{ hashFiles('**/.mise.toml') }}-
123123
124+
# Don't cache PLTs based on mix.lock hash, as Dialyzer can incrementally update even old ones
125+
# Cache key based on Elixir & Erlang version (also useful when running in matrix)
126+
- name: Restore PLT cache
127+
uses: actions/cache/restore@v4
128+
id: plt_cache
129+
with:
130+
key: ${{ runner.os }}-mix-${{ hashFiles('**/flake.nix') }}-${{ hashFiles('**/mix.lock') }}
131+
restore-keys: |
132+
${{ runner.os }}-mix-${{ hashFiles('**/flake.nix') }}-
133+
path: |
134+
priv/plts
135+
124136
- name: Install Dependencies
125137
run: nix develop --command bash -c "mix deps.get"
126138

@@ -129,3 +141,23 @@ jobs:
129141

130142
- name: Credo
131143
run: nix develop --command bash -c "mix credo"
144+
145+
# Create PLTs if no cache was found
146+
- name: Create PLTs
147+
if: steps.plt_cache.outputs.cache-hit != 'true'
148+
run: nix develop --command bash -c 'mix dialyzer --plt'
149+
150+
# By default, the GitHub Cache action will only save the cache if all steps in the job succeed,
151+
# so we separate the cache restore and save steps in case running dialyzer fails.
152+
- name: Save PLT cache
153+
uses: actions/cache/save@v4
154+
if: steps.plt_cache.outputs.cache-hit != 'true'
155+
id: plt_cache_save
156+
with:
157+
key: ${{ runner.os }}-mix-${{ hashFiles('**/flake.nix') }}-${{ hashFiles('**/mix.lock') }}
158+
path: |
159+
priv/plts
160+
161+
- name: Run dialyzer
162+
run: nix develop --command bash -c 'mix dialyzer --format github'
163+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ spitfire-*.tar
2626
/tmp/
2727
benchmarks
2828
*.bggg
29+
priv/plts/*

lib/spitfire.ex

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,6 @@ defmodule Spitfire do
634634

635635
defp parse_comma_list(parser, precedence, is_list, is_map) do
636636
trace "parse_comma_list", trace_meta(parser) do
637-
precedence = precedence || @list_comma
638637
{front, parser} = parse_expression(parser, precedence, is_list, is_map, false)
639638
# we zip together the expression and parser state so that we can potentially
640639
# backtrack later
@@ -2161,8 +2160,8 @@ defmodule Spitfire do
21612160
case code
21622161
|> String.to_charlist()
21632162
|> :spitfire_tokenizer.tokenize(opts[:line] || 1, opts[:column] || 1, opts) do
2164-
{:ok, _, _, _, tokens} ->
2165-
tokens
2163+
{:ok, _, _, _, tokens, []} ->
2164+
Enum.reverse(tokens)
21662165

21672166
{:ok, line, column, _, rev_tokens, rev_terminators} ->
21682167
# vendored from elixir-lang/elixir, license: Apache2
@@ -2333,14 +2332,6 @@ defmodule Spitfire do
23332332
eat_at(parser, [:eol, :";"], idx)
23342333
end
23352334

2336-
defp eat_at(parser, token, 0) when is_atom(token) do
2337-
eat(%{token => true}, parser)
2338-
end
2339-
2340-
defp eat_at(parser, token, idx) when is_atom(token) do
2341-
eat_at(parser, %{token => true}, idx)
2342-
end
2343-
23442335
defp eat_at(parser, tokens, idx) when is_list(tokens) do
23452336
eat_at(parser, Map.new(tokens, &{&1, true}), idx)
23462337
end

mix.exs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ defmodule Spitfire.MixProject do
1212
start_permanent: Mix.env() == :prod,
1313
deps: deps(),
1414
docs: [main: "Spitfire"],
15-
package: package()
15+
package: package(),
16+
dialyzer: [
17+
plt_core_path: "priv/plts",
18+
plt_local_path: "priv/plts",
19+
ignore_warnings: ".dialyzer_ignore.exs"
20+
]
1621
]
1722
end
1823

@@ -28,7 +33,9 @@ defmodule Spitfire.MixProject do
2833
[
2934
{:ex_doc, ">= 0.0.0", only: :dev},
3035
{:styler, "~> 0.11", only: :dev},
31-
{:credo, "~> 1.7", only: :dev}
36+
{:credo, "~> 1.7", only: :dev},
37+
{:dialyxir, "~> 1.0", only: :dev}
38+
3239
# {:dep_from_hexpm, "~> 0.3.0"},
3340
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
3441
]

mix.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
%{
22
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
33
"credo": {:hex, :credo, "1.7.11", "d3e805f7ddf6c9c854fd36f089649d7cf6ba74c42bc3795d587814e3c9847102", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "56826b4306843253a66e47ae45e98e7d284ee1f95d53d1612bb483f88a8cf219"},
4+
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
45
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
6+
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
57
"ex_doc": {:hex, :ex_doc, "0.34.0", "ab95e0775db3df71d30cf8d78728dd9261c355c81382bcd4cefdc74610bef13e", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "60734fb4c1353f270c3286df4a0d51e65a2c1d9fba66af3940847cc65a8066d7"},
68
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
79
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},

priv/plts/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)