mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	New rule: RedundantWithObject (#121)
This commit is contained in:
		
							parent
							
								
									b6cc454039
								
							
						
					
					
						commit
						fde321f7e6
					
				
					 2 changed files with 138 additions and 0 deletions
				
			
		
							
								
								
									
										83
									
								
								spec/ameba/rule/lint/redundant_with_object_spec.cr
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								spec/ameba/rule/lint/redundant_with_object_spec.cr
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,83 @@
 | 
			
		|||
require "../../../spec_helper"
 | 
			
		||||
 | 
			
		||||
module Ameba::Rule::Lint
 | 
			
		||||
  describe RedundantWithObject do
 | 
			
		||||
    subject = RedundantWithObject.new
 | 
			
		||||
 | 
			
		||||
    it "does not report if there is index argument" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        collection.each_with_object(0) do |e, obj|
 | 
			
		||||
          obj += i
 | 
			
		||||
        end
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "reports if there is not index argument" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        collection.each_with_object(0) do |e|
 | 
			
		||||
          e += 1
 | 
			
		||||
        end
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should_not be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "reports if there is underscored index argument" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        collection.each_with_object(0) do |e, _|
 | 
			
		||||
          e += 1
 | 
			
		||||
        end
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should_not be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "reports if there is no args" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        collection.each_with_object(0) do
 | 
			
		||||
          puts :nothing
 | 
			
		||||
        end
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should_not be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "does not report if there is no block" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        collection.each_with_object(0)
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "does not report if first argument is underscored" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        collection.each_with_object(0) do |_, obj|
 | 
			
		||||
          puts i
 | 
			
		||||
        end
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "does not report if there are more than 2 args" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        tup.each_with_object(0) do |key, value, obj|
 | 
			
		||||
          puts i
 | 
			
		||||
        end
 | 
			
		||||
      )
 | 
			
		||||
      subject.catch(s).should be_valid
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "reports rule, location and message" do
 | 
			
		||||
      s = Source.new %(
 | 
			
		||||
        def valid?
 | 
			
		||||
          collection.each_with_object(0) do |e|
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      ), "source.cr"
 | 
			
		||||
      subject.catch(s).should_not be_valid
 | 
			
		||||
      issue = s.issues.first
 | 
			
		||||
      issue.rule.should_not be_nil
 | 
			
		||||
      issue.location.to_s.should eq "source.cr:2:14"
 | 
			
		||||
      issue.end_location.to_s.should eq "source.cr:2:30"
 | 
			
		||||
      issue.message.should eq "Use each instead of each_with_object"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue