mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Use property? for defining Bool-returning Rule properties
				
					
				
			This commit is contained in:
		
							parent
							
								
									c7c75ee36a
								
							
						
					
					
						commit
						2af58cabd4
					
				
					 6 changed files with 21 additions and 16 deletions
				
			
		| 
						 | 
					@ -242,8 +242,12 @@ class Ameba::Config
 | 
				
			||||||
        {% properties[name] = {key: key, default: value, type: type, converter: converter} %}
 | 
					        {% properties[name] = {key: key, default: value, type: type, converter: converter} %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        @[YAML::Field(key: {{ key }}, converter: {{ converter }}, type: {{ type }})]
 | 
					        @[YAML::Field(key: {{ key }}, converter: {{ converter }}, type: {{ type }})]
 | 
				
			||||||
 | 
					        {% if type == Bool %}
 | 
				
			||||||
 | 
					          property? {{ name }} : {{ type }} = {{ value }}
 | 
				
			||||||
 | 
					        {% else %}
 | 
				
			||||||
          property {{ name }} : {{ type }} = {{ value }}
 | 
					          property {{ name }} : {{ type }} = {{ value }}
 | 
				
			||||||
        {% end %}
 | 
					        {% end %}
 | 
				
			||||||
 | 
					      {% end %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      {% if properties["enabled".id] == nil %}
 | 
					      {% if properties["enabled".id] == nil %}
 | 
				
			||||||
        @[YAML::Field(key: "Enabled")]
 | 
					        @[YAML::Field(key: "Enabled")]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,15 +41,15 @@ module Ameba::Rule::Lint
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test(source, node : Crystal::ProcLiteral, scope : AST::Scope)
 | 
					    def test(source, node : Crystal::ProcLiteral, scope : AST::Scope)
 | 
				
			||||||
      ignore_procs || find_unused_arguments source, scope
 | 
					      ignore_procs? || find_unused_arguments source, scope
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test(source, node : Crystal::Block, scope : AST::Scope)
 | 
					    def test(source, node : Crystal::Block, scope : AST::Scope)
 | 
				
			||||||
      ignore_blocks || find_unused_arguments source, scope
 | 
					      ignore_blocks? || find_unused_arguments source, scope
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test(source, node : Crystal::Def, scope : AST::Scope)
 | 
					    def test(source, node : Crystal::Def, scope : AST::Scope)
 | 
				
			||||||
      ignore_defs || find_unused_arguments source, scope
 | 
					      ignore_defs? || find_unused_arguments source, scope
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private def find_unused_arguments(source, scope)
 | 
					    private def find_unused_arguments(source, scope)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ module Ameba::Rule::Style
 | 
				
			||||||
      when Crystal::Yield
 | 
					      when Crystal::Yield
 | 
				
			||||||
        !in_ternary || node.has_parentheses? || node.exps.empty?
 | 
					        !in_ternary || node.has_parentheses? || node.exps.empty?
 | 
				
			||||||
      when Crystal::Assign, Crystal::OpAssign, Crystal::MultiAssign
 | 
					      when Crystal::Assign, Crystal::OpAssign, Crystal::MultiAssign
 | 
				
			||||||
        !in_ternary && !allow_safe_assignment
 | 
					        !in_ternary && !allow_safe_assignment?
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
        true
 | 
					        true
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ module Ameba::Rule::Style
 | 
				
			||||||
    def test(source, node : Crystal::If | Crystal::Unless | Crystal::Case | Crystal::While | Crystal::Until)
 | 
					    def test(source, node : Crystal::If | Crystal::Unless | Crystal::Case | Crystal::While | Crystal::Until)
 | 
				
			||||||
      cond = node.cond
 | 
					      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|
 | 
					        issue_for cond, MSG_MISSING do |corrector|
 | 
				
			||||||
          corrector.insert_before(cond, '(')
 | 
					          corrector.insert_before(cond, '(')
 | 
				
			||||||
          corrector.insert_after(cond, ')')
 | 
					          corrector.insert_after(cond, ')')
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ module Ameba::Rule::Style
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      is_ternary = node.is_a?(Crystal::If) && node.ternary?
 | 
					      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.is_a?(Crystal::Expressions)
 | 
				
			||||||
      return unless cond.keyword.paren?
 | 
					      return unless cond.keyword.paren?
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -113,8 +113,8 @@ module Ameba::Rule::Style
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test(source, node : Crystal::Next, visitor : AST::RedundantControlExpressionVisitor)
 | 
					    def test(source, node : Crystal::Next, visitor : AST::RedundantControlExpressionVisitor)
 | 
				
			||||||
      return if allow_multi_next && node.exp.is_a?(Crystal::TupleLiteral)
 | 
					      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_empty_next? && (node.exp.nil? || node.exp.try(&.nop?))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if exp_code = control_exp_code(node, source.lines)
 | 
					      if exp_code = control_exp_code(node, source.lines)
 | 
				
			||||||
        issue_for node, MSG do |corrector|
 | 
					        issue_for node, MSG do |corrector|
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -110,8 +110,8 @@ module Ameba::Rule::Style
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test(source, node : Crystal::Return, visitor : AST::RedundantControlExpressionVisitor)
 | 
					    def test(source, node : Crystal::Return, visitor : AST::RedundantControlExpressionVisitor)
 | 
				
			||||||
      return if allow_multi_return && node.exp.is_a?(Crystal::TupleLiteral)
 | 
					      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_empty_return? && (node.exp.nil? || node.exp.try(&.nop?))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if exp_code = control_exp_code(node, source.lines)
 | 
					      if exp_code = control_exp_code(node, source.lines)
 | 
				
			||||||
        issue_for node, MSG do |corrector|
 | 
					        issue_for node, MSG do |corrector|
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -190,11 +190,12 @@ module Ameba::Rule::Style
 | 
				
			||||||
    protected def issue_for_valid(source, call : Crystal::Call, block : Crystal::Block, body : Crystal::Call)
 | 
					    protected def issue_for_valid(source, call : Crystal::Call, block : Crystal::Block, body : Crystal::Call)
 | 
				
			||||||
      return unless location = call.name_location
 | 
					      return unless location = call.name_location
 | 
				
			||||||
      return unless end_location = block.end_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_calls_with_block? && body.block
 | 
				
			||||||
      return if exclude_prefix_operators && prefix_operator?(body)
 | 
					      return if exclude_multiple_line_blocks? && !same_location_lines?(call, body)
 | 
				
			||||||
      return if exclude_operators && operator?(body.name)
 | 
					      return if exclude_prefix_operators? && prefix_operator?(body)
 | 
				
			||||||
      return if exclude_setters && setter?(body.name)
 | 
					      return if exclude_operators? && operator?(body.name)
 | 
				
			||||||
 | 
					      return if exclude_setters? && setter?(body.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      call_code =
 | 
					      call_code =
 | 
				
			||||||
        call_code(source, call, body)
 | 
					        call_code(source, call, body)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue