Class: Skeptic::Rules::NoSemicolons

Inherits:
Object
  • Object
show all
Defined in:
lib/skeptic/rules/no_semicolons.rb

Constant Summary collapse

DESCRIPTION =
'Do not allow semicolons as statement separators'

Instance Method Summary collapse

Constructor Details

#initialize(enabled = false) ⇒ NoSemicolons

Returns a new instance of NoSemicolons.



6
7
8
# File 'lib/skeptic/rules/no_semicolons.rb', line 6

def initialize(enabled = false)
  @enabled = enabled
end

Instance Method Details

#apply_to(code, tokens, sexp) ⇒ Object



10
11
12
13
14
15
# File 'lib/skeptic/rules/no_semicolons.rb', line 10

def apply_to(code, tokens, sexp)
  @locations = tokens.
    select { |location, type, token| token == ';' and type == :on_semicolon }.
    map { |location, type, token| location }
  self
end

#nameObject



23
24
25
# File 'lib/skeptic/rules/no_semicolons.rb', line 23

def name
  'No semicolons as expression separators'
end

#semicolon_locationsObject



27
28
29
# File 'lib/skeptic/rules/no_semicolons.rb', line 27

def semicolon_locations
  @locations
end

#violationsObject



17
18
19
20
21
# File 'lib/skeptic/rules/no_semicolons.rb', line 17

def violations
  @locations.map do |line, column|
    "You have a semicolon at line #{line}, column #{column}"
  end
end