tailor 1.0.0.alpha2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/.gitignore +1 -0
  2. data/.tailor +10 -2
  3. data/Gemfile.lock +2 -2
  4. data/History.rdoc +20 -0
  5. data/README.rdoc +176 -26
  6. data/features/configurable.feature +19 -39
  7. data/features/horizontal_spacing.feature +3 -2
  8. data/features/indentation.feature +2 -2
  9. data/features/indentation/bad_files_with_no_trailing_newline.feature +9 -8
  10. data/features/indentation/good_files_with_no_trailing_newline.feature +19 -6
  11. data/features/name_detection.feature +2 -2
  12. data/features/support/env.rb +0 -2
  13. data/features/support/file_cases/horizontal_spacing_cases.rb +5 -4
  14. data/features/support/file_cases/indentation_cases.rb +105 -54
  15. data/features/support/file_cases/naming_cases.rb +0 -1
  16. data/features/support/file_cases/vertical_spacing_cases.rb +0 -1
  17. data/features/support/legacy/bad_ternary_colon_spacing.rb +1 -1
  18. data/features/valid_ruby.feature +17 -0
  19. data/features/vertical_spacing.feature +40 -19
  20. data/lib/ext/string_ext.rb +12 -0
  21. data/lib/tailor/cli.rb +7 -5
  22. data/lib/tailor/cli/options.rb +13 -3
  23. data/lib/tailor/composite_observable.rb +17 -2
  24. data/lib/tailor/configuration.rb +83 -72
  25. data/lib/tailor/configuration/style.rb +85 -0
  26. data/lib/tailor/critic.rb +67 -117
  27. data/lib/tailor/formatter.rb +38 -0
  28. data/lib/tailor/formatters/text.rb +35 -10
  29. data/lib/tailor/lexed_line.rb +38 -5
  30. data/lib/tailor/lexer.rb +150 -14
  31. data/lib/tailor/{lexer_constants.rb → lexer/lexer_constants.rb} +9 -7
  32. data/lib/tailor/lexer/token.rb +6 -2
  33. data/lib/tailor/logger.rb +4 -0
  34. data/lib/tailor/problem.rb +8 -73
  35. data/lib/tailor/reporter.rb +1 -1
  36. data/lib/tailor/ruler.rb +67 -6
  37. data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +9 -1
  38. data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +9 -1
  39. data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +38 -0
  40. data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +9 -2
  41. data/lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb +10 -5
  42. data/lib/tailor/rulers/indentation_spaces_ruler.rb +93 -26
  43. data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +128 -84
  44. data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +9 -5
  45. data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +9 -5
  46. data/lib/tailor/rulers/max_line_length_ruler.rb +10 -5
  47. data/lib/tailor/rulers/spaces_after_comma_ruler.rb +13 -4
  48. data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +8 -4
  49. data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +8 -4
  50. data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +8 -4
  51. data/lib/tailor/rulers/spaces_before_comma_ruler.rb +8 -4
  52. data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +13 -6
  53. data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +12 -8
  54. data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +12 -5
  55. data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +13 -6
  56. data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +13 -9
  57. data/lib/tailor/rulers/trailing_newlines_ruler.rb +10 -5
  58. data/lib/tailor/tailorrc.erb +3 -3
  59. data/lib/tailor/version.rb +1 -1
  60. data/m.rb +15 -0
  61. data/spec/spec_helper.rb +0 -1
  62. data/spec/tailor/cli_spec.rb +8 -9
  63. data/spec/tailor/composite_observable_spec.rb +41 -0
  64. data/spec/tailor/configuration/style_spec.rb +197 -0
  65. data/spec/tailor/configuration_spec.rb +52 -33
  66. data/spec/tailor/critic_spec.rb +7 -8
  67. data/spec/tailor/formatter_spec.rb +52 -0
  68. data/spec/tailor/lexed_line_spec.rb +236 -88
  69. data/spec/tailor/lexer_spec.rb +8 -63
  70. data/spec/tailor/problem_spec.rb +14 -46
  71. data/spec/tailor/reporter_spec.rb +8 -8
  72. data/spec/tailor/ruler_spec.rb +1 -1
  73. data/spec/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +132 -176
  74. data/spec/tailor/rulers/indentation_spaces_ruler_spec.rb +41 -33
  75. data/spec/tailor/rulers/{spaces_after_comma_spec.rb → spaces_after_comma_ruler_spec.rb} +5 -5
  76. data/spec/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +14 -14
  77. data/spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +1 -1
  78. data/spec/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +1 -1
  79. data/spec/tailor/version_spec.rb +1 -1
  80. data/spec/tailor_spec.rb +3 -1
  81. data/tailor.gemspec +11 -3
  82. data/uest.rb +9 -0
  83. metadata +66 -41
  84. data/features/step_definitions/spacing/commas_steps.rb +0 -14
@@ -1,13 +1,14 @@
1
1
  require_relative '../ruler'
2
- require_relative '../lexer_constants'
2
+ require_relative '../lexer/lexer_constants'
3
3
 
4
4
  class Tailor
5
5
  module Rulers
6
6
  class MaxCodeLinesInClassRuler < Tailor::Ruler
7
7
  include LexerConstants
8
8
 
9
- def initialize(config)
10
- super(config)
9
+ def initialize(config, options)
10
+ super(config, options)
11
+ add_lexer_observers(:ignored_nl, :kw, :nl)
11
12
  @class_start_lines = []
12
13
  @kw_start_lines = []
13
14
  @end_last_class = false
@@ -75,8 +76,11 @@ class Tailor
75
76
  # @param [Fixnum] column The column the potential problem is on.
76
77
  def measure(actual_count, lineno, column)
77
78
  if actual_count > @config
78
- @problems << Problem.new(:code_lines_in_class, lineno, column,
79
- { actual_count: actual_count, should_be_at: @config })
79
+ msg = "Class/module has #{actual_count} code lines, but "
80
+ msg << "should have no more than #{@config}."
81
+
82
+ @problems << Problem.new(problem_type, lineno, column, msg,
83
+ @options[:level])
80
84
  end
81
85
  end
82
86
  end
@@ -1,13 +1,14 @@
1
1
  require_relative '../ruler'
2
- require_relative '../lexer_constants'
2
+ require_relative '../lexer/lexer_constants'
3
3
 
4
4
  class Tailor
5
5
  module Rulers
6
6
  class MaxCodeLinesInMethodRuler < Tailor::Ruler
7
7
  include LexerConstants
8
8
 
9
- def initialize(config)
10
- super(config)
9
+ def initialize(config, options)
10
+ super(config, options)
11
+ add_lexer_observers(:ignored_nl, :kw, :nl)
11
12
  @method_start_lines = []
12
13
  @kw_start_lines = []
13
14
  @end_last_method = false
@@ -75,8 +76,11 @@ class Tailor
75
76
  # @param [Fixnum] column The column the potential problem is on.
76
77
  def measure(actual_count, lineno, column)
77
78
  if actual_count > @config
78
- @problems << Problem.new(:code_lines_in_method, lineno, column,
79
- { actual_count: actual_count, should_be_at: @config })
79
+ msg = "Method has #{actual_count} code lines, but "
80
+ msg << "should have no more than #{@config}."
81
+
82
+ @problems << Problem.new(problem_type, lineno, column, msg,
83
+ @options[:level])
80
84
  end
81
85
  end
82
86
  end
@@ -3,6 +3,11 @@ require_relative '../ruler'
3
3
  class Tailor
4
4
  module Rulers
5
5
  class MaxLineLengthRuler < Tailor::Ruler
6
+ def initialize(config, options)
7
+ super(config, options)
8
+ add_lexer_observers :ignored_nl, :nl
9
+ end
10
+
6
11
  def ignored_nl_update(lexed_line, lineno, column)
7
12
  log "<#{self.class}> Line length: #{lexed_line.line_length}"
8
13
  measure(lexed_line, lineno, column)
@@ -19,11 +24,11 @@ class Tailor
19
24
  # @param [Fixnum] column Column the potential problem is on
20
25
  def measure(lexed_line, lineno, column)
21
26
  if lexed_line.line_length > @config
22
- options = {
23
- actual_length: lexed_line.line_length,
24
- should_be_at: @config
25
- }
26
- @problems << Problem.new(:line_length, lineno, column, options)
27
+ msg = "Line is #{lexed_line.line_length} chars long, "
28
+ msg << "but should be #{@config}."
29
+
30
+ @problems << Problem.new(problem_type, lineno, column, msg,
31
+ @options[:level])
27
32
  end
28
33
  end
29
34
  end
@@ -8,8 +8,9 @@ class Tailor
8
8
  # * the char after it is a '\n'.
9
9
  # * it's at the end of a line, followed by a trailing comment.
10
10
  class SpacesAfterCommaRuler < Tailor::Ruler
11
- def initialize(config)
12
- super(config)
11
+ def initialize(config, options)
12
+ super(config, options)
13
+ add_lexer_observers :comma, :comment, :ignored_nl, :nl
13
14
  @comma_columns = []
14
15
  end
15
16
 
@@ -40,8 +41,11 @@ class Tailor
40
41
  # @param [Fixnum] column Column the potential problem is on.
41
42
  def measure(actual_spaces, lineno, column)
42
43
  if actual_spaces != @config
43
- @problems << Problem.new(:spaces_after_comma, lineno, column + 1,
44
- { actual_spaces: actual_spaces, should_have: @config })
44
+ msg = "Line has #{actual_spaces} space(s) after a comma, "
45
+ msg << "but should have #{@config}."
46
+
47
+ @problems << Problem.new(problem_type, lineno, column + 1, msg,
48
+ @options[:level])
45
49
  end
46
50
  end
47
51
 
@@ -67,6 +71,11 @@ class Tailor
67
71
  end
68
72
 
69
73
  second_next_event = lexed_line.at(event_index + 2)
74
+ if second_next_event.nil?
75
+ log "Second next event is nil."
76
+ next
77
+ end
78
+
70
79
  if second_next_event[1] == :on_comment
71
80
  log "Event + 2 is a comment."
72
81
  next
@@ -9,8 +9,9 @@ class Tailor
9
9
  # * the next char is a '}'
10
10
  # * it's at the end of a line, followed by a trailing comment.
11
11
  class SpacesAfterLbraceRuler < Tailor::Ruler
12
- def initialize(config)
13
- super(config)
12
+ def initialize(config, options)
13
+ super(config, options)
14
+ add_lexer_observers :comment, :ignored_nl, :lbrace, :nl
14
15
  @lbrace_columns = []
15
16
  end
16
17
 
@@ -41,8 +42,11 @@ class Tailor
41
42
  # @param [Fixnum] column Column the potential problem is on.
42
43
  def measure(actual_spaces, lineno, column)
43
44
  if actual_spaces != @config
44
- @problems << Problem.new(:spaces_after_lbrace, lineno, column + 1,
45
- { actual_spaces: actual_spaces, should_have: @config })
45
+ msg = "Line has #{actual_spaces} space(s) after a {, "
46
+ msg << "but should have #{@config}."
47
+
48
+ @problems << Problem.new(problem_type, lineno, column + 1, msg,
49
+ @options[:level])
46
50
  end
47
51
  end
48
52
 
@@ -9,8 +9,9 @@ class Tailor
9
9
  # * the char after it is a ']'.
10
10
  # * the char after it is space, then a '{'.
11
11
  class SpacesAfterLbracketRuler < Tailor::Ruler
12
- def initialize(config)
13
- super(config)
12
+ def initialize(config, options)
13
+ super(config, options)
14
+ add_lexer_observers :comment, :ignored_nl, :lbracket, :nl
14
15
  @lbracket_columns = []
15
16
  end
16
17
 
@@ -41,8 +42,11 @@ class Tailor
41
42
  # @param [Fixnum] column Column the problem was found on.
42
43
  def measure(actual_spaces, lineno, column)
43
44
  if actual_spaces != @config
44
- @problems << Problem.new(:spaces_after_lbracket, lineno, column + 1,
45
- { actual_spaces: actual_spaces, should_have: @config })
45
+ msg = "Line has #{actual_spaces} space(s) after a [, "
46
+ msg << "but should have #{@config}."
47
+
48
+ @problems << Problem.new(problem_type, lineno, column + 1, msg,
49
+ @options[:level])
46
50
  end
47
51
  end
48
52
 
@@ -3,8 +3,9 @@ require_relative '../ruler'
3
3
  class Tailor
4
4
  module Rulers
5
5
  class SpacesAfterLparenRuler < Tailor::Ruler
6
- def initialize(config)
7
- super(config)
6
+ def initialize(config, options)
7
+ super(config, options)
8
+ add_lexer_observers :comment, :ignored_nl, :lparen, :nl
8
9
  @lparen_columns = []
9
10
  end
10
11
 
@@ -35,8 +36,11 @@ class Tailor
35
36
  # @param [Fixnum] column Column the potential problem is on.
36
37
  def measure(actual_spaces, lineno, column)
37
38
  if actual_spaces != @config
38
- @problems << Problem.new(:spaces_after_lparen, lineno, column + 1,
39
- { actual_spaces: actual_spaces, should_have: @config })
39
+ msg = "Line has #{actual_spaces} space(s) after a (, "
40
+ msg << "but should have #{@config}."
41
+
42
+ @problems << Problem.new(problem_type, lineno, column + 1, msg,
43
+ @options[:level])
40
44
  end
41
45
  end
42
46
 
@@ -5,8 +5,9 @@ class Tailor
5
5
 
6
6
  # Checks for spaces before a ',' as given by +@config+.
7
7
  class SpacesBeforeCommaRuler < Tailor::Ruler
8
- def initialize(config)
9
- super(config)
8
+ def initialize(config, options)
9
+ super(config, options)
10
+ add_lexer_observers :comma, :comment, :ignored_nl, :nl
10
11
  @comma_columns = []
11
12
  end
12
13
 
@@ -29,8 +30,11 @@ class Tailor
29
30
  # @param [Fixnum] column Column the potential problem is on.
30
31
  def measure(actual_spaces, lineno, column)
31
32
  if actual_spaces != @config
32
- @problems << Problem.new(:spaces_before_comma, lineno, column - 1,
33
- { actual_spaces: actual_spaces, should_have: @config })
33
+ msg = "Line has #{actual_spaces} space(s) before a comma, "
34
+ msg << "but should have #{@config}."
35
+
36
+ @problems << Problem.new(problem_type, lineno, column - 1, msg,
37
+ @options[:level])
34
38
  end
35
39
  end
36
40
 
@@ -3,7 +3,7 @@ require_relative '../ruler'
3
3
  class Tailor
4
4
  module Rulers
5
5
 
6
- # Detects spaces before a '{' as given by +@config+. It skips checking
6
+ # Detects spaces before a +{+ as given by +@config+. It skips checking
7
7
  # when:
8
8
  # * it's the first char in the line.
9
9
  # * the char before it is a '#{'.
@@ -11,6 +11,10 @@ class Tailor
11
11
  # * the char before it is a '['.
12
12
  # * it's only preceded by spaces.
13
13
  class SpacesBeforeLbraceRuler < Tailor::Ruler
14
+ def initialize(config, options)
15
+ super(config, options)
16
+ add_lexer_observers :lbrace
17
+ end
14
18
 
15
19
  # Counts the spaces before the '{'.
16
20
  #
@@ -79,13 +83,16 @@ class Tailor
79
83
  # Checks to see if the counted spaces before an lbrace equals the value
80
84
  # at +@config+.
81
85
  #
82
- # @param [Fixnum] count The number of spaces before the lbrace.
86
+ # @param [Fixnum] actual_spaces The number of spaces before the lbrace.
83
87
  # @param [Fixnum] lineno Line the potential problem is on.
84
88
  # @param [Fixnum] column Column the potential problem is on.
85
- def measure(count, lineno, column)
86
- if count != @config
87
- @problems << Problem.new(:spaces_before_lbrace, lineno, column,
88
- { actual_spaces: count, should_have: @config })
89
+ def measure(actual_spaces, lineno, column)
90
+ if actual_spaces != @config
91
+ msg = "Line has #{actual_spaces} space(s) before a {, "
92
+ msg << "but should have #{@config}."
93
+
94
+ @problems << Problem.new(problem_type, lineno, column, msg,
95
+ @options[:level])
89
96
  end
90
97
  end
91
98
  end
@@ -3,14 +3,15 @@ require_relative '../ruler'
3
3
  class Tailor
4
4
  module Rulers
5
5
 
6
- # Checks for spaces before a '}' as given by +@config+. It skips checking
6
+ # Checks for spaces before a +}+ as given by +@config+. It skips checking
7
7
  # when:
8
8
  # * it's the first char in the line.
9
9
  # * it's the first char in the line, preceded by spaces.
10
10
  # * it's directly preceded by a '{'.
11
11
  class SpacesBeforeRbraceRuler < Tailor::Ruler
12
- def initialize(config)
13
- super(config)
12
+ def initialize(config, options)
13
+ super(config, options)
14
+ add_lexer_observers :embexpr_beg, :lbrace, :rbrace
14
15
  @lbrace_nesting = []
15
16
  end
16
17
 
@@ -57,13 +58,16 @@ class Tailor
57
58
  # Checks to see if the number of spaces before an rbrace equals the value
58
59
  # at +@config+.
59
60
  #
60
- # @param [Fixnum] count The number of spaces after the rbrace.
61
+ # @param [Fixnum] actual_spaces The number of spaces after the rbrace.
61
62
  # @param [Fixnum] lineno Line the problem was found on.
62
63
  # @param [Fixnum] column Column the problem was found on.
63
- def measure(count, lineno, column)
64
- if count != @config
65
- @problems << Problem.new(:spaces_before_rbrace, lineno, column,
66
- { actual_spaces: count, should_have: @config })
64
+ def measure(actual_spaces, lineno, column)
65
+ if actual_spaces != @config
66
+ msg = "Line has #{actual_spaces} space(s) before a }, "
67
+ msg << "but should have #{@config}."
68
+
69
+ @problems << Problem.new(problem_type, lineno, column, msg,
70
+ @options[:level])
67
71
  end
68
72
  end
69
73
 
@@ -9,6 +9,10 @@ class Tailor
9
9
  # * it's directly preceded by a '['.
10
10
  # * it's directly preceded by spaces, then a '['.
11
11
  class SpacesBeforeRbracketRuler < Tailor::Ruler
12
+ def initialize(config, options)
13
+ super(config, options)
14
+ add_lexer_observers :rbracket
15
+ end
12
16
 
13
17
  # @param [LexedLine] lexed_line
14
18
  # @param [Fixnum] column
@@ -36,13 +40,16 @@ class Tailor
36
40
  # Checks to see if the counted spaces before an rbracket equals the value
37
41
  # at +@config+.
38
42
  #
39
- # @param [Fixnum] count The number of spaces before the rbracket.
43
+ # @param [Fixnum] actual_spaces The number of spaces before the rbracket.
40
44
  # @param [Fixnum] lineno Line the potential problem is on.
41
45
  # @param [Fixnum] column Column the potential problem is on.
42
- def measure(count, lineno, column)
43
- if count != @config
44
- @problems << Problem.new(:spaces_before_rbracket, lineno, column,
45
- { actual_spaces: count, should_have: @config })
46
+ def measure(actual_spaces, lineno, column)
47
+ if actual_spaces != @config
48
+ msg = "Line has #{actual_spaces} space(s) before a ], "
49
+ msg << "but should have #{@config}."
50
+
51
+ @problems << Problem.new(problem_type, lineno, column, msg,
52
+ @options[:level])
46
53
  end
47
54
  end
48
55
 
@@ -3,12 +3,16 @@ require_relative '../ruler'
3
3
  class Tailor
4
4
  module Rulers
5
5
 
6
- # Checks for spaces before a ')' as given by +@config+. It skips checking
6
+ # Checks for spaces before a +)+ as given by +@config+. It skips checking
7
7
  # when:
8
8
  # * it's the first char in the line.
9
9
  # * it's directly preceded by a '('.
10
10
  # * it's directly preceded by spaces, then a '('.
11
11
  class SpacesBeforeRparenRuler < Tailor::Ruler
12
+ def initialize(config, options)
13
+ super(config, options)
14
+ add_lexer_observers :rparen
15
+ end
12
16
 
13
17
  # @param [LexedLine] lexed_line
14
18
  # @param [Fixnum] column
@@ -36,13 +40,16 @@ class Tailor
36
40
  # Checks to see if the counted spaces before an rparen equals the value
37
41
  # at +@config+.
38
42
  #
39
- # @param [Fixnum] count The number of spaces before the rparen.
43
+ # @param [Fixnum] actual_spaces The number of spaces before the rparen.
40
44
  # @param [Fixnum] lineno Line the potential problem is on.
41
45
  # @param [Fixnum] column Column the potential problem is on.
42
- def measure(count, lineno, column)
43
- if count != @config
44
- @problems << Problem.new(:spaces_before_rparen, lineno, column,
45
- { actual_spaces: count, should_have: @config })
46
+ def measure(actual_spaces, lineno, column)
47
+ if actual_spaces != @config
48
+ msg = "Line has #{actual_spaces} space(s) before a ), "
49
+ msg << "but should have #{@config}."
50
+
51
+ @problems << Problem.new(problem_type, lineno, column, msg,
52
+ @options[:level])
46
53
  end
47
54
  end
48
55
 
@@ -3,11 +3,12 @@ require_relative '../ruler'
3
3
  class Tailor
4
4
  module Rulers
5
5
 
6
- # Checks for spaces that exist between a '{' and '}' when there is only
6
+ # Checks for spaces that exist between a +{+ and +}+ when there is only
7
7
  # space in between them.
8
8
  class SpacesInEmptyBracesRuler < Tailor::Ruler
9
- def initialize(config)
10
- super(config)
9
+ def initialize(config, options)
10
+ super(config, options)
11
+ add_lexer_observers :embexpr_beg, :lbrace, :rbrace
11
12
  @lbrace_nesting = []
12
13
  end
13
14
 
@@ -54,18 +55,21 @@ class Tailor
54
55
  # Checks to see if the counted spaces between an lbrace and an rbrace
55
56
  # equals the value at +@config+.
56
57
  #
57
- # @param [Fixnum] count The number of spaces before the lbrace.
58
+ # @param [Fixnum] actual_spaces The number of spaces before the lbrace.
58
59
  # @param [Fixnum] lineno Line the potential problem is on.
59
60
  # @param [Fixnum] column Column the potential problem is on.
60
- def measure(count, lineno, column)
61
- if count != @config
62
- @problems << Problem.new(:spaces_in_empty_braces, lineno, column,
63
- { actual_spaces: count, should_have: @config })
61
+ def measure(actual_spaces, lineno, column)
62
+ if actual_spaces != @config
63
+ msg = "Line has #{actual_spaces} space(s) in between empty "
64
+ msg << "braces, but should have #{@config}."
65
+
66
+ @problems << Problem.new(problem_type, lineno, column, msg,
67
+ @options[:level])
64
68
  end
65
69
  end
66
70
 
67
71
  # This has to keep track of '{'s and only follow through with the check
68
- # if the '{' was an lbrace because Ripper doesn't scan the '}' of an
72
+ # if the +{+ was an lbrace because Ripper doesn't scan the +}+ of an
69
73
  # embedded expression (embexpr_end) as such.
70
74
  #
71
75
  # @param [Tailor::LexedLine] lexed_line
@@ -4,6 +4,10 @@ require_relative '../ruler'
4
4
  class Tailor
5
5
  module Rulers
6
6
  class TrailingNewlinesRuler < Tailor::Ruler
7
+ def initialize(config, options)
8
+ super(config, options)
9
+ add_lexer_observers :file_end
10
+ end
7
11
 
8
12
  # Checks to see if the number of newlines at the end of the file is not
9
13
  # equal to the value at +@config+.
@@ -14,10 +18,11 @@ class Tailor
14
18
  if trailing_newline_count != @config
15
19
  lineno = "<EOF>"
16
20
  column = "<EOF>"
17
- @problems << Problem.new(:trailing_newlines, lineno, column,
18
- { actual_trailing_newlines: trailing_newline_count,
19
- should_have: @config }
20
- )
21
+ msg = "File has #{trailing_newline_count} trailing "
22
+ msg << "newlines, but should have #{@config}."
23
+
24
+ @problems << Problem.new(problem_type, lineno, column, msg,
25
+ @options[:level])
21
26
  end
22
27
  end
23
28
 
@@ -28,7 +33,7 @@ class Tailor
28
33
  # final line won't ever get caught).
29
34
  #
30
35
  # @param [Fixnum] trailing_newline_count
31
- def file_update(trailing_newline_count)
36
+ def file_end_update(trailing_newline_count)
32
37
  measure(trailing_newline_count)
33
38
  end
34
39
  end