Class: Skeptic::Rules::NoGlobalVariables

Inherits:
Object
  • Object
show all
Includes:
SexpVisitor
Defined in:
lib/skeptic/rules/no_global_variables.rb

Constant Summary collapse

DESCRIPTION =
'Do not allow the use of global variables'

Instance Method Summary collapse

Methods included from SexpVisitor

included

Constructor Details

#initialize(enabled = false) ⇒ NoGlobalVariables

Returns a new instance of NoGlobalVariables.



8
9
10
11
# File 'lib/skeptic/rules/no_global_variables.rb', line 8

def initialize(enabled = false)
  @enabled = enabled
  @violations = []
end

Instance Method Details

#apply_to(code, tokens, sexp) ⇒ Object



13
14
15
16
# File 'lib/skeptic/rules/no_global_variables.rb', line 13

def apply_to(code, tokens, sexp)
  visit sexp
  self
end

#nameObject



24
25
26
# File 'lib/skeptic/rules/no_global_variables.rb', line 24

def name
  'No global variables'
end

#violationsObject



18
19
20
21
22
# File 'lib/skeptic/rules/no_global_variables.rb', line 18

def violations
  @violations.map do |variable, line|
    "You have a global variable #{variable} on line #{line}"
  end
end