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. Pragmas are read from Prism's comment list, never from raw lines: pragma-shaped text inside a string literal is data, not a directive.

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initializeDirectives

Returns a new instance of Directives.



19
20
21
# File 'lib/audition/directives.rb', line 19

def initialize
  @by_path = {}
end

Instance Method Details

#disabled?(finding) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/audition/directives.rb', line 29

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



25
26
27
# File 'lib/audition/directives.rb', line 25

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