Class: Laser::ExtraBlankLinesWarning

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

Overview

Warning for using semicolons outside of class declarations.

Constant Summary

EXTRA_LINE =
/\n[\t ]*\Z/

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

#count_extra_linesObject

Counts how many extra lines there are at the end of the file.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/laser/warnings/extra_blank_lines.rb', line 19

def count_extra_lines
  # We use this logic because #lines ignores blank lines at the end, and
  # split(/\n/) does as well.
  count = 0
  working_body = self.body.dup
  while working_body =~ EXTRA_LINE
    working_body.sub!(EXTRA_LINE, '')
    count += 1
  end
  count
end

#fix(body = self.body) ⇒ Object



14
15
16
# File 'lib/laser/warnings/extra_blank_lines.rb', line 14

def fix(body = self.body)
  body.gsub(/\s*\Z/, '')
end

#match?(body = self.body) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/laser/warnings/extra_blank_lines.rb', line 10

def match?(body = self.body)
  body =~ EXTRA_LINE
end