rubocop 0.46.0 → 0.47.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/LICENSE.txt +1 -1
- data/README.md +77 -2
- data/config/default.yml +151 -74
- data/config/disabled.yml +9 -0
- data/config/enabled.yml +49 -9
- data/lib/rubocop.rb +36 -8
- data/lib/rubocop/ast/builder.rb +59 -0
- data/lib/rubocop/ast/node.rb +607 -0
- data/lib/rubocop/ast/node/array_node.rb +45 -0
- data/lib/rubocop/ast/node/case_node.rb +63 -0
- data/lib/rubocop/ast/node/for_node.rb +53 -0
- data/lib/rubocop/ast/node/hash_node.rb +102 -0
- data/lib/rubocop/ast/node/if_node.rb +136 -0
- data/lib/rubocop/ast/node/keyword_splat_node.rb +45 -0
- data/lib/rubocop/ast/node/mixin/conditional_node.rb +45 -0
- data/lib/rubocop/ast/node/mixin/hash_element_node.rb +125 -0
- data/lib/rubocop/ast/node/mixin/modifier_node.rb +17 -0
- data/lib/rubocop/ast/node/pair_node.rb +64 -0
- data/lib/rubocop/ast/node/until_node.rb +43 -0
- data/lib/rubocop/ast/node/when_node.rb +61 -0
- data/lib/rubocop/ast/node/while_node.rb +43 -0
- data/lib/rubocop/ast/sexp.rb +16 -0
- data/lib/rubocop/{ast_node → ast}/traversal.rb +1 -1
- data/lib/rubocop/cli.rb +18 -14
- data/lib/rubocop/comment_config.rb +1 -3
- data/lib/rubocop/config.rb +93 -35
- data/lib/rubocop/config_loader.rb +1 -1
- data/lib/rubocop/cop/badge.rb +73 -0
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +43 -3
- data/lib/rubocop/cop/commissioner.rb +17 -6
- data/lib/rubocop/cop/cop.rb +25 -112
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +9 -4
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +7 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +18 -4
- data/lib/rubocop/cop/lint/block_alignment.rb +40 -9
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +14 -0
- data/lib/rubocop/cop/lint/condition_position.rb +14 -16
- data/lib/rubocop/cop/lint/debugger.rb +28 -0
- data/lib/rubocop/cop/lint/def_end_alignment.rb +21 -1
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +13 -1
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +26 -22
- data/lib/rubocop/cop/lint/duplicate_methods.rb +15 -1
- data/lib/rubocop/cop/lint/duplicated_key.rb +16 -8
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +9 -0
- data/lib/rubocop/cop/lint/else_layout.rb +26 -29
- data/lib/rubocop/cop/lint/empty_ensure.rb +38 -0
- data/lib/rubocop/cop/lint/empty_expression.rb +11 -1
- data/lib/rubocop/cop/lint/empty_interpolation.rb +8 -0
- data/lib/rubocop/cop/lint/empty_when.rb +14 -16
- data/lib/rubocop/cop/lint/end_alignment.rb +48 -28
- data/lib/rubocop/cop/lint/end_in_method.rb +23 -0
- data/lib/rubocop/cop/lint/ensure_return.rb +21 -0
- data/lib/rubocop/cop/lint/float_out_of_range.rb +5 -0
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +29 -4
- data/lib/rubocop/cop/lint/handle_exceptions.rb +40 -0
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +7 -2
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +11 -2
- data/lib/rubocop/cop/lint/invalid_character_literal.rb +3 -0
- data/lib/rubocop/cop/lint/literal_in_condition.rb +34 -36
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +8 -0
- data/lib/rubocop/cop/lint/loop.rb +36 -0
- data/lib/rubocop/cop/lint/multiple_compare.rb +46 -0
- data/lib/rubocop/cop/lint/nested_method_definition.rb +22 -0
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +5 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +8 -0
- data/lib/rubocop/cop/lint/percent_string_array.rb +27 -13
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +14 -4
- data/lib/rubocop/cop/lint/rand_one.rb +7 -3
- data/lib/rubocop/cop/lint/require_parentheses.rb +20 -19
- data/lib/rubocop/cop/lint/rescue_exception.rb +20 -0
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +66 -0
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +24 -0
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +8 -0
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +24 -0
- data/lib/rubocop/cop/lint/unified_integer.rb +5 -0
- data/lib/rubocop/cop/lint/unneeded_disable.rb +2 -2
- data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +5 -0
- data/lib/rubocop/cop/lint/unreachable_code.rb +17 -0
- data/lib/rubocop/cop/lint/unused_block_argument.rb +2 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +10 -0
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +28 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +18 -0
- data/lib/rubocop/cop/lint/useless_comparison.rb +3 -1
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +16 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +16 -4
- data/lib/rubocop/cop/lint/void.rb +52 -0
- data/lib/rubocop/cop/message_annotator.rb +102 -0
- data/lib/rubocop/cop/metrics/block_length.rb +6 -0
- data/lib/rubocop/cop/metrics/block_nesting.rb +17 -5
- data/lib/rubocop/cop/metrics/line_length.rb +11 -4
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -2
- data/lib/rubocop/cop/mixin/array_syntax.rb +2 -11
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +12 -5
- data/lib/rubocop/cop/mixin/configurable_formatting.rb +48 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +3 -3
- data/lib/rubocop/cop/mixin/configurable_naming.rb +5 -33
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +6 -47
- data/lib/rubocop/cop/mixin/documentation_comment.rb +7 -1
- data/lib/rubocop/cop/mixin/duplication.rb +46 -0
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +14 -11
- data/lib/rubocop/cop/mixin/hash_alignment.rb +114 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -3
- data/lib/rubocop/cop/mixin/negative_conditional.rb +21 -7
- data/lib/rubocop/cop/mixin/on_method_def.rb +14 -0
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +1 -24
- data/lib/rubocop/cop/mixin/statement_modifier.rb +8 -13
- data/lib/rubocop/cop/mixin/target_ruby_version.rb +16 -0
- data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -3
- data/lib/rubocop/cop/offense.rb +1 -1
- data/lib/rubocop/cop/performance/case_when_splat.rb +56 -59
- data/lib/rubocop/cop/performance/detect.rb +2 -2
- data/lib/rubocop/cop/performance/flat_map.rb +3 -3
- data/lib/rubocop/cop/performance/redundant_merge.rb +3 -6
- data/lib/rubocop/cop/performance/regexp_match.rb +201 -0
- data/lib/rubocop/cop/rails/delegate.rb +2 -2
- data/lib/rubocop/cop/rails/delegate_allow_blank.rb +10 -19
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +12 -40
- data/lib/rubocop/cop/rails/file_path.rb +80 -0
- data/lib/rubocop/cop/rails/find_each.rb +5 -14
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +30 -24
- data/lib/rubocop/cop/rails/not_null_column.rb +23 -0
- data/lib/rubocop/cop/rails/reversible_migration.rb +217 -0
- data/lib/rubocop/cop/rails/safe_navigation.rb +4 -2
- data/lib/rubocop/cop/rails/skips_model_validations.rb +46 -0
- data/lib/rubocop/cop/rails/time_zone.rb +1 -1
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +7 -5
- data/lib/rubocop/cop/registry.rb +170 -0
- data/lib/rubocop/cop/{lint → security}/eval.rb +7 -1
- data/lib/rubocop/cop/security/marshal_load.rb +33 -0
- data/lib/rubocop/cop/security/yaml_load.rb +37 -0
- data/lib/rubocop/cop/style/align_hash.rb +138 -169
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +10 -15
- data/lib/rubocop/cop/style/case_indentation.rb +36 -27
- data/lib/rubocop/cop/style/conditional_assignment.rb +64 -47
- data/lib/rubocop/cop/style/each_with_object.rb +4 -1
- data/lib/rubocop/cop/style/else_alignment.rb +14 -20
- data/lib/rubocop/cop/style/empty_case_condition.rb +16 -25
- data/lib/rubocop/cop/style/empty_else.rb +20 -22
- data/lib/rubocop/cop/style/empty_literal.rb +4 -4
- data/lib/rubocop/cop/style/empty_method.rb +12 -6
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/file_name.rb +24 -4
- data/lib/rubocop/cop/style/first_method_argument_line_break.rb +1 -1
- data/lib/rubocop/cop/style/format_string.rb +17 -48
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +40 -11
- data/lib/rubocop/cop/style/guard_clause.rb +11 -17
- data/lib/rubocop/cop/style/hash_syntax.rb +24 -42
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +40 -28
- data/lib/rubocop/cop/style/if_inside_else.rb +6 -9
- data/lib/rubocop/cop/style/if_unless_modifier.rb +16 -25
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +3 -9
- data/lib/rubocop/cop/style/indent_array.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +29 -60
- data/lib/rubocop/cop/style/infinite_loop.rb +21 -22
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +86 -0
- data/lib/rubocop/cop/style/{method_call_parentheses.rb → method_call_without_args_parentheses.rb} +8 -1
- data/lib/rubocop/cop/style/missing_else.rb +40 -14
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +5 -15
- data/lib/rubocop/cop/style/multiline_if_then.rb +14 -8
- data/lib/rubocop/cop/style/multiline_method_call_indentation.rb +3 -3
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -5
- data/lib/rubocop/cop/style/mutable_constant.rb +3 -2
- data/lib/rubocop/cop/style/negated_if.rb +3 -19
- data/lib/rubocop/cop/style/negated_while.rb +2 -17
- data/lib/rubocop/cop/style/nested_modifier.rb +16 -43
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +3 -5
- data/lib/rubocop/cop/style/next.rb +23 -21
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -3
- data/lib/rubocop/cop/style/not.rb +1 -3
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +12 -22
- data/lib/rubocop/cop/style/option_hash.rb +4 -15
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -3
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +8 -12
- data/lib/rubocop/cop/style/percent_q_literals.rb +15 -12
- data/lib/rubocop/cop/style/redundant_freeze.rb +3 -2
- data/lib/rubocop/cop/style/redundant_parentheses.rb +27 -4
- data/lib/rubocop/cop/style/redundant_return.rb +4 -8
- data/lib/rubocop/cop/style/safe_navigation.rb +13 -6
- data/lib/rubocop/cop/style/space_after_colon.rb +2 -4
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/style/space_around_operators.rb +15 -13
- data/lib/rubocop/cop/style/string_methods.rb +1 -3
- data/lib/rubocop/cop/style/symbol_array.rb +1 -5
- data/lib/rubocop/cop/style/ternary_parentheses.rb +5 -6
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +2 -5
- data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +1 -1
- data/lib/rubocop/cop/style/unless_else.rb +1 -5
- data/lib/rubocop/cop/style/when_then.rb +4 -2
- data/lib/rubocop/cop/style/while_until_do.rb +9 -13
- data/lib/rubocop/cop/style/while_until_modifier.rb +12 -11
- data/lib/rubocop/cop/style/word_array.rb +5 -9
- data/lib/rubocop/cop/team.rb +16 -15
- data/lib/rubocop/cop/util.rb +13 -3
- data/lib/rubocop/formatter/clang_style_formatter.rb +2 -2
- data/lib/rubocop/formatter/disabled_config_formatter.rb +2 -1
- data/lib/rubocop/magic_comment.rb +196 -0
- data/lib/rubocop/options.rb +5 -4
- data/lib/rubocop/processed_source.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +9 -0
- data/lib/rubocop/rspec/shared_examples.rb +1 -1
- data/lib/rubocop/runner.rb +7 -2
- data/lib/rubocop/version.rb +1 -1
- metadata +41 -14
- data/lib/rubocop/ast_node.rb +0 -624
- data/lib/rubocop/ast_node/builder.rb +0 -30
- data/lib/rubocop/ast_node/sexp.rb +0 -13
- data/lib/rubocop/cop/mixin/hash_node.rb +0 -14
- data/lib/rubocop/cop/mixin/if_node.rb +0 -42
@@ -7,14 +7,19 @@ module RuboCop
|
|
7
7
|
# method invocation without parentheses.
|
8
8
|
#
|
9
9
|
# @example
|
10
|
-
#
|
10
|
+
#
|
11
|
+
# # bad
|
11
12
|
#
|
12
13
|
# # The `*` is interpreted as a splat operator but it could possibly be
|
13
|
-
# # a `*` method invocation (i.e. `do_something.*(
|
14
|
-
# do_something *
|
14
|
+
# # a `*` method invocation (i.e. `do_something.*(some_array)`).
|
15
|
+
# do_something *some_array
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
#
|
19
|
+
# # good
|
15
20
|
#
|
16
21
|
# # With parentheses, there's no ambiguity.
|
17
|
-
# do_something(*
|
22
|
+
# do_something(*some_array)
|
18
23
|
class AmbiguousOperator < Cop
|
19
24
|
include ParserDiagnostic
|
20
25
|
|
@@ -7,11 +7,18 @@ module RuboCop
|
|
7
7
|
# a method invocation without parentheses.
|
8
8
|
#
|
9
9
|
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
#
|
10
13
|
# # This is interpreted as a method invocation with a regexp literal,
|
11
14
|
# # but it could possibly be `/` method invocations.
|
12
15
|
# # (i.e. `do_something./(pattern)./(i)`)
|
13
16
|
# do_something /pattern/i
|
14
17
|
#
|
18
|
+
# @example
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
#
|
15
22
|
# # With parentheses, there's no ambiguity.
|
16
23
|
# do_something(/pattern/i)
|
17
24
|
class AmbiguousRegexpLiteral < Cop
|
@@ -5,6 +5,22 @@ module RuboCop
|
|
5
5
|
module Lint
|
6
6
|
# This cop checks for assignments in the conditions of
|
7
7
|
# if/while/until.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
#
|
13
|
+
# if some_var = true
|
14
|
+
# do_something
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
#
|
21
|
+
# if some_var == true
|
22
|
+
# do_something
|
23
|
+
# end
|
8
24
|
class AssignmentInCondition < Cop
|
9
25
|
include SafeAssignment
|
10
26
|
|
@@ -26,11 +42,9 @@ module RuboCop
|
|
26
42
|
private
|
27
43
|
|
28
44
|
def check(node)
|
29
|
-
|
45
|
+
return if node.condition.block_type?
|
30
46
|
|
31
|
-
|
32
|
-
|
33
|
-
traverse_node(condition, ASGN_TYPES) do |asgn_node|
|
47
|
+
traverse_node(node.condition, ASGN_TYPES) do |asgn_node|
|
34
48
|
next :skip_children if skip_children?(asgn_node)
|
35
49
|
next if allowed_construct?(asgn_node)
|
36
50
|
|
@@ -6,8 +6,8 @@ module RuboCop
|
|
6
6
|
# This cop checks whether the end keywords are aligned properly for do
|
7
7
|
# end blocks.
|
8
8
|
#
|
9
|
-
# Three modes are supported through the `
|
10
|
-
# parameter:
|
9
|
+
# Three modes are supported through the `EnforcedStyleAlignWith`
|
10
|
+
# configuration parameter:
|
11
11
|
#
|
12
12
|
# `start_of_block` : the `end` shall be aligned with the
|
13
13
|
# start of the line where the `do` appeared.
|
@@ -20,18 +20,40 @@ module RuboCop
|
|
20
20
|
#
|
21
21
|
# @example
|
22
22
|
#
|
23
|
-
# #
|
23
|
+
# # bad
|
24
|
+
#
|
25
|
+
# foo.bar
|
26
|
+
# .each do
|
27
|
+
# baz
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
#
|
32
|
+
# # EnforcedStyleAlignWith: either (default)
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
#
|
24
36
|
# variable = lambda do |i|
|
25
37
|
# i
|
26
38
|
# end
|
27
39
|
#
|
28
|
-
#
|
40
|
+
# @example
|
41
|
+
#
|
42
|
+
# # EnforcedStyleAlignWith: start_of_block
|
43
|
+
#
|
44
|
+
# # good
|
45
|
+
#
|
29
46
|
# foo.bar
|
30
47
|
# .each do
|
31
48
|
# baz
|
32
49
|
# end
|
33
50
|
#
|
34
|
-
#
|
51
|
+
# @example
|
52
|
+
#
|
53
|
+
# # EnforcedStyleAlignWith: start_of_line
|
54
|
+
#
|
55
|
+
# # good
|
56
|
+
#
|
35
57
|
# foo.bar
|
36
58
|
# .each do
|
37
59
|
# baz
|
@@ -54,8 +76,8 @@ module RuboCop
|
|
54
76
|
check_block_alignment(start_for_block_node(node), node)
|
55
77
|
end
|
56
78
|
|
57
|
-
def
|
58
|
-
'
|
79
|
+
def style_parameter_name
|
80
|
+
'EnforcedStyleAlignWith'
|
59
81
|
end
|
60
82
|
|
61
83
|
private
|
@@ -93,10 +115,19 @@ module RuboCop
|
|
93
115
|
compute_do_source_line_column(block_node, end_loc)
|
94
116
|
return unless do_source_line_column
|
95
117
|
|
96
|
-
|
118
|
+
register_offense(
|
119
|
+
block_node,
|
120
|
+
start_loc,
|
121
|
+
end_loc,
|
122
|
+
do_source_line_column
|
123
|
+
)
|
97
124
|
end
|
98
125
|
|
99
|
-
def
|
126
|
+
def register_offense(block_node,
|
127
|
+
start_loc,
|
128
|
+
end_loc,
|
129
|
+
do_source_line_column)
|
130
|
+
|
100
131
|
error_source_line_column = if style == :start_of_block
|
101
132
|
do_source_line_column
|
102
133
|
else
|
@@ -9,27 +9,41 @@ module RuboCop
|
|
9
9
|
# This cop mirrors a warning produced by MRI since 2.2.
|
10
10
|
#
|
11
11
|
# @example
|
12
|
+
#
|
12
13
|
# # bad
|
14
|
+
#
|
13
15
|
# def bake(pie: pie)
|
14
16
|
# pie.heat_up
|
15
17
|
# end
|
16
18
|
#
|
19
|
+
# @example
|
20
|
+
#
|
17
21
|
# # good
|
22
|
+
#
|
18
23
|
# def bake(pie:)
|
19
24
|
# pie.refrigerate
|
20
25
|
# end
|
21
26
|
#
|
27
|
+
# @example
|
28
|
+
#
|
22
29
|
# # good
|
30
|
+
#
|
23
31
|
# def bake(pie: self.pie)
|
24
32
|
# pie.feed_to(user)
|
25
33
|
# end
|
26
34
|
#
|
35
|
+
# @example
|
36
|
+
#
|
27
37
|
# # bad
|
38
|
+
#
|
28
39
|
# def cook(dry_ingredients = dry_ingredients)
|
29
40
|
# dry_ingredients.reduce(&:+)
|
30
41
|
# end
|
31
42
|
#
|
43
|
+
# @example
|
44
|
+
#
|
32
45
|
# # good
|
46
|
+
#
|
33
47
|
# def cook(dry_ingredients = self.dry_ingredients)
|
34
48
|
# dry_ingredients.combine
|
35
49
|
# end
|
@@ -8,15 +8,25 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
#
|
11
|
+
# # bad
|
12
|
+
#
|
11
13
|
# if
|
12
14
|
# some_condition
|
13
15
|
# do_something
|
14
16
|
# end
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
#
|
22
|
+
# if some_condition
|
23
|
+
# do_something
|
24
|
+
# end
|
15
25
|
class ConditionPosition < Cop
|
16
|
-
|
26
|
+
MSG = 'Place the condition on the same line as `%s`.'.freeze
|
17
27
|
|
18
28
|
def on_if(node)
|
19
|
-
return if ternary?
|
29
|
+
return if node.ternary?
|
20
30
|
|
21
31
|
check(node)
|
22
32
|
end
|
@@ -32,21 +42,9 @@ module RuboCop
|
|
32
42
|
private
|
33
43
|
|
34
44
|
def check(node)
|
35
|
-
return if
|
36
|
-
|
37
|
-
condition, = *node
|
38
|
-
return unless on_different_line?(node.loc.keyword.line,
|
39
|
-
condition.source_range.line)
|
40
|
-
|
41
|
-
add_offense(condition, :expression, message(node.loc.keyword.source))
|
42
|
-
end
|
43
|
-
|
44
|
-
def message(keyword)
|
45
|
-
"Place the condition on the same line as `#{keyword}`."
|
46
|
-
end
|
45
|
+
return if node.modifier_form? || node.single_line_condition?
|
47
46
|
|
48
|
-
|
49
|
-
keyword_line != cond_line
|
47
|
+
add_offense(node.condition, :expression, format(MSG, node.keyword))
|
50
48
|
end
|
51
49
|
end
|
52
50
|
end
|
@@ -4,6 +4,34 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Lint
|
6
6
|
# This cop checks for calls to debugger or pry.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad (ok during development)
|
11
|
+
#
|
12
|
+
# # using pry
|
13
|
+
# def some_method
|
14
|
+
# binding.pry
|
15
|
+
# do_something
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
#
|
20
|
+
# # bad (ok during development)
|
21
|
+
#
|
22
|
+
# # using byebug
|
23
|
+
# def some_method
|
24
|
+
# byebug
|
25
|
+
# do_something
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
#
|
32
|
+
# def some_method
|
33
|
+
# do_something
|
34
|
+
# end
|
7
35
|
class Debugger < Cop
|
8
36
|
MSG = 'Remove debugger entry point `%s`.'.freeze
|
9
37
|
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# This cop checks whether the end keywords of method definitions are
|
7
7
|
# aligned properly.
|
8
8
|
#
|
9
|
-
# Two modes are supported through the
|
9
|
+
# Two modes are supported through the EnforcedStyleAlignWith configuration
|
10
10
|
# parameter. If it's set to `start_of_line` (which is the default), the
|
11
11
|
# `end` shall be aligned with the start of the line where the `def`
|
12
12
|
# keyword is. If it's set to `def`, the `end` shall be aligned with the
|
@@ -14,8 +14,28 @@ module RuboCop
|
|
14
14
|
#
|
15
15
|
# @example
|
16
16
|
#
|
17
|
+
# # bad
|
18
|
+
#
|
19
|
+
# private def foo
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
#
|
24
|
+
# # EnforcedStyleAlignWith: start_of_line (default)
|
25
|
+
#
|
26
|
+
# # good
|
27
|
+
#
|
17
28
|
# private def foo
|
18
29
|
# end
|
30
|
+
#
|
31
|
+
# @example
|
32
|
+
#
|
33
|
+
# # EnforcedStyleAlignWith: def
|
34
|
+
#
|
35
|
+
# # good
|
36
|
+
#
|
37
|
+
# private def foo
|
38
|
+
# end
|
19
39
|
class DefEndAlignment < Cop
|
20
40
|
include OnMethodDef
|
21
41
|
include EndKeywordAlignment
|
@@ -4,12 +4,24 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Lint
|
6
6
|
# This cop checks for uses of the deprecated class method usages.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
#
|
10
|
+
# # bad
|
11
|
+
#
|
12
|
+
# File.exists?(some_path)
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
#
|
18
|
+
# File.exist?(some_path)
|
7
19
|
class DeprecatedClassMethods < Cop
|
8
20
|
# Inner class to DeprecatedClassMethods.
|
9
21
|
# This class exists to add abstraction and clean naming to the
|
10
22
|
# objects that are going to be operated on.
|
11
23
|
class DeprecatedClassMethod
|
12
|
-
include RuboCop::Sexp
|
24
|
+
include RuboCop::AST::Sexp
|
13
25
|
|
14
26
|
attr_reader :class_constant, :deprecated_method, :replacement_method
|
15
27
|
|
@@ -8,40 +8,44 @@ module RuboCop
|
|
8
8
|
#
|
9
9
|
# @example
|
10
10
|
#
|
11
|
-
#
|
12
|
-
# case x
|
13
|
-
# when 'first'
|
14
|
-
# do_something
|
15
|
-
# when 'first'
|
16
|
-
# do_something_else
|
17
|
-
# end
|
11
|
+
# # bad
|
18
12
|
#
|
13
|
+
# case x
|
14
|
+
# when 'first'
|
15
|
+
# do_something
|
16
|
+
# when 'first'
|
17
|
+
# do_something_else
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
#
|
22
|
+
# # good
|
23
|
+
#
|
24
|
+
# case x
|
25
|
+
# when 'first
|
26
|
+
# do_something
|
27
|
+
# when 'second'
|
28
|
+
# do_something_else
|
29
|
+
# end
|
19
30
|
class DuplicateCaseCondition < Cop
|
20
31
|
MSG = 'Duplicate `when` condition detected.'.freeze
|
21
32
|
|
22
33
|
def on_case(case_node)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
conditions = when_conditions(when_node)
|
28
|
-
conditions.each do |cond|
|
29
|
-
if repeated_condition?(conditions_seen, cond)
|
30
|
-
add_offense(case_node, cond.loc.expression, MSG)
|
34
|
+
case_node.when_branches.each_with_object([]) do |when_node, previous|
|
35
|
+
when_node.each_condition do |condition|
|
36
|
+
if repeated_condition?(previous, condition)
|
37
|
+
add_offense(condition, :expression, MSG)
|
31
38
|
end
|
32
39
|
end
|
33
|
-
|
40
|
+
|
41
|
+
previous.push(when_node.conditions)
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
37
45
|
private
|
38
46
|
|
39
|
-
def
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def repeated_condition?(conditions_seen, condition)
|
44
|
-
conditions_seen.any? { |x| x.include?(condition) }
|
47
|
+
def repeated_condition?(previous, condition)
|
48
|
+
previous.any? { |c| c.include?(condition) }
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
@@ -7,7 +7,9 @@ module RuboCop
|
|
7
7
|
# definitions.
|
8
8
|
#
|
9
9
|
# @example
|
10
|
-
#
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
#
|
11
13
|
# def duplicated
|
12
14
|
# 1
|
13
15
|
# end
|
@@ -15,6 +17,18 @@ module RuboCop
|
|
15
17
|
# def duplicated
|
16
18
|
# 2
|
17
19
|
# end
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
#
|
23
|
+
# # good
|
24
|
+
#
|
25
|
+
# def duplicated
|
26
|
+
# 1
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def other_duplicated
|
30
|
+
# 2
|
31
|
+
# end
|
18
32
|
class DuplicateMethods < Cop
|
19
33
|
MSG = 'Method `%s` is defined at both %s and %s.'.freeze
|
20
34
|
|