Class: Wool::ExtraBlankLinesWarning
- Inherits:
-
FileWarning
- Object
- Struct
- Warning
- FileWarning
- Wool::ExtraBlankLinesWarning
- Defined in:
- lib/wool/warnings/extra_blank_lines.rb
Overview
Warning for using semicolons outside of class declarations.
Constant Summary collapse
- EXTRA_LINE =
/\n[\t ]*\Z/
Instance Attribute Summary
Attributes inherited from Warning
#body, #file, #line_number, #name, #settings, #severity
Instance Method Summary collapse
-
#count_extra_lines ⇒ Object
Counts how many extra lines there are at the end of the file.
- #fix ⇒ Object
- #match?(body = self.body) ⇒ Boolean
Methods inherited from FileWarning
Methods inherited from Warning
all_types, all_warnings, concrete_warnings, #count_occurrences, #desc, #fixable?, #generated_warnings, #get_indent, #indent, inherited, #initialize, opt, options, setting_accessor, type
Methods included from Advice
#advice_counter, #after_advice, #argument_advice, #before_advice, #bump_advice_counter!, #with_advice
Methods included from ModuleExtensions
#attr_accessor_with_default, #cattr_accessor, #cattr_accessor_with_default, #cattr_get_and_setter, #cattr_reader, #cattr_writer
Methods included from SexpAnalysis
Methods included from LexicalAnalysis
#find_keyword, #find_token, #lex, #select_token, #split_on_keyword, #split_on_token, #text_between_token_positions
Constructor Details
This class inherits a constructor from Wool::Warning
Instance Method Details
#count_extra_lines ⇒ Object
Counts how many extra lines there are at the end of the file.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wool/warnings/extra_blank_lines.rb', line 18 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 ⇒ Object
13 14 15 |
# File 'lib/wool/warnings/extra_blank_lines.rb', line 13 def fix body.gsub(/\s*\Z/, '') end |
#match?(body = self.body) ⇒ Boolean
9 10 11 |
# File 'lib/wool/warnings/extra_blank_lines.rb', line 9 def match?(body = self.body) body =~ EXTRA_LINE end |