mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Properly detect if scope references a variable
This commit is contained in:
		
							parent
							
								
									904b5beec2
								
							
						
					
					
						commit
						19d9223ec1
					
				
					 2 changed files with 4 additions and 3 deletions
				
			
		| 
						 | 
					@ -90,8 +90,9 @@ module Ameba::AST
 | 
				
			||||||
    # false if not.
 | 
					    # false if not.
 | 
				
			||||||
    def references?(variable : Variable)
 | 
					    def references?(variable : Variable)
 | 
				
			||||||
      variable.references.any? do |reference|
 | 
					      variable.references.any? do |reference|
 | 
				
			||||||
        reference.scope == self || inner_scopes.any?(&.references? variable)
 | 
					        reference.scope == self ||
 | 
				
			||||||
      end
 | 
					          inner_scopes.any?(&.references? variable)
 | 
				
			||||||
 | 
					      end || variable.used_in_macro?
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Returns true if current scope is a def, false if not.
 | 
					    # Returns true if current scope is a def, false if not.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ module Ameba::Rule::Lint
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private def find_unused_arguments(source, scope)
 | 
					    private def find_unused_arguments(source, scope)
 | 
				
			||||||
      scope.arguments.each do |argument|
 | 
					      scope.arguments.each do |argument|
 | 
				
			||||||
        next if argument.ignored? || scope.references?(argument.variable) || argument.variable.used_in_macro?
 | 
					        next if argument.ignored? || scope.references?(argument.variable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        name_suggestion = scope.node.is_a?(Crystal::Block) ? '_' : "_#{argument.name}"
 | 
					        name_suggestion = scope.node.is_a?(Crystal::Block) ? '_' : "_#{argument.name}"
 | 
				
			||||||
        issue_for argument.node, MSG % {argument.name, name_suggestion}
 | 
					        issue_for argument.node, MSG % {argument.name, name_suggestion}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue