Class: Audition::Directives

Inherits:
Object
  • Object
show all
Defined in:
lib/audition/directives.rb

Overview

Same-line suppression pragmas:

$flag = true  # audition:disable global-variables
legacy_call   # audition:disable

A bare pragma silences every check on that line; otherwise only the listed check names. Applied to any finding carrying a real path and line, including runtime findings.

Constant Summary collapse

PATTERN =
/#\s*audition:disable\b[ \t]*(?<list>[^#\n]*)/

Instance Method Summary collapse

Constructor Details

#initializeDirectives

Returns a new instance of Directives.



15
16
17
# File 'lib/audition/directives.rb', line 15

def initialize
  @by_path = {}
end

Instance Method Details

#disabled?(finding) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'lib/audition/directives.rb', line 25

def disabled?(finding)
  return false unless finding.path && finding.line

  checks = directives_for(finding.path)[finding.line]
  return false unless checks

  checks.empty? || checks.include?(finding.check)
end

#filter(findings) ⇒ Array<Finding>

Returns findings not silenced by a pragma.

Parameters:

Returns:

  • (Array<Finding>)

    findings not silenced by a pragma



21
22
23
# File 'lib/audition/directives.rb', line 21

def filter(findings)
  findings.reject { |finding| disabled?(finding) }
end