Support [elem, ...] non-empty list shorthand in AbstractCode - #42
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes are fully covered by tests and no unresolved issues remain.
Pull request overview
Adds support for Elixir non-empty list shorthand types in Spectral.AbstractCode.
Changes:
- Converts
[...]and[elem, ...]to non-empty list types. - Adds encoding, decoding, schema, and equivalence coverage.
File summaries
| File | Description |
|---|---|
test/type_info_equivalence_test.exs |
Includes shorthand types in equivalence checks. |
test/support/nonempty_list_module.ex |
Adds shorthand and longhand fixtures. |
test/support/all_types_module.ex |
Adds shorthand list fixtures. |
test/spectral_nonempty_list_test.exs |
Tests validation and schema behavior. |
lib/spectral/abstract_code.ex |
Handles non-empty list shorthand ASTs. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
andreashasse
pushed a commit
that referenced
this pull request
Sep 14, 2026
Merges in the non-empty list shorthand fix (#42), which landed on main after this branch. Folds its CHANGELOG entry into the same 0.14.0 section as the spectra bump, since main is still at 0.13.0 and this branch is the one cutting that release. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XTMXez4gy2fHp6HgovtfGG
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Spectral.AbstractCode.convert_type/1did not handle the Elixir shorthand for a non-empty list type,[elem_type, ...](or bare[...]), even though the longhandnonempty_list(elem_type)worked fine. A type like@type t :: %{tags: [String.t(), ...]}failed to compile with:Fix
Added two clauses to
convert_type/1in lib/spectral/abstract_code.ex, matching before the existing single-element[elem]clause:[elem_ast, {:..., _, _}]→sp_nonempty_list(type: convert_type(elem_ast))[{:..., _, _}](bare[...]) →sp_nonempty_list(type: term)Improper-list shorthands (
[elem | tail],[elem, ... | tail]) were considered but not added: Elixir's typespec compiler treats[a | b]aslist(a | b)(already handled by the existing[elem]clause) and rejects[a, ... | b]outright at compile time, so there's no AST shape frommaybe_improper_list/nonempty_improper_listshorthand to handle here — those types are already only reachable via their named-type form, which already works.Testing
test/support/nonempty_list_module.ex+test/spectral_nonempty_list_test.exs: encode/decode round-trips a non-empty list, empty list is rejected both ways, and the generated JSON Schema hasminItems: 1and matchesnonempty_list(elem)'s schema exactly.[integer(), ...]/[...]types totest/support/all_types_module.ex, covered by the existing compile-time vs. runtime type_info equivalence test.make format && make cipasses (217 tests, 0 failures, no Credo or Dialyzer issues).🤖 Generated with Claude Code