Skip to content

Commit

Permalink
Merge pull request #436 from crystal-ameba/cleanup-properties-macro
Browse files Browse the repository at this point in the history
Make `RuleConfig#properties` accept only `Call` nodes
  • Loading branch information
Sija committed Dec 28, 2023
2 parents 954345d + 55f3ec5 commit 9bb6c9a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Ameba
# Dummy Rule which does nothing.
class DummyRule < Rule::Base
properties do
description : String = "Dummy rule that does nothing."
description "Dummy rule that does nothing."
dummy true
end

Expand Down Expand Up @@ -92,7 +92,7 @@ module Ameba

class PerfRule < Rule::Performance::Base
properties do
description : String = "Sample performance rule"
description "Sample performance rule"
end

def test(source)
Expand Down
24 changes: 12 additions & 12 deletions src/ameba/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,20 @@ class Ameba::Config
# Define rule properties
macro properties(&block)
{% definitions = [] of NamedTuple %}
{% if block.body.is_a? Assign %}
{% definitions << {var: block.body.target, value: block.body.value} %}
{% elsif block.body.is_a? Call %}
{% definitions << {var: block.body.name, value: block.body.args.first} %}
{% elsif block.body.is_a? TypeDeclaration %}
{% definitions << {var: block.body.var, value: block.body.value, type: block.body.type} %}
{% if (prop = block.body).is_a? Call %}
{% if (named_args = prop.named_args) && (type = named_args.select(&.name.== "as".id).first) %}
{% definitions << {var: prop.name, value: prop.args.first, type: type.value} %}
{% else %}
{% definitions << {var: prop.name, value: prop.args.first} %}
{% end %}
{% elsif block.body.is_a? Expressions %}
{% for prop in block.body.expressions %}
{% if prop.is_a? Assign %}
{% definitions << {var: prop.target, value: prop.value} %}
{% elsif prop.is_a? Call %}
{% definitions << {var: prop.name, value: prop.args.first} %}
{% elsif prop.is_a? TypeDeclaration %}
{% definitions << {var: prop.var, value: prop.value, type: prop.type} %}
{% if prop.is_a? Call %}
{% if (named_args = prop.named_args) && (type = named_args.select(&.name.== "as".id).first) %}
{% definitions << {var: prop.name, value: prop.args.first, type: type.value} %}
{% else %}
{% definitions << {var: prop.name, value: prop.args.first} %}
{% end %}
{% end %}
{% end %}
{% end %}
Expand Down
3 changes: 2 additions & 1 deletion src/ameba/rule/lint/typos.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module Ameba::Rule::Lint
class Typos < Base
properties do
description "Reports typos found in source files"
bin_path : String? = nil

bin_path nil, as: String?
fail_on_error false
end

Expand Down
4 changes: 2 additions & 2 deletions src/ameba/rule/style/verbose_block.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module Ameba::Rule::Style
exclude_operators true
exclude_setters false

max_line_length : Int32? = nil # 100
max_length : Int32? = 50
max_line_length nil, as: Int32?
max_length 50, as: Int32?
end

MSG = "Use short block notation instead: `%s`"
Expand Down

0 comments on commit 9bb6c9a

Please sign in to comment.