tailor 1.0.0.alpha2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.tailor +10 -2
- data/Gemfile.lock +2 -2
- data/History.rdoc +20 -0
- data/README.rdoc +176 -26
- data/features/configurable.feature +19 -39
- data/features/horizontal_spacing.feature +3 -2
- data/features/indentation.feature +2 -2
- data/features/indentation/bad_files_with_no_trailing_newline.feature +9 -8
- data/features/indentation/good_files_with_no_trailing_newline.feature +19 -6
- data/features/name_detection.feature +2 -2
- data/features/support/env.rb +0 -2
- data/features/support/file_cases/horizontal_spacing_cases.rb +5 -4
- data/features/support/file_cases/indentation_cases.rb +105 -54
- data/features/support/file_cases/naming_cases.rb +0 -1
- data/features/support/file_cases/vertical_spacing_cases.rb +0 -1
- data/features/support/legacy/bad_ternary_colon_spacing.rb +1 -1
- data/features/valid_ruby.feature +17 -0
- data/features/vertical_spacing.feature +40 -19
- data/lib/ext/string_ext.rb +12 -0
- data/lib/tailor/cli.rb +7 -5
- data/lib/tailor/cli/options.rb +13 -3
- data/lib/tailor/composite_observable.rb +17 -2
- data/lib/tailor/configuration.rb +83 -72
- data/lib/tailor/configuration/style.rb +85 -0
- data/lib/tailor/critic.rb +67 -117
- data/lib/tailor/formatter.rb +38 -0
- data/lib/tailor/formatters/text.rb +35 -10
- data/lib/tailor/lexed_line.rb +38 -5
- data/lib/tailor/lexer.rb +150 -14
- data/lib/tailor/{lexer_constants.rb → lexer/lexer_constants.rb} +9 -7
- data/lib/tailor/lexer/token.rb +6 -2
- data/lib/tailor/logger.rb +4 -0
- data/lib/tailor/problem.rb +8 -73
- data/lib/tailor/reporter.rb +1 -1
- data/lib/tailor/ruler.rb +67 -6
- data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +9 -1
- data/lib/tailor/rulers/allow_hard_tabs_ruler.rb +9 -1
- data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +38 -0
- data/lib/tailor/rulers/allow_screaming_snake_case_classes_ruler.rb +9 -2
- data/lib/tailor/rulers/allow_trailing_line_spaces_ruler.rb +10 -5
- data/lib/tailor/rulers/indentation_spaces_ruler.rb +93 -26
- data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +128 -84
- data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +9 -5
- data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +9 -5
- data/lib/tailor/rulers/max_line_length_ruler.rb +10 -5
- data/lib/tailor/rulers/spaces_after_comma_ruler.rb +13 -4
- data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_before_comma_ruler.rb +8 -4
- data/lib/tailor/rulers/spaces_before_lbrace_ruler.rb +13 -6
- data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +12 -8
- data/lib/tailor/rulers/spaces_before_rbracket_ruler.rb +12 -5
- data/lib/tailor/rulers/spaces_before_rparen_ruler.rb +13 -6
- data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +13 -9
- data/lib/tailor/rulers/trailing_newlines_ruler.rb +10 -5
- data/lib/tailor/tailorrc.erb +3 -3
- data/lib/tailor/version.rb +1 -1
- data/m.rb +15 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/tailor/cli_spec.rb +8 -9
- data/spec/tailor/composite_observable_spec.rb +41 -0
- data/spec/tailor/configuration/style_spec.rb +197 -0
- data/spec/tailor/configuration_spec.rb +52 -33
- data/spec/tailor/critic_spec.rb +7 -8
- data/spec/tailor/formatter_spec.rb +52 -0
- data/spec/tailor/lexed_line_spec.rb +236 -88
- data/spec/tailor/lexer_spec.rb +8 -63
- data/spec/tailor/problem_spec.rb +14 -46
- data/spec/tailor/reporter_spec.rb +8 -8
- data/spec/tailor/ruler_spec.rb +1 -1
- data/spec/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +132 -176
- data/spec/tailor/rulers/indentation_spaces_ruler_spec.rb +41 -33
- data/spec/tailor/rulers/{spaces_after_comma_spec.rb → spaces_after_comma_ruler_spec.rb} +5 -5
- data/spec/tailor/rulers/spaces_after_lbrace_ruler_spec.rb +14 -14
- data/spec/tailor/rulers/spaces_before_lbrace_ruler_spec.rb +1 -1
- data/spec/tailor/rulers/spaces_before_rbrace_ruler_spec.rb +1 -1
- data/spec/tailor/version_spec.rb +1 -1
- data/spec/tailor_spec.rb +3 -1
- data/tailor.gemspec +11 -3
- data/uest.rb +9 -0
- metadata +66 -41
- 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
|
-
|
79
|
-
|
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
|
-
|
79
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
44
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
39
|
-
|
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
|
-
|
33
|
-
|
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
|
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]
|
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(
|
86
|
-
if
|
87
|
-
|
88
|
-
|
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
|
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]
|
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(
|
64
|
-
if
|
65
|
-
|
66
|
-
|
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]
|
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(
|
43
|
-
if
|
44
|
-
|
45
|
-
|
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
|
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]
|
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(
|
43
|
-
if
|
44
|
-
|
45
|
-
|
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
|
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]
|
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(
|
61
|
-
if
|
62
|
-
|
63
|
-
|
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
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
36
|
+
def file_end_update(trailing_newline_count)
|
32
37
|
measure(trailing_newline_count)
|
33
38
|
end
|
34
39
|
end
|