mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Refactor comparison to boolean rule
This commit is contained in:
		
							parent
							
								
									362b66ce81
								
							
						
					
					
						commit
						b6c0d3e8ad
					
				
					 1 changed files with 7 additions and 6 deletions
				
			
		| 
						 | 
					@ -18,12 +18,13 @@ module Ameba::Rules
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test(source, node : Crystal::Call)
 | 
					    def test(source, node : Crystal::Call)
 | 
				
			||||||
      if %w(== != ===).includes?(node.name) && (
 | 
					      comparison? = %w(== != ===).includes?(node.name)
 | 
				
			||||||
           node.args.first?.try &.is_a?(Crystal::BoolLiteral) ||
 | 
					      to_boolean? = node.args.first?.try &.is_a?(Crystal::BoolLiteral) ||
 | 
				
			||||||
                    node.obj.is_a?(Crystal::BoolLiteral)
 | 
					                    node.obj.is_a?(Crystal::BoolLiteral)
 | 
				
			||||||
         )
 | 
					
 | 
				
			||||||
 | 
					      return unless comparison? && to_boolean?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      source.error self, node.location, "Comparison to a boolean is pointless"
 | 
					      source.error self, node.location, "Comparison to a boolean is pointless"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue