Class: Tailor::Rulers::TrailingNewlinesRuler
- Inherits:
-
Tailor::Ruler
- Object
- Tailor::Ruler
- Tailor::Rulers::TrailingNewlinesRuler
- Defined in:
- lib/tailor/rulers/trailing_newlines_ruler.rb
Instance Attribute Summary
Attributes inherited from Tailor::Ruler
Instance Method Summary collapse
-
#file_end_update(trailing_newline_count) ⇒ Object
Checks to see if the file’s final character is a n.
-
#initialize(config, options) ⇒ TrailingNewlinesRuler
constructor
A new instance of TrailingNewlinesRuler.
-
#measure(trailing_newline_count) ⇒ Object
Checks to see if the number of newlines at the end of the file is not equal to the value at @config.
Methods inherited from Tailor::Ruler
#add_child_ruler, #problem_type, #problems
Methods included from Logger::Mixin
Constructor Details
#initialize(config, options) ⇒ TrailingNewlinesRuler
Returns a new instance of TrailingNewlinesRuler.
7 8 9 10 |
# File 'lib/tailor/rulers/trailing_newlines_ruler.rb', line 7 def initialize(config, ) super(config, ) add_lexer_observers :file_end end |
Instance Method Details
#file_end_update(trailing_newline_count) ⇒ Object
Checks to see if the file’s final character is a n. If it is, it just returns the text that was passed in. If it’s not, it adds a n, since the current indentation-checking algorithm only checks indent levels when it parses a newline character (without this, indentation problems on the final line won’t ever get caught).
36 37 38 |
# File 'lib/tailor/rulers/trailing_newlines_ruler.rb', line 36 def file_end_update(trailing_newline_count) measure(trailing_newline_count) end |
#measure(trailing_newline_count) ⇒ Object
Checks to see if the number of newlines at the end of the file is not equal to the value at @config.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tailor/rulers/trailing_newlines_ruler.rb', line 17 def measure(trailing_newline_count) if trailing_newline_count != @config lineno = "<EOF>" column = "<EOF>" msg = "File has #{trailing_newline_count} trailing " msg << "newlines, but should have #{@config}." @problems << Problem.new(problem_type, lineno, column, msg, @options[:level]) end end |