Class: Laser::SemicolonWarning

Inherits:
LineWarning show all
Defined in:
lib/laser/warnings/semicolon.rb

Overview

Warning for using semicolons outside of class declarations.

Instance Attribute Summary

Attributes inherited from Warning

#body, #file, #line_number, #name, #severity

Instance Method Summary (collapse)

Methods inherited from LineWarning

options

Constructor Details

- (SemicolonWarning) initialize(*args)



8
9
10
11
# File 'lib/laser/warnings/semicolon.rb', line 8

def initialize(*args)
  super
  self.severity = line =~ /['"]/ ? 2 : 4
end

Instance Method Details

- (Object) fix(line = self.body)



17
18
19
20
21
22
23
24
# File 'lib/laser/warnings/semicolon.rb', line 17

def fix(line = self.body)
  left, right = split_on_token(line, :on_semicolon)
  return line if right.empty?
  return right[1..-1] if left.empty?

  right = fix(right[1..-1])
  "#{indent left}\n#{indent right}"
end

- (Boolean) match?(line = self.body)



13
14
15
# File 'lib/laser/warnings/semicolon.rb', line 13

def match?(line = self.body)
  !!(find_token(line, :on_semicolon) && !find_keyword(line, :class))
end