rubocop 0.58.2 → 0.59.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.
- 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
@@ -129,6 +129,7 @@ module RuboCop
|
|
129
129
|
corrector.replace(block_method.source_range, 'lambda')
|
130
130
|
corrector.remove(args.source_range) if args.source_range
|
131
131
|
return if args.children.empty?
|
132
|
+
|
132
133
|
arg_str = " |#{lambda_arg_string(args)}|"
|
133
134
|
corrector.insert_after(node.loc.begin, arg_str)
|
134
135
|
end
|
@@ -40,6 +40,8 @@ module RuboCop
|
|
40
40
|
# bar :baz
|
41
41
|
# end
|
42
42
|
class MethodCallWithArgsParentheses < Cop
|
43
|
+
include IgnoredMethods
|
44
|
+
|
43
45
|
MSG = 'Use parentheses for method calls with arguments.'.freeze
|
44
46
|
|
45
47
|
def on_send(node)
|
@@ -66,11 +68,7 @@ module RuboCop
|
|
66
68
|
def ignored_method?(node)
|
67
69
|
node.operator_method? || node.setter_method? ||
|
68
70
|
ignore_macros? && node.macro? ||
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
def ignored_list
|
73
|
-
cop_config['IgnoredMethods'].map(&:to_sym)
|
71
|
+
super(node.method_name)
|
74
72
|
end
|
75
73
|
|
76
74
|
def ignore_macros?
|
@@ -12,6 +12,8 @@ module RuboCop
|
|
12
12
|
# # good
|
13
13
|
# object.some_method
|
14
14
|
class MethodCallWithoutArgsParentheses < Cop
|
15
|
+
include IgnoredMethods
|
16
|
+
|
15
17
|
MSG = 'Do not use parentheses for method calls with ' \
|
16
18
|
'no arguments.'.freeze
|
17
19
|
|
@@ -36,11 +38,7 @@ module RuboCop
|
|
36
38
|
private
|
37
39
|
|
38
40
|
def ineligible_node?(node)
|
39
|
-
node.camel_case_method? || node.implicit_call? || node.
|
40
|
-
end
|
41
|
-
|
42
|
-
def ignored_method?(method)
|
43
|
-
cop_config['IgnoredMethods'].to_a.map(&:to_sym).include?(method)
|
41
|
+
node.camel_case_method? || node.implicit_call? || node.prefix_not?
|
44
42
|
end
|
45
43
|
|
46
44
|
def same_name_assignment?(node)
|
@@ -60,8 +60,8 @@ module RuboCop
|
|
60
60
|
#
|
61
61
|
# @example EnforcedStyle: require_no_parentheses_except_multiline
|
62
62
|
# # The `require_no_parentheses_except_multiline` style prefers no
|
63
|
-
# #
|
64
|
-
# # but prefers
|
63
|
+
# # parentheses when method definition arguments fit on single line,
|
64
|
+
# # but prefers parentheses when arguments span multiple lines.
|
65
65
|
#
|
66
66
|
# # bad
|
67
67
|
# def bar(num1, num2)
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for method signatures that span multiple lines.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # good
|
11
|
+
#
|
12
|
+
# def foo(bar, baz)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # bad
|
16
|
+
#
|
17
|
+
# def foo(bar,
|
18
|
+
# baz)
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
class MultilineMethodSignature < Cop
|
22
|
+
MSG = 'Avoid multi-line method signatures.'.freeze
|
23
|
+
|
24
|
+
def on_def(node)
|
25
|
+
return if opening_line(node) == closing_line(node)
|
26
|
+
return if correction_exceeds_max_line_length?(node)
|
27
|
+
|
28
|
+
add_offense(node)
|
29
|
+
end
|
30
|
+
alias on_defs on_def
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def opening_line(node)
|
35
|
+
node.first_line
|
36
|
+
end
|
37
|
+
|
38
|
+
def closing_line(node)
|
39
|
+
if node.arguments?
|
40
|
+
node.arguments.last_line
|
41
|
+
else
|
42
|
+
node.first_line
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def correction_exceeds_max_line_length?(node)
|
47
|
+
indentation_width(node) + definition_width(node) > max_line_length
|
48
|
+
end
|
49
|
+
|
50
|
+
def indentation_width(node)
|
51
|
+
processed_source.line_indentation(node.loc.expression.line)
|
52
|
+
end
|
53
|
+
|
54
|
+
def definition_width(node)
|
55
|
+
node.loc.expression.source.squeeze.length -
|
56
|
+
node.loc.end.source.length
|
57
|
+
end
|
58
|
+
|
59
|
+
def max_line_length
|
60
|
+
config.for_cop('Metrics/LineLength')['Max'] || 80
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -3,9 +3,12 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
|
-
# This cop checks for comparison of something with nil using
|
6
|
+
# This cop checks for comparison of something with nil using `==` and
|
7
|
+
# `nil?`.
|
7
8
|
#
|
8
|
-
#
|
9
|
+
# Supported styles are: predicate, comparison.
|
10
|
+
#
|
11
|
+
# @example EnforcedStyle: predicate (default)
|
9
12
|
#
|
10
13
|
# # bad
|
11
14
|
# if x == nil
|
@@ -14,21 +17,58 @@ module RuboCop
|
|
14
17
|
# # good
|
15
18
|
# if x.nil?
|
16
19
|
# end
|
20
|
+
#
|
21
|
+
# @example EnforcedStyle: comparison
|
22
|
+
#
|
23
|
+
# # bad
|
24
|
+
# if x.nil?
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# # good
|
28
|
+
# if x == nil
|
29
|
+
# end
|
30
|
+
#
|
17
31
|
class NilComparison < Cop
|
18
|
-
|
32
|
+
include ConfigurableEnforcedStyle
|
33
|
+
|
34
|
+
PREDICATE_MSG = 'Prefer the use of the `nil?` predicate.'.freeze
|
35
|
+
EXPLICIT_MSG = 'Prefer the use of the `==` comparison.'.freeze
|
19
36
|
|
20
37
|
def_node_matcher :nil_comparison?, '(send _ {:== :===} nil)'
|
38
|
+
def_node_matcher :nil_check?, '(send _ :nil?)'
|
21
39
|
|
22
40
|
def on_send(node)
|
23
|
-
|
41
|
+
style_check?(node) do
|
24
42
|
add_offense(node, location: :selector)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
28
46
|
def autocorrect(node)
|
29
|
-
new_code =
|
47
|
+
new_code = if prefer_comparison?
|
48
|
+
node.source.sub('.nil?', ' == nil')
|
49
|
+
else
|
50
|
+
node.source.sub(/\s*={2,3}\s*nil/, '.nil?')
|
51
|
+
end
|
30
52
|
->(corrector) { corrector.replace(node.source_range, new_code) }
|
31
53
|
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def message(_node)
|
58
|
+
prefer_comparison? ? EXPLICIT_MSG : PREDICATE_MSG
|
59
|
+
end
|
60
|
+
|
61
|
+
def style_check?(node, &block)
|
62
|
+
if prefer_comparison?
|
63
|
+
nil_check?(node, &block)
|
64
|
+
else
|
65
|
+
nil_comparison?(node, &block)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def prefer_comparison?
|
70
|
+
style == :comparison
|
71
|
+
end
|
32
72
|
end
|
33
73
|
end
|
34
74
|
end
|
@@ -43,6 +43,7 @@ module RuboCop
|
|
43
43
|
# bar.baz > 0
|
44
44
|
class NumericPredicate < Cop
|
45
45
|
include ConfigurableEnforcedStyle
|
46
|
+
include IgnoredMethods
|
46
47
|
|
47
48
|
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
|
48
49
|
|
@@ -53,6 +54,10 @@ module RuboCop
|
|
53
54
|
}.freeze
|
54
55
|
|
55
56
|
def on_send(node)
|
57
|
+
return if node.each_ancestor(:send, :block).any? do |ancestor|
|
58
|
+
ignored_method?(ancestor.method_name)
|
59
|
+
end
|
60
|
+
|
56
61
|
numeric, replacement = check(node)
|
57
62
|
|
58
63
|
return unless numeric
|
@@ -30,7 +30,7 @@ module RuboCop
|
|
30
30
|
include ConfigurableEnforcedStyle
|
31
31
|
|
32
32
|
LOWER_CASE_Q_MSG = 'Do not use `%Q` unless interpolation is ' \
|
33
|
-
'needed.
|
33
|
+
'needed. Use `%q`.'.freeze
|
34
34
|
UPPER_CASE_Q_MSG = 'Use `%Q` instead of `%q`.'.freeze
|
35
35
|
|
36
36
|
def on_str(node)
|
@@ -44,6 +44,16 @@ module RuboCop
|
|
44
44
|
# rescue => ex
|
45
45
|
# anything
|
46
46
|
# end
|
47
|
+
#
|
48
|
+
# # good
|
49
|
+
# # Stabby lambdas don't support implicit `begin` in `do-end` blocks.
|
50
|
+
# -> do
|
51
|
+
# begin
|
52
|
+
# foo
|
53
|
+
# rescue Bar
|
54
|
+
# baz
|
55
|
+
# end
|
56
|
+
# end
|
47
57
|
class RedundantBegin < Cop
|
48
58
|
MSG = 'Redundant `begin` block detected.'.freeze
|
49
59
|
|
@@ -54,7 +64,10 @@ module RuboCop
|
|
54
64
|
|
55
65
|
def on_block(node)
|
56
66
|
return if target_ruby_version < 2.5
|
67
|
+
|
68
|
+
return if node.send_node.stabby_lambda?
|
57
69
|
return if node.braces?
|
70
|
+
|
58
71
|
check(node)
|
59
72
|
end
|
60
73
|
|
@@ -28,6 +28,7 @@ module RuboCop
|
|
28
28
|
|
29
29
|
def on_begin(node)
|
30
30
|
return if !parentheses?(node) || parens_allowed?(node)
|
31
|
+
|
31
32
|
check(node)
|
32
33
|
end
|
33
34
|
|
@@ -63,8 +64,10 @@ module RuboCop
|
|
63
64
|
|
64
65
|
def allowed_multiple_expression?(node)
|
65
66
|
return false if node.children.one?
|
67
|
+
|
66
68
|
ancestor = node.ancestors.first
|
67
69
|
return false unless ancestor
|
70
|
+
|
68
71
|
!ancestor.begin_type? && !ancestor.def_type? && !ancestor.block_type?
|
69
72
|
end
|
70
73
|
|
@@ -89,6 +92,7 @@ module RuboCop
|
|
89
92
|
end
|
90
93
|
return offense(begin_node, 'a variable') if node.variable?
|
91
94
|
return offense(begin_node, 'a constant') if node.const_type?
|
95
|
+
|
92
96
|
check_send(begin_node, node) if node.send_type?
|
93
97
|
end
|
94
98
|
|
@@ -157,6 +161,7 @@ module RuboCop
|
|
157
161
|
|
158
162
|
siblings = begin_node.parent && begin_node.parent.children
|
159
163
|
return false if siblings.nil?
|
164
|
+
|
160
165
|
next_sibling = siblings[begin_node.sibling_index + 1]
|
161
166
|
base_value = node.children.first
|
162
167
|
|
@@ -178,7 +183,7 @@ module RuboCop
|
|
178
183
|
|
179
184
|
def method_call_with_redundant_parentheses?(node)
|
180
185
|
return false unless node.send_type?
|
181
|
-
return false if node.
|
186
|
+
return false if node.prefix_not?
|
182
187
|
return false if range_end?(node)
|
183
188
|
|
184
189
|
send_node, args = method_node_and_args(node)
|
@@ -88,6 +88,7 @@ module RuboCop
|
|
88
88
|
|
89
89
|
def on_if(node)
|
90
90
|
return if allowed_if_condition?(node)
|
91
|
+
|
91
92
|
check_node(node)
|
92
93
|
end
|
93
94
|
|
@@ -97,6 +98,7 @@ module RuboCop
|
|
97
98
|
|
98
99
|
def check_node(node)
|
99
100
|
return if target_ruby_version < 2.3
|
101
|
+
|
100
102
|
checked_variable, receiver, method_chain, method = extract_parts(node)
|
101
103
|
return unless receiver == checked_variable
|
102
104
|
# method is already a method call so this is actually checking for a
|
@@ -176,12 +178,14 @@ module RuboCop
|
|
176
178
|
end
|
177
179
|
|
178
180
|
return receiver if receiver == checked_variable
|
181
|
+
|
179
182
|
find_matching_receiver_invocation(receiver, checked_variable)
|
180
183
|
end
|
181
184
|
|
182
185
|
def chain_size(method_chain, method)
|
183
186
|
method.each_ancestor(:send).inject(0) do |total, ancestor|
|
184
187
|
break total + 1 if ancestor == method_chain
|
188
|
+
|
185
189
|
total + 1
|
186
190
|
end
|
187
191
|
end
|