mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Performance/FirstLastAfterFilter: ignore .first/.last with args
closes #104
This commit is contained in:
		
							parent
							
								
									9e2061cbf6
								
							
						
					
					
						commit
						037d1dde74
					
				
					 2 changed files with 8 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -36,6 +36,13 @@ module Ameba::Rule::Performance
 | 
			
		|||
      subject.catch(source).should_not be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "does not report if there is selected followed by first with arguments" do
 | 
			
		||||
      source = Source.new %(
 | 
			
		||||
        [1, 2, 3].select { |n| n % 2 == 0 }.first(2)
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(source).should be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "reports if there is select followed by first?" do
 | 
			
		||||
      source = Source.new %(
 | 
			
		||||
        [1, 2, 3].select { |e| e > 2 }.first?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,6 +45,7 @@ module Ameba::Rule::Performance
 | 
			
		|||
 | 
			
		||||
    def test(source, node : Crystal::Call)
 | 
			
		||||
      return unless CALL_NAMES.includes?(node.name) && (obj = node.obj)
 | 
			
		||||
      return if node.args.any?
 | 
			
		||||
 | 
			
		||||
      if node.block.nil? && obj.is_a?(Crystal::Call) &&
 | 
			
		||||
         filter_names.includes?(obj.name) && !obj.block.nil?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue