Skip to content

Commit

Permalink
Handle hash defaults correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nobodywasishere committed Nov 19, 2024
1 parent 21c279a commit c219fc2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
27 changes: 18 additions & 9 deletions .ameba.yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2192,15 +2192,24 @@
"default": "Identifies usage of excessive collection allocations"
},
"CallNames": {
"type": "array",
"items": {
"type": "string"
},
"default": {
"codepoints": "each_codepoint",
"graphemes": "each_grapheme",
"chars": "each_char",
"lines": "each_line"
"type": "object",
"properties": {
"codepoints": {
"type": "string",
"default": "each_codepoint"
},
"graphemes": {
"type": "string",
"default": "each_grapheme"
},
"chars": {
"type": "string",
"default": "each_char"
},
"lines": {
"type": "string",
"default": "each_line"
}
}
},
"Enabled": {
Expand Down
18 changes: 17 additions & 1 deletion src/ameba/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,29 @@ class Ameba::Config
end
bld.field("default", {{ prop[:default].capitalize }})
{% default_set = true %}
{% else %}
{% elsif prop[:default].is_a?(ArrayLiteral) %}
bld.field("type", "array")

bld.string("items")
bld.object do
bld.field("type", "string")
end
{% elsif prop[:default].is_a?(HashLiteral) %}
bld.field("type", "object")

bld.string("properties")
bld.object do
{% for pr in prop[:default] %}
bld.string({{ pr }})
bld.object do
bld.field("type", "string")
bld.field("default", {{ prop[:default][pr] }})
end
{% end %}
end
{% default_set = true %}
{% else %}
{% raise "Unhandled schema type for #{prop}" %}
{% end %}

{% if !prop[:default].is_a?(Ameba::Severity) && !default_set %}
Expand Down

0 comments on commit c219fc2

Please sign in to comment.