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
@@ -22,6 +22,7 @@ module RuboCop
|
|
22
22
|
|
23
23
|
def investigate(processed_source)
|
24
24
|
return if processed_source.blank?
|
25
|
+
|
25
26
|
@processed_source = processed_source
|
26
27
|
|
27
28
|
check_for_line_terminator_or_opener
|
@@ -29,6 +30,7 @@ module RuboCop
|
|
29
30
|
|
30
31
|
def on_begin(node)
|
31
32
|
return if cop_config['AllowAsExpressionSeparator']
|
33
|
+
|
32
34
|
exprs = node.children
|
33
35
|
|
34
36
|
return if exprs.size < 2
|
@@ -40,6 +42,7 @@ module RuboCop
|
|
40
42
|
# every line with more than 1 expression on it is an offense
|
41
43
|
lines.each do |line, expr_on_line|
|
42
44
|
next unless expr_on_line.size > 1
|
45
|
+
|
43
46
|
# TODO: Find the correct position of the semicolon. We don't know
|
44
47
|
# if the first semicolon on the line is a separator of
|
45
48
|
# expressions. It's just a guess.
|
@@ -50,6 +53,7 @@ module RuboCop
|
|
50
53
|
|
51
54
|
def autocorrect(range)
|
52
55
|
return unless range
|
56
|
+
|
53
57
|
->(corrector) { corrector.remove(range) }
|
54
58
|
end
|
55
59
|
|
@@ -13,6 +13,7 @@ module RuboCop
|
|
13
13
|
# something.map(&:upcase)
|
14
14
|
class SymbolProc < Cop
|
15
15
|
include RangeHelp
|
16
|
+
include IgnoredMethods
|
16
17
|
|
17
18
|
MSG = 'Pass `&:%<method>s` as an argument to `%<block_method>s` ' \
|
18
19
|
'instead of a block.'.freeze
|
@@ -120,14 +121,6 @@ module RuboCop
|
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
|
-
def ignored_methods
|
124
|
-
cop_config['IgnoredMethods']
|
125
|
-
end
|
126
|
-
|
127
|
-
def ignored_method?(name)
|
128
|
-
ignored_methods.include?(name.to_s)
|
129
|
-
end
|
130
|
-
|
131
124
|
def super?(node)
|
132
125
|
SUPER_TYPES.include?(node.type)
|
133
126
|
end
|
@@ -50,8 +50,7 @@ module RuboCop
|
|
50
50
|
elsif node.modifier_form?
|
51
51
|
corrector.replace(node.source_range, node.if_branch.source)
|
52
52
|
else
|
53
|
-
corrected =
|
54
|
-
else_source(node.else_branch)].join(' || ')
|
53
|
+
corrected = make_ternary_form(node)
|
55
54
|
|
56
55
|
corrector.replace(node.source_range, corrected)
|
57
56
|
end
|
@@ -70,6 +69,7 @@ module RuboCop
|
|
70
69
|
|
71
70
|
def range_of_offense(node)
|
72
71
|
return :expression unless node.ternary?
|
72
|
+
|
73
73
|
range_between(node.loc.question.begin_pos, node.loc.colon.end_pos)
|
74
74
|
end
|
75
75
|
|
@@ -94,6 +94,17 @@ module RuboCop
|
|
94
94
|
else_branch.modifier_form?
|
95
95
|
wrap_else ? "(#{else_branch.source})" : else_branch.source
|
96
96
|
end
|
97
|
+
|
98
|
+
def make_ternary_form(node)
|
99
|
+
ternary_form = [node.if_branch.source,
|
100
|
+
else_source(node.else_branch)].join(' || ')
|
101
|
+
|
102
|
+
if node.parent && node.parent.send_type?
|
103
|
+
"(#{ternary_form})"
|
104
|
+
else
|
105
|
+
ternary_form
|
106
|
+
end
|
107
|
+
end
|
97
108
|
end
|
98
109
|
end
|
99
110
|
end
|
@@ -32,6 +32,7 @@ module RuboCop
|
|
32
32
|
|
33
33
|
def on_dstr(node)
|
34
34
|
return unless string_literal?(node)
|
35
|
+
|
35
36
|
check(node)
|
36
37
|
end
|
37
38
|
|
@@ -40,6 +41,7 @@ module RuboCop
|
|
40
41
|
# will call `on_dstr` for the entire string and `on_str` for the
|
41
42
|
# non interpolated portion of the string
|
42
43
|
return unless string_literal?(node)
|
44
|
+
|
43
45
|
check(node)
|
44
46
|
end
|
45
47
|
|
@@ -81,12 +81,24 @@ module RuboCop
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def correct_bracketed(node)
|
84
|
-
words = node.children.map
|
84
|
+
words = node.children.map do |word|
|
85
|
+
if word.dstr_type?
|
86
|
+
string_literal = to_string_literal(word.source)
|
87
|
+
|
88
|
+
trim_string_interporation_escape_character(string_literal)
|
89
|
+
else
|
90
|
+
to_string_literal(word.children[0])
|
91
|
+
end
|
92
|
+
end
|
85
93
|
|
86
94
|
lambda do |corrector|
|
87
95
|
corrector.replace(node.source_range, "[#{words.join(', ')}]")
|
88
96
|
end
|
89
97
|
end
|
98
|
+
|
99
|
+
def trim_string_interporation_escape_character(str)
|
100
|
+
str.gsub(/\\\#{(.*?)\}/) { "\#{#{Regexp.last_match(1)}}" }
|
101
|
+
end
|
90
102
|
end
|
91
103
|
end
|
92
104
|
end
|
data/lib/rubocop/cop/team.rb
CHANGED
@@ -99,6 +99,7 @@ module RuboCop
|
|
99
99
|
def process_children(origin_node)
|
100
100
|
origin_node.each_child_node do |child_node|
|
101
101
|
next if scanned_node?(child_node)
|
102
|
+
|
102
103
|
process_node(child_node)
|
103
104
|
end
|
104
105
|
end
|
@@ -174,6 +175,7 @@ module RuboCop
|
|
174
175
|
|
175
176
|
variable_names.each do |name|
|
176
177
|
next if variable_table.variable_exist?(name)
|
178
|
+
|
177
179
|
variable_table.declare_variable(name, node)
|
178
180
|
end
|
179
181
|
|
@@ -272,6 +274,7 @@ module RuboCop
|
|
272
274
|
def process_zero_arity_super(node)
|
273
275
|
variable_table.accessible_variables.each do |variable|
|
274
276
|
next unless variable.method_argument?
|
277
|
+
|
275
278
|
variable.reference!(node)
|
276
279
|
end
|
277
280
|
end
|
@@ -315,10 +318,12 @@ module RuboCop
|
|
315
318
|
# Non related references which are caught in the above scan
|
316
319
|
# would be skipped here.
|
317
320
|
next unless variable
|
321
|
+
|
318
322
|
variable.assignments.each do |assignment|
|
319
323
|
next if assignment_nodes_in_loop.none? do |assignment_node|
|
320
324
|
assignment_node.equal?(assignment.node)
|
321
325
|
end
|
326
|
+
|
322
327
|
assignment.reference!(node)
|
323
328
|
end
|
324
329
|
end
|
@@ -48,11 +48,13 @@ module RuboCop
|
|
48
48
|
|
49
49
|
def operator_assignment?
|
50
50
|
return false unless meta_assignment_node
|
51
|
+
|
51
52
|
OPERATOR_ASSIGNMENT_TYPES.include?(meta_assignment_node.type)
|
52
53
|
end
|
53
54
|
|
54
55
|
def multiple_assignment?
|
55
56
|
return false unless meta_assignment_node
|
57
|
+
|
56
58
|
meta_assignment_node.type == MULTIPLE_ASSIGNMENT_TYPE
|
57
59
|
end
|
58
60
|
|
@@ -76,6 +78,7 @@ module RuboCop
|
|
76
78
|
return nil unless node.parent
|
77
79
|
return nil unless OPERATOR_ASSIGNMENT_TYPES.include?(node.parent.type)
|
78
80
|
return nil unless node.sibling_index.zero?
|
81
|
+
|
79
82
|
node.parent
|
80
83
|
end
|
81
84
|
|
@@ -84,6 +87,7 @@ module RuboCop
|
|
84
87
|
return nil unless grandparent_node
|
85
88
|
return nil unless grandparent_node.type == MULTIPLE_ASSIGNMENT_TYPE
|
86
89
|
return nil unless node.parent.type == MULTIPLE_LEFT_HAND_SIDE_TYPE
|
90
|
+
|
87
91
|
grandparent_node
|
88
92
|
end
|
89
93
|
end
|
@@ -9,8 +9,10 @@ module RuboCop
|
|
9
9
|
([target_node] + target_node.ancestors).each do |node|
|
10
10
|
return nil unless node.parent
|
11
11
|
return nil unless scope.include?(node)
|
12
|
+
|
12
13
|
klass = CLASSES_BY_TYPE[node.parent.type]
|
13
14
|
next unless klass
|
15
|
+
|
14
16
|
branch = klass.new(node, scope)
|
15
17
|
return branch if branch.branched?
|
16
18
|
end
|
@@ -74,6 +76,7 @@ module RuboCop
|
|
74
76
|
|
75
77
|
def parent
|
76
78
|
return @parent if instance_variable_defined?(:@parent)
|
79
|
+
|
77
80
|
@branch = Branch.of(control_node, scope: scope)
|
78
81
|
end
|
79
82
|
|
@@ -122,6 +125,7 @@ module RuboCop
|
|
122
125
|
|
123
126
|
def ==(other)
|
124
127
|
return false unless other
|
128
|
+
|
125
129
|
control_node.equal?(other.control_node) &&
|
126
130
|
child_node.equal?(other.child_node)
|
127
131
|
end
|
@@ -8,11 +8,13 @@ module RuboCop
|
|
8
8
|
module Branchable
|
9
9
|
def branch
|
10
10
|
return @branch if instance_variable_defined?(:@branch)
|
11
|
+
|
11
12
|
@branch = Branch.of(node, scope: scope)
|
12
13
|
end
|
13
14
|
|
14
15
|
def run_exclusively_with?(other)
|
15
16
|
return false if !branch || !other.branch
|
17
|
+
|
16
18
|
branch.exclusive_with?(other.branch)
|
17
19
|
end
|
18
20
|
end
|
@@ -61,6 +61,7 @@ module RuboCop
|
|
61
61
|
|
62
62
|
def each_node(&block)
|
63
63
|
return to_enum(__method__) unless block_given?
|
64
|
+
|
64
65
|
yield node if naked_top_level?
|
65
66
|
scan_node(node, &block)
|
66
67
|
end
|
@@ -70,6 +71,7 @@ module RuboCop
|
|
70
71
|
def scan_node(node, &block)
|
71
72
|
node.each_child_node do |child_node|
|
72
73
|
next unless include?(child_node)
|
74
|
+
|
73
75
|
yield child_node
|
74
76
|
scan_node(child_node, &block)
|
75
77
|
end
|
@@ -79,16 +81,20 @@ module RuboCop
|
|
79
81
|
return true if !naked_top_level? && target_node.equal?(node)
|
80
82
|
return true if ancestor_node?(target_node)
|
81
83
|
return false unless target_node.parent.equal?(node)
|
84
|
+
|
82
85
|
indices = OUTER_SCOPE_CHILD_INDICES[target_node.parent.type]
|
83
86
|
return false unless indices
|
87
|
+
|
84
88
|
indices.include?(target_node.sibling_index)
|
85
89
|
end
|
86
90
|
|
87
91
|
def belong_to_inner_scope?(target_node)
|
88
92
|
return false if !target_node.parent || target_node.parent.equal?(node)
|
89
93
|
return false unless SCOPE_TYPES.include?(target_node.parent.type)
|
94
|
+
|
90
95
|
indices = OUTER_SCOPE_CHILD_INDICES[target_node.parent.type]
|
91
96
|
return true unless indices
|
97
|
+
|
92
98
|
!indices.include?(target_node.sibling_index)
|
93
99
|
end
|
94
100
|
|
data/lib/rubocop/file_finder.rb
CHANGED
@@ -33,11 +33,13 @@ module RuboCop
|
|
33
33
|
def traverse_files_upwards(filename, start_dir, use_home)
|
34
34
|
Pathname.new(start_dir).expand_path.ascend do |dir|
|
35
35
|
break if FileFinder.root_level?(dir)
|
36
|
+
|
36
37
|
file = dir + filename
|
37
38
|
yield(file.to_s) if file.exist?
|
38
39
|
end
|
39
40
|
|
40
41
|
return unless use_home && ENV.key?('HOME')
|
42
|
+
|
41
43
|
file = File.join(Dir.home, filename)
|
42
44
|
yield(file) if File.exist?(file)
|
43
45
|
end
|
@@ -128,10 +128,10 @@ module RuboCop
|
|
128
128
|
|
129
129
|
params.each do |param|
|
130
130
|
value = default_cfg[param]
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
131
|
+
next unless value.is_a?(Array)
|
132
|
+
next if value.empty?
|
133
|
+
|
134
|
+
output_buffer.puts "# #{param}: #{value.join(', ')}"
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
data/lib/rubocop/options.rb
CHANGED
@@ -29,6 +29,7 @@ module RuboCop
|
|
29
29
|
if args.any?
|
30
30
|
raise OptionArgumentError, '-s/--stdin requires exactly one path.'
|
31
31
|
end
|
32
|
+
|
32
33
|
# We want the STDIN contents in @options[:stdin] and the file name in
|
33
34
|
# args to simplify the rest of the processing.
|
34
35
|
args = [@options[:stdin]]
|
@@ -136,6 +137,7 @@ module RuboCop
|
|
136
137
|
table) do |severity|
|
137
138
|
@options[:fail_level] = severity
|
138
139
|
end
|
140
|
+
option(opts, '--display-only-fail-level-offenses')
|
139
141
|
end
|
140
142
|
|
141
143
|
def add_flags_with_optional_args(opts)
|
@@ -251,10 +253,16 @@ module RuboCop
|
|
251
253
|
unless boolean_or_empty_cache?
|
252
254
|
raise OptionArgumentError, '-C/--cache argument must be true or false'
|
253
255
|
end
|
256
|
+
|
257
|
+
if display_only_fail_level_offenses_with_autocorrect?
|
258
|
+
raise OptionArgumentError, '--autocorrect can not be used with ' \
|
259
|
+
'--display-only-fail-level-offenses'
|
260
|
+
end
|
254
261
|
validate_auto_gen_config
|
255
262
|
validate_parallel
|
256
263
|
|
257
264
|
return if incompatible_options.size <= 1
|
265
|
+
|
258
266
|
raise OptionArgumentError, 'Incompatible cli options: ' \
|
259
267
|
"#{incompatible_options.inspect}"
|
260
268
|
end
|
@@ -304,6 +312,10 @@ module RuboCop
|
|
304
312
|
UnneededCopDisableDirective]).any?
|
305
313
|
end
|
306
314
|
|
315
|
+
def display_only_fail_level_offenses_with_autocorrect?
|
316
|
+
@options[:display_only_fail_level_offenses] && @options[:autocorrect]
|
317
|
+
end
|
318
|
+
|
307
319
|
def except_syntax?
|
308
320
|
@options.key?(:except) &&
|
309
321
|
(@options[:except] & %w[Lint/Syntax Syntax]).any?
|
@@ -319,6 +331,7 @@ module RuboCop
|
|
319
331
|
|
320
332
|
def validate_exclude_limit_option
|
321
333
|
return if @options[:exclude_limit] =~ /^\d+$/
|
334
|
+
|
322
335
|
# Emulate OptionParser's behavior to make failures consistent regardless
|
323
336
|
# of option order.
|
324
337
|
raise OptionParser::MissingArgument
|
@@ -378,6 +391,9 @@ module RuboCop
|
|
378
391
|
'if no format is specified.'],
|
379
392
|
fail_level: ['Minimum severity (A/R/C/W/E/F) for exit',
|
380
393
|
'with error code.'],
|
394
|
+
display_only_fail_level_offenses:
|
395
|
+
['Only output offense messages at',
|
396
|
+
'the specified --fail-level or above'],
|
381
397
|
show_cops: ['Shows the given cops, or all cops by',
|
382
398
|
'default, and their configurations for the',
|
383
399
|
'current directory.'],
|