From 2af58cabd4777fc6791de2baa508a55aba741379 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Tue, 22 Nov 2022 19:49:16 +0100 Subject: [PATCH] Use `property?` for defining `Bool`-returning `Rule` properties --- src/ameba/config.cr | 6 +++++- src/ameba/rule/lint/unused_argument.cr | 6 +++--- src/ameba/rule/style/parentheses_around_condition.cr | 6 +++--- src/ameba/rule/style/redundant_next.cr | 4 ++-- src/ameba/rule/style/redundant_return.cr | 4 ++-- src/ameba/rule/style/verbose_block.cr | 11 ++++++----- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/ameba/config.cr b/src/ameba/config.cr index 515e4fd8..47a4e49b 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -242,7 +242,11 @@ class Ameba::Config {% properties[name] = {key: key, default: value, type: type, converter: converter} %} @[YAML::Field(key: {{ key }}, converter: {{ converter }}, type: {{ type }})] - property {{ name }} : {{ type }} = {{ value }} + {% if type == Bool %} + property? {{ name }} : {{ type }} = {{ value }} + {% else %} + property {{ name }} : {{ type }} = {{ value }} + {% end %} {% end %} {% if properties["enabled".id] == nil %} diff --git a/src/ameba/rule/lint/unused_argument.cr b/src/ameba/rule/lint/unused_argument.cr index 16d86049..891486e8 100644 --- a/src/ameba/rule/lint/unused_argument.cr +++ b/src/ameba/rule/lint/unused_argument.cr @@ -41,15 +41,15 @@ module Ameba::Rule::Lint end def test(source, node : Crystal::ProcLiteral, scope : AST::Scope) - ignore_procs || find_unused_arguments source, scope + ignore_procs? || find_unused_arguments source, scope end def test(source, node : Crystal::Block, scope : AST::Scope) - ignore_blocks || find_unused_arguments source, scope + ignore_blocks? || find_unused_arguments source, scope end def test(source, node : Crystal::Def, scope : AST::Scope) - ignore_defs || find_unused_arguments source, scope + ignore_defs? || find_unused_arguments source, scope end private def find_unused_arguments(source, scope) diff --git a/src/ameba/rule/style/parentheses_around_condition.cr b/src/ameba/rule/style/parentheses_around_condition.cr index 1b347e2a..5ddc15f4 100644 --- a/src/ameba/rule/style/parentheses_around_condition.cr +++ b/src/ameba/rule/style/parentheses_around_condition.cr @@ -46,7 +46,7 @@ module Ameba::Rule::Style when Crystal::Yield !in_ternary || node.has_parentheses? || node.exps.empty? when Crystal::Assign, Crystal::OpAssign, Crystal::MultiAssign - !in_ternary && !allow_safe_assignment + !in_ternary && !allow_safe_assignment? else true end @@ -55,7 +55,7 @@ module Ameba::Rule::Style def test(source, node : Crystal::If | Crystal::Unless | Crystal::Case | Crystal::While | Crystal::Until) cond = node.cond - if cond.is_a?(Crystal::Assign) && allow_safe_assignment + if cond.is_a?(Crystal::Assign) && allow_safe_assignment? issue_for cond, MSG_MISSING do |corrector| corrector.insert_before(cond, '(') corrector.insert_after(cond, ')') @@ -65,7 +65,7 @@ module Ameba::Rule::Style is_ternary = node.is_a?(Crystal::If) && node.ternary? - return if is_ternary && exclude_ternary + return if is_ternary && exclude_ternary? return unless cond.is_a?(Crystal::Expressions) return unless cond.keyword.paren? diff --git a/src/ameba/rule/style/redundant_next.cr b/src/ameba/rule/style/redundant_next.cr index b0e8b1eb..ce81d080 100644 --- a/src/ameba/rule/style/redundant_next.cr +++ b/src/ameba/rule/style/redundant_next.cr @@ -113,8 +113,8 @@ module Ameba::Rule::Style end def test(source, node : Crystal::Next, visitor : AST::RedundantControlExpressionVisitor) - return if allow_multi_next && node.exp.is_a?(Crystal::TupleLiteral) - return if allow_empty_next && (node.exp.nil? || node.exp.try(&.nop?)) + return if allow_multi_next? && node.exp.is_a?(Crystal::TupleLiteral) + return if allow_empty_next? && (node.exp.nil? || node.exp.try(&.nop?)) if exp_code = control_exp_code(node, source.lines) issue_for node, MSG do |corrector| diff --git a/src/ameba/rule/style/redundant_return.cr b/src/ameba/rule/style/redundant_return.cr index 7a020073..234fd097 100644 --- a/src/ameba/rule/style/redundant_return.cr +++ b/src/ameba/rule/style/redundant_return.cr @@ -110,8 +110,8 @@ module Ameba::Rule::Style end def test(source, node : Crystal::Return, visitor : AST::RedundantControlExpressionVisitor) - return if allow_multi_return && node.exp.is_a?(Crystal::TupleLiteral) - return if allow_empty_return && (node.exp.nil? || node.exp.try(&.nop?)) + return if allow_multi_return? && node.exp.is_a?(Crystal::TupleLiteral) + return if allow_empty_return? && (node.exp.nil? || node.exp.try(&.nop?)) if exp_code = control_exp_code(node, source.lines) issue_for node, MSG do |corrector| diff --git a/src/ameba/rule/style/verbose_block.cr b/src/ameba/rule/style/verbose_block.cr index a97661cb..5e70ee5c 100644 --- a/src/ameba/rule/style/verbose_block.cr +++ b/src/ameba/rule/style/verbose_block.cr @@ -190,11 +190,12 @@ module Ameba::Rule::Style protected def issue_for_valid(source, call : Crystal::Call, block : Crystal::Block, body : Crystal::Call) return unless location = call.name_location return unless end_location = block.end_location - return if exclude_calls_with_block && body.block - return if exclude_multiple_line_blocks && !same_location_lines?(call, body) - return if exclude_prefix_operators && prefix_operator?(body) - return if exclude_operators && operator?(body.name) - return if exclude_setters && setter?(body.name) + + return if exclude_calls_with_block? && body.block + return if exclude_multiple_line_blocks? && !same_location_lines?(call, body) + return if exclude_prefix_operators? && prefix_operator?(body) + return if exclude_operators? && operator?(body.name) + return if exclude_setters? && setter?(body.name) call_code = call_code(source, call, body)