mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Minor details
This commit is contained in:
		
							parent
							
								
									523a622b34
								
							
						
					
					
						commit
						134963ece7
					
				
					 7 changed files with 21 additions and 10 deletions
				
			
		| 
						 | 
					@ -12,15 +12,17 @@ module Ameba::AST
 | 
				
			||||||
    # :nodoc:
 | 
					    # :nodoc:
 | 
				
			||||||
    def visit(node : Crystal::Require)
 | 
					    def visit(node : Crystal::Require)
 | 
				
			||||||
      require_nodes << node
 | 
					      require_nodes << node
 | 
				
			||||||
 | 
					      true
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # If a top level node is Crystal::Expressions traverse the children.
 | 
					    # If a top level node is `Crystal::Expressions`,
 | 
				
			||||||
 | 
					    # then always traverse the children.
 | 
				
			||||||
    def visit(node : Crystal::Expressions)
 | 
					    def visit(node : Crystal::Expressions)
 | 
				
			||||||
      true
 | 
					      true
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # A general visit method for rest of the nodes.
 | 
					    # A general visit method for rest of the nodes.
 | 
				
			||||||
    # Returns false meaning all child nodes will not be traversed.
 | 
					    # Returns `false`, meaning all child nodes will not be traversed.
 | 
				
			||||||
    def visit(node : Crystal::ASTNode)
 | 
					    def visit(node : Crystal::ASTNode)
 | 
				
			||||||
      false
 | 
					      false
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,7 +24,9 @@ module Ameba::Rule::Layout
 | 
				
			||||||
      return if source_lines_size == 1 && last_source_line.empty?
 | 
					      return if source_lines_size == 1 && last_source_line.empty?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      last_line_empty = last_source_line.empty?
 | 
					      last_line_empty = last_source_line.empty?
 | 
				
			||||||
      return if source_lines_size.zero? || (source_lines.last(2).join.presence && last_line_empty)
 | 
					      return if source_lines_size.zero? ||
 | 
				
			||||||
 | 
					                (source_lines.last(2).join.presence && last_line_empty)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if last_line_empty
 | 
					      if last_line_empty
 | 
				
			||||||
        issue_for({source_lines_size, 1}, MSG)
 | 
					        issue_for({source_lines_size, 1}, MSG)
 | 
				
			||||||
      else
 | 
					      else
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,6 +41,7 @@ module Ameba::Rule::Lint
 | 
				
			||||||
        op_end_location.column_number - 1
 | 
					        op_end_location.column_number - 1
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      op_text = source_between(op_location, op_end_location, source.lines)
 | 
					      op_text = source_between(op_location, op_end_location, source.lines)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return unless op_text
 | 
					      return unless op_text
 | 
				
			||||||
      return unless MISTAKES.has_key?(op_text)
 | 
					      return unless MISTAKES.has_key?(op_text)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,7 +35,7 @@ module Ameba::Rule::Lint
 | 
				
			||||||
    private def duplicated_keys(entries)
 | 
					    private def duplicated_keys(entries)
 | 
				
			||||||
      entries.map(&.key)
 | 
					      entries.map(&.key)
 | 
				
			||||||
        .group_by(&.itself)
 | 
					        .group_by(&.itself)
 | 
				
			||||||
        .tap(&.select! { |_, v| v.size > 1 })
 | 
					        .select! { |_, v| v.size > 1 }
 | 
				
			||||||
        .map { |k, _| k }
 | 
					        .map { |k, _| k }
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,13 +45,16 @@ module Ameba::Rule::Lint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return if rescues.nil?
 | 
					      return if rescues.nil?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      shadowed(rescues).each { |tp| issue_for tp, MSG % tp.names.join("::") }
 | 
					      shadowed(rescues).each do |path|
 | 
				
			||||||
 | 
					        issue_for path, MSG % path.names.join("::")
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private def shadowed(rescues, catch_all = false)
 | 
					    private def shadowed(rescues, catch_all = false)
 | 
				
			||||||
      traversed_types = Set(String).new
 | 
					      traversed_types = Set(String).new
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      filter_rescues(rescues).each_with_object([] of Crystal::Path) do |types, shadowed|
 | 
					      rescues = filter_rescues(rescues)
 | 
				
			||||||
 | 
					      rescues.each_with_object([] of Crystal::Path) do |types, shadowed|
 | 
				
			||||||
        case
 | 
					        case
 | 
				
			||||||
        when catch_all
 | 
					        when catch_all
 | 
				
			||||||
          shadowed.concat(types)
 | 
					          shadowed.concat(types)
 | 
				
			||||||
| 
						 | 
					@ -62,7 +65,7 @@ module Ameba::Rule::Lint
 | 
				
			||||||
          catch_all = true
 | 
					          catch_all = true
 | 
				
			||||||
          next
 | 
					          next
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
          nodes = types.select { |tp| traverse(tp.to_s, traversed_types) }
 | 
					          nodes = types.select { |path| traverse(path.to_s, traversed_types) }
 | 
				
			||||||
          shadowed.concat(nodes) unless nodes.empty?
 | 
					          shadowed.concat(nodes) unless nodes.empty?
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,10 +20,12 @@ module Ameba::Rule::Metrics
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test(source, node : Crystal::Def)
 | 
					    def test(source, node : Crystal::Def)
 | 
				
			||||||
      complexity = AST::CountingVisitor.new(node).count
 | 
					      complexity = AST::CountingVisitor.new(node).count
 | 
				
			||||||
 | 
					      return unless complexity > max_complexity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return unless complexity > max_complexity && (location = node.name_location)
 | 
					      return unless location = node.name_location
 | 
				
			||||||
      issue_for location, name_end_location(node),
 | 
					      end_location = name_end_location(node)
 | 
				
			||||||
        MSG % {complexity, max_complexity}
 | 
					
 | 
				
			||||||
 | 
					      issue_for location, end_location, MSG % {complexity, max_complexity}
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -79,6 +79,7 @@ module Ameba::Rule::Style
 | 
				
			||||||
      old = OLD % node.name
 | 
					      old = OLD % node.name
 | 
				
			||||||
      new = NEW % {node.name, name}
 | 
					      new = NEW % {node.name, name}
 | 
				
			||||||
      msg = MSG % {new, old}
 | 
					      msg = MSG % {new, old}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if end_location
 | 
					      if end_location
 | 
				
			||||||
        issue_for(filter_location, end_location, msg) do |corrector|
 | 
					        issue_for(filter_location, end_location, msg) do |corrector|
 | 
				
			||||||
          corrector.replace(filter_location, end_location, new)
 | 
					          corrector.replace(filter_location, end_location, new)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue