Class: Laser::HashSymbol19Warning

Inherits:
FileWarning show all
Defined in:
lib/laser/warnings/hash_symbol_19_warning.rb

Overview

Warning for rescuing “Exception” or “Object”.

Instance Attribute Summary

Attributes inherited from Warning

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

Instance Method Summary (collapse)

Methods inherited from FileWarning

options

Instance Method Details

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



22
23
24
25
26
27
28
# File 'lib/laser/warnings/hash_symbol_19_warning.rb', line 22

def fix(body = self.body)
  lines = body.lines.to_a  # eagerly expand lines
  label = token
  lines[label.line - 1][label.col + line_adjustments[label.line],label.body.size] = ":#{label.body[0..-2]} =>"
  line_adjustments[label.line] += 3  # " =>" is inserted and is 3 chars
  lines.join
end

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

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
# File 'lib/laser/warnings/hash_symbol_19_warning.rb', line 11

def match?(body = self.body)
  line_adjustments = Hash.new(0)
  lex.map do |token|
    if token.type == :on_label
      Laser::HashSymbol19Warning.new(file, body,
          token: token,
          line_adjustments: line_adjustments)
    end
  end.compact
end