mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Prevent disabling of UnneededDisableDirective rule
This commit is contained in:
		
							parent
							
								
									8075c39aa9
								
							
						
					
					
						commit
						6fb483a2dd
					
				
					 4 changed files with 18 additions and 3 deletions
				
			
		| 
						 | 
					@ -65,6 +65,15 @@ module Ameba::Rule
 | 
				
			||||||
      s.errors.last.message.should contain "Rule3"
 | 
					      s.errors.last.message.should contain "Rule3"
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it "fails if there is disabled UnneededDisableDirective" do
 | 
				
			||||||
 | 
					      s = Source.new %Q(
 | 
				
			||||||
 | 
					        # ameba:disable #{UnneededDisableDirective.class_name}
 | 
				
			||||||
 | 
					        a = 1
 | 
				
			||||||
 | 
					      ), "source.cr"
 | 
				
			||||||
 | 
					      s.error UnneededDisableDirective.new, 3, 1, "Alarm!", :disabled
 | 
				
			||||||
 | 
					      subject.catch(s).should_not be_valid
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "reports error, location and message" do
 | 
					    it "reports error, location and message" do
 | 
				
			||||||
      s = Source.new %Q(
 | 
					      s = Source.new %Q(
 | 
				
			||||||
        # ameba:disable Rule1, Rule2
 | 
					        # ameba:disable Rule1, Rule2
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ module Ameba
 | 
				
			||||||
    # ```
 | 
					    # ```
 | 
				
			||||||
    #
 | 
					    #
 | 
				
			||||||
    def location_disabled?(location, rule)
 | 
					    def location_disabled?(location, rule)
 | 
				
			||||||
 | 
					      return false if Rule::SPECIAL.includes?(rule)
 | 
				
			||||||
      return false unless line_number = location.try &.line_number.try &.- 1
 | 
					      return false unless line_number = location.try &.line_number.try &.- 1
 | 
				
			||||||
      return false unless line = lines[line_number]?
 | 
					      return false unless line = lines[line_number]?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,9 @@
 | 
				
			||||||
module Ameba::Rule
 | 
					module Ameba::Rule
 | 
				
			||||||
 | 
					  SPECIAL = [
 | 
				
			||||||
 | 
					    Syntax.class_name,
 | 
				
			||||||
 | 
					    UnneededDisableDirective.class_name,
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Represents a base of all rules. In other words, all rules
 | 
					  # Represents a base of all rules. In other words, all rules
 | 
				
			||||||
  # inherits from this struct:
 | 
					  # inherits from this struct:
 | 
				
			||||||
  #
 | 
					  #
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,7 @@ module Ameba::Rule
 | 
				
			||||||
  # end
 | 
					  # end
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					  #
 | 
				
			||||||
  # as the predicate name is correct and comment directive does not
 | 
					  # as the predicate name is correct and the comment directive does not
 | 
				
			||||||
  # have any effect, the snippet should be written as the following:
 | 
					  # have any effect, the snippet should be written as the following:
 | 
				
			||||||
  #
 | 
					  #
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
| 
						 | 
					@ -39,11 +39,11 @@ module Ameba::Rule
 | 
				
			||||||
      return unless directive[:action] == "disable"
 | 
					      return unless directive[:action] == "disable"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      directive[:rules].reject do |rule_name|
 | 
					      directive[:rules].reject do |rule_name|
 | 
				
			||||||
        any = source.errors.any? do |error|
 | 
					        source.errors.any? do |error|
 | 
				
			||||||
          error.rule.name == rule_name &&
 | 
					          error.rule.name == rule_name &&
 | 
				
			||||||
            error.disabled? &&
 | 
					            error.disabled? &&
 | 
				
			||||||
            error.location.try(&.line_number) == location.line_number
 | 
					            error.location.try(&.line_number) == location.line_number
 | 
				
			||||||
        end
 | 
					        end && rule_name != self.name
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue