rubocop 0.58.2 → 0.59.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +22 -7
- data/config/disabled.yml +33 -4
- data/config/enabled.yml +4 -11
- data/lib/rubocop.rb +5 -0
- data/lib/rubocop/ast/builder.rb +1 -0
- data/lib/rubocop/ast/node.rb +11 -33
- data/lib/rubocop/ast/node/block_node.rb +8 -1
- data/lib/rubocop/ast/node/defined_node.rb +13 -0
- data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +16 -5
- data/lib/rubocop/ast/node/mixin/method_identifier_predicates.rb +21 -0
- data/lib/rubocop/ast/node/send_node.rb +3 -12
- data/lib/rubocop/ast/traversal.rb +10 -0
- data/lib/rubocop/cli.rb +4 -1
- data/lib/rubocop/config.rb +21 -5
- data/lib/rubocop/config_loader.rb +2 -0
- data/lib/rubocop/config_loader_resolver.rb +3 -1
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -0
- data/lib/rubocop/cop/bundler/gem_comment.rb +64 -0
- data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -0
- data/lib/rubocop/cop/commissioner.rb +2 -0
- data/lib/rubocop/cop/cop.rb +3 -0
- data/lib/rubocop/cop/corrector.rb +2 -0
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +1 -0
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +2 -0
- data/lib/rubocop/cop/force.rb +1 -0
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -0
- data/lib/rubocop/cop/generator.rb +1 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/class_structure.rb +4 -0
- data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +5 -4
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +35 -0
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -0
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +5 -2
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -0
- data/lib/rubocop/cop/layout/end_of_line.rb +1 -0
- data/lib/rubocop/cop/layout/extra_spacing.rb +1 -0
- data/lib/rubocop/cop/layout/indent_array.rb +1 -0
- data/lib/rubocop/cop/layout/indent_heredoc.rb +3 -0
- data/lib/rubocop/cop/layout/indentation_width.rb +2 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -1
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +34 -11
- data/lib/rubocop/cop/layout/space_after_method_name.rb +1 -0
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +3 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -0
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +16 -8
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -0
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -0
- data/lib/rubocop/cop/layout/tab.rb +1 -0
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -0
- data/lib/rubocop/cop/lint/duplicate_methods.rb +9 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +1 -0
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +2 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +3 -6
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -0
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -0
- data/lib/rubocop/cop/lint/rescue_type.rb +1 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +2 -2
- data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -0
- data/lib/rubocop/cop/lint/script_permission.rb +1 -0
- data/lib/rubocop/cop/lint/shadowed_argument.rb +3 -0
- data/lib/rubocop/cop/lint/shadowed_exception.rb +2 -0
- data/lib/rubocop/cop/lint/unneeded_cop_disable_directive.rb +1 -0
- data/lib/rubocop/cop/lint/unneeded_cop_enable_directive.rb +1 -0
- data/lib/rubocop/cop/lint/unneeded_require_statement.rb +1 -0
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -0
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +3 -0
- data/lib/rubocop/cop/lint/void.rb +1 -0
- data/lib/rubocop/cop/message_annotator.rb +1 -0
- data/lib/rubocop/cop/metrics/block_length.rb +1 -0
- data/lib/rubocop/cop/metrics/block_nesting.rb +1 -0
- data/lib/rubocop/cop/metrics/line_length.rb +6 -1
- data/lib/rubocop/cop/metrics/method_length.rb +1 -0
- data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -0
- data/lib/rubocop/cop/mixin/classish_length.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -0
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +1 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +12 -6
- data/lib/rubocop/cop/mixin/empty_parameter.rb +1 -0
- data/lib/rubocop/cop/mixin/ignored_methods.rb +19 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +25 -1
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +5 -3
- data/lib/rubocop/cop/mixin/percent_literal.rb +2 -0
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +6 -1
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -0
- data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -0
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -0
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +2 -0
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -0
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -0
- data/lib/rubocop/cop/naming/file_name.rb +4 -1
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +1 -0
- data/lib/rubocop/cop/naming/uncommunicative_block_param_name.rb +1 -0
- data/lib/rubocop/cop/naming/uncommunicative_method_param_name.rb +1 -0
- data/lib/rubocop/cop/naming/variable_name.rb +1 -0
- data/lib/rubocop/cop/performance/case_when_splat.rb +11 -7
- data/lib/rubocop/cop/performance/casecmp.rb +33 -42
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +77 -0
- data/lib/rubocop/cop/performance/compare_with_block.rb +3 -0
- data/lib/rubocop/cop/performance/regexp_match.rb +1 -0
- data/lib/rubocop/cop/performance/sample.rb +2 -0
- data/lib/rubocop/cop/performance/size.rb +8 -2
- data/lib/rubocop/cop/performance/string_replacement.rb +1 -0
- data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -0
- data/lib/rubocop/cop/rails/bulk_change_table.rb +9 -2
- data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +1 -0
- data/lib/rubocop/cop/rails/delegate.rb +7 -2
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +1 -0
- data/lib/rubocop/cop/rails/find_each.rb +7 -2
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +1 -1
- data/lib/rubocop/cop/rails/http_status.rb +2 -0
- data/lib/rubocop/cop/rails/inverse_of.rb +4 -0
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +1 -0
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -0
- data/lib/rubocop/cop/rails/reversible_migration.rb +1 -0
- data/lib/rubocop/cop/rails/save_bang.rb +189 -38
- data/lib/rubocop/cop/rails/time_zone.rb +1 -0
- data/lib/rubocop/cop/security/eval.rb +1 -0
- data/lib/rubocop/cop/security/json_load.rb +2 -2
- data/lib/rubocop/cop/security/open.rb +6 -3
- data/lib/rubocop/cop/severity.rb +1 -0
- data/lib/rubocop/cop/style/and_or.rb +3 -3
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -0
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +2 -3
- data/lib/rubocop/cop/style/class_and_module_children.rb +3 -0
- data/lib/rubocop/cop/style/class_vars.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_definition.rb +1 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -0
- data/lib/rubocop/cop/style/conditional_assignment.rb +2 -0
- data/lib/rubocop/cop/style/copyright.rb +7 -2
- data/lib/rubocop/cop/style/date_time.rb +40 -7
- data/lib/rubocop/cop/style/double_negation.rb +1 -1
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -0
- data/lib/rubocop/cop/style/empty_else.rb +2 -0
- data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -0
- data/lib/rubocop/cop/style/eval_with_location.rb +2 -0
- data/lib/rubocop/cop/style/for.rb +56 -10
- data/lib/rubocop/cop/style/format_string_token.rb +1 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -0
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -0
- data/lib/rubocop/cop/style/lambda.rb +1 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +3 -5
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +3 -5
- data/lib/rubocop/cop/style/method_def_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/missing_else.rb +1 -0
- data/lib/rubocop/cop/style/multiline_memoization.rb +1 -0
- data/lib/rubocop/cop/style/multiline_method_signature.rb +65 -0
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +45 -5
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_predicate.rb +5 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
- data/lib/rubocop/cop/style/or_assignment.rb +2 -0
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/random_with_offset.rb +1 -0
- data/lib/rubocop/cop/style/redundant_begin.rb +13 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -0
- data/lib/rubocop/cop/style/redundant_parentheses.rb +6 -1
- data/lib/rubocop/cop/style/redundant_return.rb +1 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -0
- data/lib/rubocop/cop/style/rescue_standard_error.rb +1 -0
- data/lib/rubocop/cop/style/safe_navigation.rb +4 -0
- data/lib/rubocop/cop/style/semicolon.rb +4 -0
- data/lib/rubocop/cop/style/signal_exception.rb +1 -0
- data/lib/rubocop/cop/style/string_hash_keys.rb +1 -0
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -8
- data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -0
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -0
- data/lib/rubocop/cop/style/unneeded_condition.rb +13 -2
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +2 -0
- data/lib/rubocop/cop/style/word_array.rb +13 -1
- data/lib/rubocop/cop/team.rb +1 -0
- data/lib/rubocop/cop/variable_force.rb +5 -0
- data/lib/rubocop/cop/variable_force/assignment.rb +4 -0
- data/lib/rubocop/cop/variable_force/branch.rb +4 -0
- data/lib/rubocop/cop/variable_force/branchable.rb +2 -0
- data/lib/rubocop/cop/variable_force/scope.rb +6 -0
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -0
- data/lib/rubocop/file_finder.rb +2 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +4 -4
- data/lib/rubocop/formatter/file_list_formatter.rb +1 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -0
- data/lib/rubocop/options.rb +16 -0
- data/lib/rubocop/path_util.rb +16 -1
- data/lib/rubocop/processed_source.rb +4 -0
- data/lib/rubocop/remote_config.rb +6 -1
- data/lib/rubocop/result_cache.rb +1 -0
- data/lib/rubocop/rspec/cop_helper.rb +3 -5
- data/lib/rubocop/rspec/shared_examples.rb +1 -9
- data/lib/rubocop/runner.rb +4 -0
- data/lib/rubocop/target_finder.rb +2 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +7 -2
@@ -84,6 +84,27 @@ module RuboCop
|
|
84
84
|
def const_receiver?
|
85
85
|
receiver && receiver.const_type?
|
86
86
|
end
|
87
|
+
|
88
|
+
# Checks whether this is a negation method, i.e. `!` or keyword `not`.
|
89
|
+
#
|
90
|
+
# @return [Boolean] whether this method is a negation method
|
91
|
+
def negation_method?
|
92
|
+
receiver && method_name == :!
|
93
|
+
end
|
94
|
+
|
95
|
+
# Checks whether this is a prefix not method, e.g. `not foo`.
|
96
|
+
#
|
97
|
+
# @return [Boolean] whether this method is a prefix not
|
98
|
+
def prefix_not?
|
99
|
+
negation_method? && loc.selector.is?('not')
|
100
|
+
end
|
101
|
+
|
102
|
+
# Checks whether this is a prefix bang method, e.g. `!foo`.
|
103
|
+
#
|
104
|
+
# @return [Boolean] whether this method is a prefix bang
|
105
|
+
def prefix_bang?
|
106
|
+
negation_method? && loc.selector.is?('!')
|
107
|
+
end
|
87
108
|
end
|
88
109
|
end
|
89
110
|
end
|
@@ -8,29 +8,20 @@ module RuboCop
|
|
8
8
|
class SendNode < Node
|
9
9
|
include ParameterizedNode
|
10
10
|
include MethodDispatchNode
|
11
|
-
ARROW = '->'.freeze
|
12
|
-
|
13
|
-
# Checks whether this is a negation method, i.e. `!` or keyword `not`.
|
14
|
-
#
|
15
|
-
# @return [Boolean] whether this method is a negation method
|
16
|
-
def negation_method?
|
17
|
-
keyword_bang? || keyword_not?
|
18
|
-
end
|
19
11
|
|
20
12
|
# Checks whether this is a lambda. Some versions of parser parses
|
21
13
|
# non-literal lambdas as a method send.
|
22
14
|
#
|
23
15
|
# @return [Boolean] whether this method is a lambda
|
24
16
|
def lambda?
|
25
|
-
|
17
|
+
block_literal? && method?(:lambda)
|
26
18
|
end
|
27
19
|
|
28
20
|
# Checks whether this is a stabby lambda. e.g. `-> () {}`
|
29
21
|
#
|
30
|
-
# @return [Boolean] whether this method is a
|
22
|
+
# @return [Boolean] whether this method is a stabby lambda
|
31
23
|
def stabby_lambda?
|
32
|
-
selector
|
33
|
-
selector && selector.source == ARROW
|
24
|
+
loc.selector && loc.selector.source == '->'
|
34
25
|
end
|
35
26
|
end
|
36
27
|
end
|
@@ -9,6 +9,7 @@ module RuboCop
|
|
9
9
|
module Traversal
|
10
10
|
def walk(node)
|
11
11
|
return if node.nil?
|
12
|
+
|
12
13
|
send(:"on_#{node.type}", node)
|
13
14
|
nil
|
14
15
|
end
|
@@ -65,6 +66,7 @@ module RuboCop
|
|
65
66
|
|
66
67
|
def on_const(node)
|
67
68
|
return unless (child = node.children[0])
|
69
|
+
|
68
70
|
send(:"on_#{child.type}", child)
|
69
71
|
end
|
70
72
|
|
@@ -74,6 +76,7 @@ module RuboCop
|
|
74
76
|
send(:"on_#{child.type}", child)
|
75
77
|
end
|
76
78
|
return unless (child = children[2])
|
79
|
+
|
77
80
|
send(:"on_#{child.type}", child)
|
78
81
|
end
|
79
82
|
|
@@ -85,6 +88,7 @@ module RuboCop
|
|
85
88
|
send(:"on_#{child.type}", child)
|
86
89
|
end
|
87
90
|
return unless (child = children[2])
|
91
|
+
|
88
92
|
send(:"on_#{child.type}", child)
|
89
93
|
end
|
90
94
|
|
@@ -92,12 +96,14 @@ module RuboCop
|
|
92
96
|
children = node.children
|
93
97
|
on_args(children[1])
|
94
98
|
return unless (child = children[2])
|
99
|
+
|
95
100
|
send(:"on_#{child.type}", child)
|
96
101
|
end
|
97
102
|
|
98
103
|
def on_send(node)
|
99
104
|
node.children.each_with_index do |child, i|
|
100
105
|
next if i == 1
|
106
|
+
|
101
107
|
send(:"on_#{child.type}", child) if child
|
102
108
|
end
|
103
109
|
nil
|
@@ -119,6 +125,7 @@ module RuboCop
|
|
119
125
|
send(:"on_#{child.type}", child)
|
120
126
|
on_args(children[2])
|
121
127
|
return unless (child = children[3])
|
128
|
+
|
122
129
|
send(:"on_#{child.type}", child)
|
123
130
|
end
|
124
131
|
|
@@ -130,6 +137,7 @@ module RuboCop
|
|
130
137
|
send(:"on_#{child.type}", child)
|
131
138
|
end
|
132
139
|
return unless (child = children[2])
|
140
|
+
|
133
141
|
send(:"on_#{child.type}", child)
|
134
142
|
end
|
135
143
|
|
@@ -138,6 +146,7 @@ module RuboCop
|
|
138
146
|
child = children[0]
|
139
147
|
send(:"on_#{child.type}", child)
|
140
148
|
return unless (child = children[1])
|
149
|
+
|
141
150
|
send(:"on_#{child.type}", child)
|
142
151
|
end
|
143
152
|
|
@@ -151,6 +160,7 @@ module RuboCop
|
|
151
160
|
send(:"on_#{child.type}", child) # can be send, zsuper...
|
152
161
|
on_args(children[1])
|
153
162
|
return unless (child = children[2])
|
163
|
+
|
154
164
|
send(:"on_#{child.type}", child)
|
155
165
|
end
|
156
166
|
|
data/lib/rubocop/cli.rb
CHANGED
@@ -159,7 +159,9 @@ module RuboCop
|
|
159
159
|
display_error_summary(runner.errors)
|
160
160
|
maybe_print_corrected_source
|
161
161
|
|
162
|
-
|
162
|
+
all_pass_or_excluded = all_passed || @options[:auto_gen_config]
|
163
|
+
|
164
|
+
if all_pass_or_excluded && !runner.aborting? && runner.errors.empty?
|
163
165
|
STATUS_SUCCESS
|
164
166
|
else
|
165
167
|
STATUS_OFFENSES
|
@@ -277,6 +279,7 @@ module RuboCop
|
|
277
279
|
# So a delimiter is needed for tools to easily identify where the
|
278
280
|
# autocorrected source begins
|
279
281
|
return unless @options[:stdin] && @options[:auto_correct]
|
282
|
+
|
280
283
|
puts '=' * 20
|
281
284
|
print @options[:stdin]
|
282
285
|
end
|
data/lib/rubocop/config.rb
CHANGED
@@ -373,8 +373,20 @@ module RuboCop
|
|
373
373
|
absolute_file_path = File.expand_path(file)
|
374
374
|
|
375
375
|
patterns_to_include.any? do |pattern|
|
376
|
-
|
377
|
-
|
376
|
+
if block_given?
|
377
|
+
yield pattern, relative_file_path, absolute_file_path
|
378
|
+
else
|
379
|
+
match_path?(pattern, relative_file_path) ||
|
380
|
+
match_path?(pattern, absolute_file_path)
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
def allowed_camel_case_file?(file)
|
386
|
+
file_to_include?(file) do |pattern, relative_path, absolute_path|
|
387
|
+
pattern.to_s =~ /[A-Z]/ &&
|
388
|
+
(match_path?(pattern, relative_path) ||
|
389
|
+
match_path?(pattern, absolute_path))
|
378
390
|
end
|
379
391
|
end
|
380
392
|
|
@@ -396,11 +408,11 @@ module RuboCop
|
|
396
408
|
end
|
397
409
|
|
398
410
|
def patterns_to_include
|
399
|
-
for_all_cops['Include']
|
411
|
+
for_all_cops['Include'] || []
|
400
412
|
end
|
401
413
|
|
402
414
|
def patterns_to_exclude
|
403
|
-
for_all_cops['Exclude']
|
415
|
+
for_all_cops['Exclude'] || []
|
404
416
|
end
|
405
417
|
|
406
418
|
def path_relative_to_config(path)
|
@@ -483,6 +495,7 @@ module RuboCop
|
|
483
495
|
|
484
496
|
def validate_section_presence(name)
|
485
497
|
return unless key?(name) && self[name].nil?
|
498
|
+
|
486
499
|
raise ValidationError,
|
487
500
|
"empty section #{name} found in #{smart_loaded_path}"
|
488
501
|
end
|
@@ -546,6 +559,7 @@ module RuboCop
|
|
546
559
|
def obsolete_cops
|
547
560
|
OBSOLETE_COPS.map do |cop_name, message|
|
548
561
|
next unless key?(cop_name) || key?(Cop::Badge.parse(cop_name).cop_name)
|
562
|
+
|
549
563
|
message + "\n(obsolete configuration found in #{smart_loaded_path}," \
|
550
564
|
' please update it)'
|
551
565
|
end
|
@@ -615,7 +629,8 @@ module RuboCop
|
|
615
629
|
# "RUBY VERSION" line.
|
616
630
|
in_ruby_section ||= line.match(/^\s*RUBY\s*VERSION\s*$/)
|
617
631
|
next unless in_ruby_section
|
618
|
-
|
632
|
+
|
633
|
+
# We currently only allow this feature to work with MRI ruby. If jruby
|
619
634
|
# (or something else) is used by the project, it's lock file will have a
|
620
635
|
# line that looks like:
|
621
636
|
# RUBY VERSION
|
@@ -645,6 +660,7 @@ module RuboCop
|
|
645
660
|
|
646
661
|
def bundler_lock_file_path
|
647
662
|
return nil unless loaded_path
|
663
|
+
|
648
664
|
base_path = base_dir_for_path_parameters
|
649
665
|
['gems.locked', 'Gemfile.lock'].each do |file_name|
|
650
666
|
path = find_file_upwards(file_name, base_path)
|
@@ -95,6 +95,7 @@ module RuboCop
|
|
95
95
|
return if found_files.empty?
|
96
96
|
return if PathUtil.relative_path(found_files.last) ==
|
97
97
|
PathUtil.relative_path(config_file)
|
98
|
+
|
98
99
|
print 'AllCops/Exclude ' if debug?
|
99
100
|
config.add_excludes_from_higher_level(load_file(found_files.last))
|
100
101
|
end
|
@@ -129,6 +130,7 @@ module RuboCop
|
|
129
130
|
if File.exist?(DOTFILE)
|
130
131
|
files = Array(load_yaml_configuration(DOTFILE)['inherit_from'])
|
131
132
|
return if files.include?(AUTO_GENERATED_FILE)
|
133
|
+
|
132
134
|
files.unshift(AUTO_GENERATED_FILE)
|
133
135
|
file_string = "\n - " + files.join("\n - ") if files.size > 1
|
134
136
|
rubocop_yml_contents = IO.read(DOTFILE, encoding: Encoding::UTF_8)
|
@@ -23,6 +23,7 @@ module RuboCop
|
|
23
23
|
.reverse.each_with_index do |base_config, index|
|
24
24
|
base_config.each do |k, v|
|
25
25
|
next unless v.is_a?(Hash)
|
26
|
+
|
26
27
|
if hash.key?(k)
|
27
28
|
v = merge(v, hash[k],
|
28
29
|
cop_name: k, file: file, debug: debug,
|
@@ -51,7 +52,7 @@ module RuboCop
|
|
51
52
|
|
52
53
|
# Merges the given configuration with the default one. If
|
53
54
|
# AllCops:DisabledByDefault is true, it changes the Enabled params so that
|
54
|
-
# only cops from user configuration are enabled.
|
55
|
+
# only cops from user configuration are enabled. If
|
55
56
|
# AllCops::EnabledByDefault is true, it changes the Enabled params so that
|
56
57
|
# only cops explicitly disabled in user configuration are disabled.
|
57
58
|
def merge_with_default(config, config_file)
|
@@ -102,6 +103,7 @@ module RuboCop
|
|
102
103
|
return false if inherited_file.start_with?('..') # Legitimate override
|
103
104
|
return false if base_hash[key] == derived_hash[key] # Same value
|
104
105
|
return false if remote_file?(inherited_file) # Can't change
|
106
|
+
|
105
107
|
Gem.path.none? { |dir| inherited_file.start_with?(dir) } # Can change?
|
106
108
|
end
|
107
109
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Bundler
|
6
|
+
# Add a comment describing each gem in your Gemfile.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
#
|
11
|
+
# gem 'foo'
|
12
|
+
#
|
13
|
+
# # good
|
14
|
+
#
|
15
|
+
# # Helpers for the foo things.
|
16
|
+
# gem 'foo'
|
17
|
+
#
|
18
|
+
class GemComment < Cop
|
19
|
+
include DefNode
|
20
|
+
|
21
|
+
MSG = 'Missing gem description comment.'.freeze
|
22
|
+
|
23
|
+
def_node_matcher :gem_declaration?, '(send nil? :gem str ...)'
|
24
|
+
|
25
|
+
def on_send(node)
|
26
|
+
return unless gem_declaration?(node)
|
27
|
+
return if whitelisted_gem?(node)
|
28
|
+
return if commented?(node)
|
29
|
+
|
30
|
+
add_offense(node)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def commented?(node)
|
36
|
+
preceding_lines = preceding_lines(node)
|
37
|
+
preceding_comment?(node, preceding_lines.last)
|
38
|
+
end
|
39
|
+
|
40
|
+
# The args node1 & node2 may represent a RuboCop::AST::Node
|
41
|
+
# or a Parser::Source::Comment. Both respond to #loc.
|
42
|
+
def precede?(node1, node2)
|
43
|
+
node2.loc.line - node1.loc.line == 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def preceding_lines(node)
|
47
|
+
processed_source.ast_with_comments[node].select do |line|
|
48
|
+
line.loc.line < node.loc.line
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def preceding_comment?(node1, node2)
|
53
|
+
node1 && node2 && precede?(node2, node1) &&
|
54
|
+
comment_line?(node2.loc.expression.source)
|
55
|
+
end
|
56
|
+
|
57
|
+
def whitelisted_gem?(node)
|
58
|
+
whitelist = Array(cop_config['Whitelist'])
|
59
|
+
whitelist.include?(node.first_argument.value)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
|
35
35
|
def investigate(processed_source)
|
36
36
|
return if processed_source.blank?
|
37
|
+
|
37
38
|
gem_declarations(processed_source.ast)
|
38
39
|
.each_cons(2) do |previous, current|
|
39
40
|
next unless consecutive_lines(previous, current)
|
@@ -41,6 +42,7 @@ module RuboCop
|
|
41
42
|
gem_name(current),
|
42
43
|
gem_name(previous)
|
43
44
|
)
|
45
|
+
|
44
46
|
register_offense(previous, current)
|
45
47
|
end
|
46
48
|
end
|
@@ -29,6 +29,7 @@ module RuboCop
|
|
29
29
|
Parser::Meta::NODE_TYPES.each do |node_type|
|
30
30
|
method_name = :"on_#{node_type}"
|
31
31
|
next unless method_defined?(method_name)
|
32
|
+
|
32
33
|
define_method(method_name) do |node|
|
33
34
|
trigger_responding_cops(method_name, node)
|
34
35
|
super(node) unless NO_CHILD_NODES.include?(node_type)
|
@@ -105,6 +106,7 @@ module RuboCop
|
|
105
106
|
yield
|
106
107
|
rescue StandardError => e
|
107
108
|
raise e if @options[:raise_error]
|
109
|
+
|
108
110
|
if node
|
109
111
|
line = node.first_line
|
110
112
|
column = node.loc.column
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -152,6 +152,7 @@ module RuboCop
|
|
152
152
|
@corrected_nodes[node] = true
|
153
153
|
correction = autocorrect(node)
|
154
154
|
return :uncorrected unless correction
|
155
|
+
|
155
156
|
@corrections << correction
|
156
157
|
:corrected
|
157
158
|
end
|
@@ -204,6 +205,7 @@ module RuboCop
|
|
204
205
|
def file_name_matches_any?(file, parameter, default_result)
|
205
206
|
patterns = cop_config[parameter]
|
206
207
|
return default_result unless patterns
|
208
|
+
|
207
209
|
path = nil
|
208
210
|
patterns.any? do |pattern|
|
209
211
|
# Try to match the absolute path, as Exclude properties are absolute.
|
@@ -217,6 +219,7 @@ module RuboCop
|
|
217
219
|
|
218
220
|
def enabled_line?(line_number)
|
219
221
|
return true unless @processed_source
|
222
|
+
|
220
223
|
@processed_source.comment_config.cop_enabled_at_line?(self, line_number)
|
221
224
|
end
|
222
225
|
|
@@ -34,6 +34,7 @@ module RuboCop
|
|
34
34
|
@source_buffer = source_buffer
|
35
35
|
raise 'source_buffer should be a Parser::Source::Buffer' unless \
|
36
36
|
source_buffer.is_a? Parser::Source::Buffer
|
37
|
+
|
37
38
|
@corrections = corrections
|
38
39
|
@source_rewriter = Parser::Source::TreeRewriter.new(
|
39
40
|
source_buffer,
|
@@ -155,6 +156,7 @@ module RuboCop
|
|
155
156
|
# :nodoc:
|
156
157
|
def validate_range(range)
|
157
158
|
return if range.source_buffer == @source_buffer
|
159
|
+
|
158
160
|
unless range.source_buffer.is_a?(Parser::Source::Buffer)
|
159
161
|
# actually this should be enforced by parser gem
|
160
162
|
raise 'Corrector expected range source buffer to be a '\
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
|
37
37
|
def move_comment(eol_comment:, node:, corrector:)
|
38
38
|
return unless eol_comment
|
39
|
+
|
39
40
|
text = eol_comment.loc.expression.source
|
40
41
|
corrector.insert_before(node.source_range,
|
41
42
|
text + "\n" + (' ' * node.loc.keyword.column))
|
@@ -46,6 +47,7 @@ module RuboCop
|
|
46
47
|
|
47
48
|
def remove_semicolon(node, corrector)
|
48
49
|
return unless semicolon(node)
|
50
|
+
|
49
51
|
corrector.remove(semicolon(node).pos)
|
50
52
|
end
|
51
53
|
|
@@ -29,6 +29,7 @@ module RuboCop
|
|
29
29
|
corrector.remove(range)
|
30
30
|
end
|
31
31
|
return unless right_token.space_before?
|
32
|
+
|
32
33
|
range = side_space_range(range: right_token.pos, side: :left)
|
33
34
|
corrector.remove(range)
|
34
35
|
end
|
@@ -39,6 +40,7 @@ module RuboCop
|
|
39
40
|
corrector.insert_after(left_token.pos, ' ')
|
40
41
|
end
|
41
42
|
return if right_token.space_before?
|
43
|
+
|
42
44
|
corrector.insert_before(right_token.pos, ' ')
|
43
45
|
end
|
44
46
|
end
|