rubocop 0.26.1 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +10 -6
- data/.travis.yml +2 -0
- data/CHANGELOG.md +30 -0
- data/README.md +9 -2
- data/assets/logo.png +0 -0
- data/assets/output.html.erb +68 -65
- data/config/default.yml +42 -7
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +32 -7
- data/lib/rubocop.rb +10 -2
- data/lib/rubocop/comment_config.rb +11 -17
- data/lib/rubocop/config.rb +20 -16
- data/lib/rubocop/config_loader.rb +8 -12
- data/lib/rubocop/cop/cop.rb +13 -12
- data/lib/rubocop/cop/lint/block_alignment.rb +4 -6
- data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +2 -3
- data/lib/rubocop/cop/lint/useless_setter_call.rb +2 -2
- data/lib/rubocop/cop/metrics/abc_size.rb +27 -0
- data/lib/rubocop/cop/metrics/block_nesting.rb +2 -4
- data/lib/rubocop/cop/metrics/class_length.rb +1 -1
- data/lib/rubocop/cop/metrics/line_length.rb +2 -5
- data/lib/rubocop/cop/metrics/method_length.rb +2 -2
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +24 -15
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +15 -2
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +63 -0
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/if_node.rb +3 -1
- data/lib/rubocop/cop/mixin/method_complexity.rb +3 -3
- data/lib/rubocop/cop/mixin/{on_method.rb → on_method_def.rb} +3 -3
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -2
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +2 -2
- data/lib/rubocop/cop/mixin/string_literals_help.rb +28 -0
- data/lib/rubocop/cop/rails/delegate.rb +2 -2
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +2 -2
- data/lib/rubocop/cop/style/accessor_method_name.rb +2 -2
- data/lib/rubocop/cop/style/align_hash.rb +16 -12
- data/lib/rubocop/cop/style/align_parameters.rb +1 -1
- data/lib/rubocop/cop/style/and_or.rb +14 -6
- data/lib/rubocop/cop/style/array_join.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +16 -8
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -30
- data/lib/rubocop/cop/style/case_indentation.rb +20 -12
- data/lib/rubocop/cop/style/collection_methods.rb +4 -4
- data/lib/rubocop/cop/style/colon_method_call.rb +9 -0
- data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
- data/lib/rubocop/cop/style/comment_indentation.rb +22 -22
- data/lib/rubocop/cop/style/def_with_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +6 -1
- data/lib/rubocop/cop/style/else_alignment.rb +93 -0
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_class_body.rb +34 -0
- data/lib/rubocop/cop/style/empty_lines_around_method_body.rb +37 -0
- data/lib/rubocop/cop/style/empty_lines_around_module_body.rb +30 -0
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +4 -4
- data/lib/rubocop/cop/style/indent_array.rb +2 -2
- data/lib/rubocop/cop/style/indent_hash.rb +17 -12
- data/lib/rubocop/cop/style/indentation_width.rb +27 -19
- data/lib/rubocop/cop/style/method_call_parentheses.rb +3 -3
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +1 -1
- data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -11
- data/lib/rubocop/cop/style/method_name.rb +1 -1
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +174 -0
- data/lib/rubocop/cop/style/non_nil_check.rb +12 -15
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +12 -17
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/predicate_name.rb +2 -2
- data/lib/rubocop/cop/style/redundant_begin.rb +2 -2
- data/lib/rubocop/cop/style/redundant_return.rb +3 -3
- data/lib/rubocop/cop/style/redundant_self.rb +3 -3
- data/lib/rubocop/cop/style/regexp_literal.rb +17 -13
- data/lib/rubocop/cop/style/rescue_modifier.rb +2 -2
- data/lib/rubocop/cop/style/single_line_methods.rb +7 -4
- data/lib/rubocop/cop/style/space_after_method_name.rb +2 -2
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +17 -11
- data/lib/rubocop/cop/style/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +17 -14
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +10 -6
- data/lib/rubocop/cop/style/string_literals.rb +13 -16
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +41 -0
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +3 -3
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/word_array.rb +23 -19
- data/lib/rubocop/cop/team.rb +13 -26
- data/lib/rubocop/cop/util.rb +5 -0
- data/lib/rubocop/cop/variable_force/locatable.rb +7 -13
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +9 -1
- data/lib/rubocop/formatter/html_formatter.rb +83 -55
- data/lib/rubocop/formatter/simple_text_formatter.rb +2 -2
- data/lib/rubocop/formatter/text_util.rb +25 -0
- data/lib/rubocop/options.rb +14 -7
- data/lib/rubocop/path_util.rb +11 -7
- data/lib/rubocop/runner.rb +7 -2
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.27.0.md +77 -0
- data/rubocop.gemspec +1 -1
- data/spec/fixtures/html_formatter/expected.html +495 -0
- data/spec/fixtures/html_formatter/project/app/controllers/application_controller.rb +5 -0
- data/spec/fixtures/html_formatter/project/app/controllers/books_controller.rb +74 -0
- data/spec/fixtures/html_formatter/project/app/models/book.rb +5 -0
- data/spec/rubocop/cli_spec.rb +56 -13
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +1 -1
- data/spec/rubocop/cop/metrics/abc_size_spec.rb +99 -0
- data/spec/rubocop/cop/rails/action_filter_spec.rb +1 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +23 -1
- data/spec/rubocop/cop/style/align_hash_spec.rb +13 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +44 -33
- data/spec/rubocop/cop/style/blocks_spec.rb +8 -0
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +9 -9
- data/spec/rubocop/cop/style/case_indentation_spec.rb +3 -2
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +5 -0
- data/spec/rubocop/cop/style/comment_indentation_spec.rb +6 -1
- data/spec/rubocop/cop/style/else_alignment_spec.rb +437 -0
- data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +75 -0
- data/spec/rubocop/cop/style/{empty_lines_around_body_spec.rb → empty_lines_around_method_body_spec.rb} +9 -50
- data/spec/rubocop/cop/style/empty_lines_around_module_body_spec.rb +79 -0
- data/spec/rubocop/cop/style/file_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/format_string_spec.rb +12 -0
- data/spec/rubocop/cop/style/indent_array_spec.rb +6 -1
- data/spec/rubocop/cop/style/indent_hash_spec.rb +2 -1
- data/spec/rubocop/cop/style/indentation_width_spec.rb +765 -722
- data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +414 -0
- data/spec/rubocop/cop/style/non_nil_check_spec.rb +86 -55
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +5 -1
- data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +2 -1
- data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +2 -1
- data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +63 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +2 -2
- data/spec/rubocop/cop/style/word_array_spec.rb +15 -1
- data/spec/rubocop/formatter/base_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +0 -1
- data/spec/rubocop/formatter/formatter_set_spec.rb +9 -0
- data/spec/rubocop/formatter/html_formatter_spec.rb +25 -122
- data/spec/rubocop/formatter/offense_count_formatter_spec.rb +0 -1
- data/spec/rubocop/runner_spec.rb +1 -1
- data/spec/spec_helper.rb +12 -130
- data/spec/support/cop_helper.rb +72 -0
- data/spec/support/coverage.rb +15 -0
- data/spec/support/{offenses_matcher.rb → custom_matchers.rb} +28 -0
- data/spec/support/jruby_workaround.rb +15 -0
- data/spec/support/{isolated_environment.rb → shared_contexts.rb} +19 -0
- metadata +49 -14
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +0 -75
- data/spec/support/shared_context.rb +0 -20
data/config/disabled.yml
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# These are all the cops that are disabled in the default configuration.
|
2
2
|
|
3
|
+
Style/CollectionMethods:
|
4
|
+
Description: 'Preferred collection methods.'
|
5
|
+
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#map-fine-select-reduce-size'
|
6
|
+
Enabled: false
|
7
|
+
|
3
8
|
Style/Encoding:
|
4
9
|
Description: 'Use UTF-8 as the source file encoding.'
|
5
10
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#utf-8'
|
data/config/enabled.yml
CHANGED
@@ -128,11 +128,6 @@ Style/ClassVars:
|
|
128
128
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-class-vars'
|
129
129
|
Enabled: true
|
130
130
|
|
131
|
-
Style/CollectionMethods:
|
132
|
-
Description: 'Preferred collection methods.'
|
133
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#map-fine-select-reduce-size'
|
134
|
-
Enabled: true
|
135
|
-
|
136
131
|
Style/ColonMethodCall:
|
137
132
|
Description: 'Do not use :: for method call.'
|
138
133
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#double-colons'
|
@@ -182,6 +177,10 @@ Style/EachWithObject:
|
|
182
177
|
Description: 'Prefer `each_with_object` over `inject` or `reduce`.'
|
183
178
|
Enabled: true
|
184
179
|
|
180
|
+
Style/ElseAlignment:
|
181
|
+
Description: 'Align elses and elsifs correctly.'
|
182
|
+
Enabled: true
|
183
|
+
|
185
184
|
Style/EmptyLineBetweenDefs:
|
186
185
|
Description: 'Use empty lines between defs.'
|
187
186
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods'
|
@@ -195,8 +194,16 @@ Style/EmptyLinesAroundAccessModifier:
|
|
195
194
|
Description: "Keep blank lines around access modifiers."
|
196
195
|
Enabled: true
|
197
196
|
|
198
|
-
Style/
|
199
|
-
Description: "Keeps track of empty lines around
|
197
|
+
Style/EmptyLinesAroundClassBody:
|
198
|
+
Description: "Keeps track of empty lines around class bodies."
|
199
|
+
Enabled: true
|
200
|
+
|
201
|
+
Style/EmptyLinesAroundModuleBody:
|
202
|
+
Description: "Keeps track of empty lines around module bodies."
|
203
|
+
Enabled: true
|
204
|
+
|
205
|
+
Style/EmptyLinesAroundMethodBody:
|
206
|
+
Description: "Keeps track of empty lines around method bodies."
|
200
207
|
Enabled: true
|
201
208
|
|
202
209
|
Style/EmptyLiteral:
|
@@ -349,6 +356,12 @@ Style/MultilineIfThen:
|
|
349
356
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-then'
|
350
357
|
Enabled: true
|
351
358
|
|
359
|
+
Style/MultilineOperationIndentation:
|
360
|
+
Description: >-
|
361
|
+
Checks indentation of binary operations that span more than
|
362
|
+
one line.
|
363
|
+
Enabled: true
|
364
|
+
|
352
365
|
Style/MultilineTernaryOperator:
|
353
366
|
Description: >-
|
354
367
|
Avoid multi-line ?: (the ternary operator);
|
@@ -620,6 +633,12 @@ Style/StringLiterals:
|
|
620
633
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-string-literals'
|
621
634
|
Enabled: true
|
622
635
|
|
636
|
+
Style/StringLiteralsInInterpolation:
|
637
|
+
Description: >-
|
638
|
+
Checks if uses of quotes inside expressions in interpolated
|
639
|
+
strings match the configured preference.
|
640
|
+
Enabled: true
|
641
|
+
|
623
642
|
Style/SymbolProc:
|
624
643
|
Description: 'Use symbols as procs instead of blocks when possible.'
|
625
644
|
Enabled: true
|
@@ -706,6 +725,12 @@ Style/WordArray:
|
|
706
725
|
|
707
726
|
#################### Metrics ################################
|
708
727
|
|
728
|
+
Metrics/AbcSize:
|
729
|
+
Description: >-
|
730
|
+
A calculated magnitude based on number of assignments,
|
731
|
+
branches, and conditions.
|
732
|
+
Enabled: true
|
733
|
+
|
709
734
|
Metrics/BlockNesting:
|
710
735
|
Description: 'Avoid excessive block nesting'
|
711
736
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
|
data/lib/rubocop.rb
CHANGED
@@ -46,10 +46,11 @@ require 'rubocop/cop/mixin/configurable_max'
|
|
46
46
|
require 'rubocop/cop/mixin/code_length'
|
47
47
|
require 'rubocop/cop/mixin/configurable_enforced_style'
|
48
48
|
require 'rubocop/cop/mixin/configurable_naming'
|
49
|
+
require 'rubocop/cop/mixin/empty_lines_around_body'
|
49
50
|
require 'rubocop/cop/mixin/end_keyword_alignment'
|
50
51
|
require 'rubocop/cop/mixin/if_node'
|
51
52
|
require 'rubocop/cop/mixin/negative_conditional'
|
52
|
-
require 'rubocop/cop/mixin/
|
53
|
+
require 'rubocop/cop/mixin/on_method_def'
|
53
54
|
require 'rubocop/cop/mixin/method_complexity'
|
54
55
|
require 'rubocop/cop/mixin/on_normal_if_unless'
|
55
56
|
require 'rubocop/cop/mixin/parser_diagnostic'
|
@@ -61,6 +62,7 @@ require 'rubocop/cop/mixin/space_after_punctuation'
|
|
61
62
|
require 'rubocop/cop/mixin/space_before_punctuation'
|
62
63
|
require 'rubocop/cop/mixin/statement_modifier'
|
63
64
|
require 'rubocop/cop/mixin/string_help'
|
65
|
+
require 'rubocop/cop/mixin/string_literals_help'
|
64
66
|
require 'rubocop/cop/mixin/unused_argument'
|
65
67
|
|
66
68
|
require 'rubocop/cop/lint/ambiguous_operator'
|
@@ -104,6 +106,7 @@ require 'rubocop/cop/lint/void'
|
|
104
106
|
require 'rubocop/cop/metrics/block_nesting'
|
105
107
|
require 'rubocop/cop/metrics/class_length'
|
106
108
|
require 'rubocop/cop/metrics/cyclomatic_complexity'
|
109
|
+
require 'rubocop/cop/metrics/abc_size'
|
107
110
|
require 'rubocop/cop/metrics/line_length'
|
108
111
|
require 'rubocop/cop/metrics/method_length'
|
109
112
|
require 'rubocop/cop/metrics/parameter_lists'
|
@@ -145,10 +148,13 @@ require 'rubocop/cop/style/documentation'
|
|
145
148
|
require 'rubocop/cop/style/dot_position'
|
146
149
|
require 'rubocop/cop/style/double_negation'
|
147
150
|
require 'rubocop/cop/style/each_with_object'
|
151
|
+
require 'rubocop/cop/style/else_alignment'
|
148
152
|
require 'rubocop/cop/style/empty_line_between_defs'
|
149
153
|
require 'rubocop/cop/style/empty_lines'
|
150
154
|
require 'rubocop/cop/style/empty_lines_around_access_modifier'
|
151
|
-
require 'rubocop/cop/style/
|
155
|
+
require 'rubocop/cop/style/empty_lines_around_class_body'
|
156
|
+
require 'rubocop/cop/style/empty_lines_around_method_body'
|
157
|
+
require 'rubocop/cop/style/empty_lines_around_module_body'
|
152
158
|
require 'rubocop/cop/style/empty_literal'
|
153
159
|
require 'rubocop/cop/style/encoding'
|
154
160
|
require 'rubocop/cop/style/end_block'
|
@@ -181,6 +187,7 @@ require 'rubocop/cop/style/module_function'
|
|
181
187
|
require 'rubocop/cop/style/multiline_block_chain'
|
182
188
|
require 'rubocop/cop/style/multiline_block_layout'
|
183
189
|
require 'rubocop/cop/style/multiline_if_then'
|
190
|
+
require 'rubocop/cop/style/multiline_operation_indentation'
|
184
191
|
require 'rubocop/cop/style/multiline_ternary_operator'
|
185
192
|
require 'rubocop/cop/style/negated_if'
|
186
193
|
require 'rubocop/cop/style/negated_while'
|
@@ -231,6 +238,7 @@ require 'rubocop/cop/style/space_inside_parens'
|
|
231
238
|
require 'rubocop/cop/style/space_inside_range_literal'
|
232
239
|
require 'rubocop/cop/style/special_global_vars'
|
233
240
|
require 'rubocop/cop/style/string_literals'
|
241
|
+
require 'rubocop/cop/style/string_literals_in_interpolation'
|
234
242
|
require 'rubocop/cop/style/symbol_array'
|
235
243
|
require 'rubocop/cop/style/symbol_proc'
|
236
244
|
require 'rubocop/cop/style/tab'
|
@@ -32,16 +32,12 @@ module RuboCop
|
|
32
32
|
|
33
33
|
each_mentioned_cop do |cop_name, disabled, line, single_line|
|
34
34
|
if single_line
|
35
|
-
|
36
|
-
|
35
|
+
disabled_line_ranges[cop_name] << (line..line) if disabled
|
36
|
+
elsif disabled
|
37
|
+
disablement_start_line_numbers[cop_name] = line
|
37
38
|
else
|
38
|
-
|
39
|
-
|
40
|
-
else
|
41
|
-
start_line = disablement_start_line_numbers.delete(cop_name)
|
42
|
-
next unless start_line
|
43
|
-
disabled_line_ranges[cop_name] << (start_line..line)
|
44
|
-
end
|
39
|
+
start_line = disablement_start_line_numbers.delete(cop_name)
|
40
|
+
disabled_line_ranges[cop_name] << (start_line..line) if start_line
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
@@ -53,8 +49,6 @@ module RuboCop
|
|
53
49
|
end
|
54
50
|
|
55
51
|
def each_mentioned_cop
|
56
|
-
all_cop_names = nil # For performance improvement
|
57
|
-
|
58
52
|
return if processed_source.comments.nil?
|
59
53
|
|
60
54
|
processed_source.comments.each do |comment|
|
@@ -63,12 +57,8 @@ module RuboCop
|
|
63
57
|
|
64
58
|
switch, cops_string = match.captures
|
65
59
|
|
66
|
-
|
67
|
-
all_cop_names
|
68
|
-
cop_names = all_cop_names
|
69
|
-
else
|
70
|
-
cop_names = cops_string.split(/,\s*/)
|
71
|
-
end
|
60
|
+
cop_names =
|
61
|
+
cops_string == 'all' ? all_cop_names : cops_string.split(/,\s*/)
|
72
62
|
|
73
63
|
disabled = (switch == 'disable')
|
74
64
|
comment_line_number = comment.loc.expression.line
|
@@ -82,6 +72,10 @@ module RuboCop
|
|
82
72
|
end
|
83
73
|
end
|
84
74
|
|
75
|
+
def all_cop_names
|
76
|
+
@all_cop_names ||= Cop::Cop.all.map(&:cop_name)
|
77
|
+
end
|
78
|
+
|
85
79
|
def comment_only_line?(line_number)
|
86
80
|
non_comment_token_line_numbers.none? do |non_comment_line_number|
|
87
81
|
non_comment_line_number == line_number
|
data/lib/rubocop/config.rb
CHANGED
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
|
39
39
|
def add_excludes_from_higher_level(highest_config)
|
40
40
|
return unless highest_config['AllCops'] &&
|
41
|
-
|
41
|
+
highest_config['AllCops']['Exclude']
|
42
42
|
|
43
43
|
self['AllCops'] ||= {}
|
44
44
|
excludes = self['AllCops']['Exclude'] ||= []
|
@@ -93,13 +93,11 @@ module RuboCop
|
|
93
93
|
# TODO: This should be a private method
|
94
94
|
def validate
|
95
95
|
# Don't validate RuboCop's own files. Avoids inifinite recursion.
|
96
|
-
return if
|
97
|
-
|
98
|
-
|
99
|
-
default_config = ConfigLoader.default_configuration
|
96
|
+
return if loaded_path.start_with?(File.join(ConfigLoader::RUBOCOP_HOME,
|
97
|
+
'config'))
|
100
98
|
|
101
99
|
valid_cop_names, invalid_cop_names = @hash.keys.partition do |key|
|
102
|
-
|
100
|
+
ConfigLoader.default_configuration.key?(key)
|
103
101
|
end
|
104
102
|
|
105
103
|
invalid_cop_names.each do |name|
|
@@ -107,16 +105,7 @@ module RuboCop
|
|
107
105
|
"unrecognized cop #{name} found in #{loaded_path || self}"
|
108
106
|
end
|
109
107
|
|
110
|
-
valid_cop_names
|
111
|
-
@hash[name].each_key do |param|
|
112
|
-
next if COMMON_PARAMS.include?(param) ||
|
113
|
-
default_config[name].key?(param)
|
114
|
-
|
115
|
-
fail ValidationError,
|
116
|
-
"unrecognized parameter #{name}:#{param} found " \
|
117
|
-
"in #{loaded_path || self}"
|
118
|
-
end
|
119
|
-
end
|
108
|
+
validate_parameter_names(valid_cop_names)
|
120
109
|
end
|
121
110
|
|
122
111
|
def file_to_include?(file)
|
@@ -156,5 +145,20 @@ module RuboCop
|
|
156
145
|
Dir.pwd
|
157
146
|
end
|
158
147
|
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def validate_parameter_names(valid_cop_names)
|
152
|
+
valid_cop_names.each do |name|
|
153
|
+
@hash[name].each_key do |param|
|
154
|
+
next if COMMON_PARAMS.include?(param) ||
|
155
|
+
ConfigLoader.default_configuration[name].key?(param)
|
156
|
+
|
157
|
+
fail ValidationError,
|
158
|
+
"unrecognized parameter #{name}:#{param} found " \
|
159
|
+
"in #{loaded_path || self}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
159
163
|
end
|
160
164
|
end
|
@@ -24,18 +24,14 @@ module RuboCop
|
|
24
24
|
|
25
25
|
def load_file(path)
|
26
26
|
path = File.absolute_path(path)
|
27
|
-
|
28
|
-
#
|
29
|
-
# Ruby
|
30
|
-
# files
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
hash = YAML.load_file(path) || {}
|
36
|
-
# Restore yamler for applications using RuboCop as a library.
|
37
|
-
YAML::ENGINE.yamler = original_yamler if original_yamler
|
38
|
-
|
27
|
+
yaml_code = IO.read(path)
|
28
|
+
# At one time, there was a problem with the psych YAML engine under
|
29
|
+
# Ruby 1.9.3. YAML.load_file would crash when reading empty .yml files
|
30
|
+
# or files that only contained comments and blank lines. This problem
|
31
|
+
# is not possible to reproduce now, but we want to avoid it in case
|
32
|
+
# it's still there. So we only load the YAML code if we find some real
|
33
|
+
# code in there.
|
34
|
+
hash = yaml_code =~ /^[A-Z]/i ? YAML.load(yaml_code) : {}
|
39
35
|
puts "configuration from #{path}" if debug?
|
40
36
|
|
41
37
|
resolve_inheritance(path, hash)
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -65,17 +65,18 @@ module RuboCop
|
|
65
65
|
end
|
66
66
|
|
67
67
|
case found_ns.size
|
68
|
-
when 0
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
68
|
+
when 0 then name # No namespace found. Deal with it later in caller.
|
69
|
+
when 1 then cop_name_with_namespace(name, origin, basename, found_ns[0])
|
70
|
+
else fail AmbiguousCopName, "`#{basename}` used in #{origin}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.cop_name_with_namespace(name, origin, basename, found_ns)
|
75
|
+
if name != basename && found_ns != File.dirname(name).to_sym
|
76
|
+
warn "#{origin}: #{name} has the wrong namespace - should be " \
|
77
|
+
"#{found_ns}"
|
78
78
|
end
|
79
|
+
"#{found_ns}/#{basename}"
|
79
80
|
end
|
80
81
|
|
81
82
|
def self.non_rails
|
@@ -208,9 +209,9 @@ module RuboCop
|
|
208
209
|
if Severity::NAMES.include?(severity.to_sym)
|
209
210
|
severity.to_sym
|
210
211
|
else
|
211
|
-
warn
|
212
|
+
warn("Warning: Invalid severity '#{severity}'. " +
|
212
213
|
"Valid severities are #{Severity::NAMES.join(', ')}."
|
213
|
-
.color(:red)
|
214
|
+
.color(:red))
|
214
215
|
end
|
215
216
|
end
|
216
217
|
end
|
@@ -130,7 +130,7 @@ module RuboCop
|
|
130
130
|
|
131
131
|
def alt_start_msg(match, start_loc, do_loc, indentation_of_do_line)
|
132
132
|
if start_loc.line == do_loc.line &&
|
133
|
-
|
133
|
+
start_loc.column == indentation_of_do_line
|
134
134
|
''
|
135
135
|
else
|
136
136
|
" or `#{match[0]}` at #{do_loc.line}, #{indentation_of_do_line}"
|
@@ -161,11 +161,9 @@ module RuboCop
|
|
161
161
|
delta = start_col - end_col
|
162
162
|
corrector.insert_before(node.loc.end, ' ' * delta)
|
163
163
|
elsif end_col > start_col
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
range = Parser::Source::Range.new(source, range_start, range_end)
|
164
|
+
range_start = starting_position_of_block_end + start_col - end_col
|
165
|
+
range = Parser::Source::Range.new(source, range_start,
|
166
|
+
starting_position_of_block_end)
|
169
167
|
corrector.remove(range)
|
170
168
|
end
|
171
169
|
end
|
@@ -17,12 +17,12 @@ module RuboCop
|
|
17
17
|
# private def foo
|
18
18
|
# end
|
19
19
|
class DefEndAlignment < Cop
|
20
|
-
include
|
20
|
+
include OnMethodDef
|
21
21
|
include EndKeywordAlignment
|
22
22
|
|
23
23
|
MSG = '`end` at %d, %d is not aligned with `%s` at %d, %d'
|
24
24
|
|
25
|
-
def
|
25
|
+
def on_method_def(node, _method_name, _args, _body)
|
26
26
|
check_offset_of_node(node)
|
27
27
|
end
|
28
28
|
|
@@ -24,7 +24,7 @@ module RuboCop
|
|
24
24
|
|
25
25
|
body_nodes.each do |child_node|
|
26
26
|
check_for_access_modifier(child_node) ||
|
27
|
-
|
27
|
+
check_for_instance_method(child_node)
|
28
28
|
end
|
29
29
|
|
30
30
|
add_offense_for_access_modifier
|
@@ -41,8 +41,7 @@ module RuboCop
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def check_for_instance_method(node)
|
44
|
-
return unless node.type == :def ||
|
45
|
-
node.type == :send
|
44
|
+
return unless node.type == :def || node.type == :send
|
46
45
|
|
47
46
|
@access_modifier_node = nil
|
48
47
|
end
|
@@ -13,7 +13,7 @@ module RuboCop
|
|
13
13
|
# x.attr = 5
|
14
14
|
# end
|
15
15
|
class UselessSetterCall < Cop
|
16
|
-
include
|
16
|
+
include OnMethodDef
|
17
17
|
|
18
18
|
MSG = 'Useless setter call to local variable `%s`.'
|
19
19
|
ASSIGNMENT_TYPES = [:lvasgn, :ivasgn, :cvasgn, :gvasgn].freeze
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
30
|
+
def on_method_def(_node, _method_name, _args, body)
|
31
31
|
return unless body
|
32
32
|
|
33
33
|
if body.type == :begin
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Metrics
|
6
|
+
# This cop checks that the ABC size of methods is not higher than the
|
7
|
+
# configured maximum. The ABC size is based on assignments, branches
|
8
|
+
# (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
|
9
|
+
class AbcSize < Cop
|
10
|
+
include MethodComplexity
|
11
|
+
|
12
|
+
MSG = 'Assignment Branch Condition size for %s is too high. [%.4g/%.4g]'
|
13
|
+
BRANCH_NODES = [:send]
|
14
|
+
CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def complexity(node)
|
19
|
+
a = node.each_node(ASGN_NODES).count
|
20
|
+
b = node.each_node(BRANCH_NODES).count
|
21
|
+
c = node.each_node(CONDITION_NODES).count
|
22
|
+
Math.sqrt(a**2 + b**2 + c**2).round(2)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|