rubocop 0.52.0 → 0.52.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/config/default.yml +1 -11
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +6 -8
- data/lib/rubocop.rb +13 -2
- data/lib/rubocop/ast/node.rb +23 -15
- data/lib/rubocop/cli.rb +25 -2
- data/lib/rubocop/config.rb +23 -8
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -0
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +121 -0
- data/lib/rubocop/cop/correctors/condition_corrector.rb +28 -0
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +26 -0
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +62 -0
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +44 -0
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +31 -0
- data/lib/rubocop/cop/correctors/punctuation_corrector.rb +29 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +34 -0
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +25 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +31 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -0
- data/lib/rubocop/cop/generator.rb +18 -87
- data/lib/rubocop/cop/generator/require_file_injector.rb +78 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/align_array.rb +5 -1
- data/lib/rubocop/cop/layout/align_hash.rb +1 -1
- data/lib/rubocop/cop/layout/align_parameters.rb +5 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -2
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +3 -3
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +17 -19
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +4 -0
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/indent_array.rb +6 -2
- data/lib/rubocop/cop/layout/indent_assignment.rb +6 -2
- data/lib/rubocop/cop/layout/indent_hash.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_consistency.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +3 -3
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/space_after_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +16 -7
- data/lib/rubocop/cop/layout/tab.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/end_alignment.rb +3 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +4 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +6 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -1
- data/lib/rubocop/cop/mixin/alignment.rb +70 -0
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +2 -0
- data/lib/rubocop/cop/mixin/code_length.rb +2 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +2 -0
- data/lib/rubocop/cop/mixin/def_node.rb +3 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -15
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -25
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -6
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +5 -9
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +2 -2
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +2 -0
- data/lib/rubocop/cop/mixin/integer_node.rb +2 -0
- data/lib/rubocop/cop/mixin/match_range.rb +2 -0
- data/lib/rubocop/cop/mixin/min_body_length.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +9 -48
- data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -16
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +12 -31
- data/lib/rubocop/cop/mixin/parentheses.rb +2 -19
- data/lib/rubocop/cop/mixin/percent_literal.rb +3 -3
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +2 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -2
- data/lib/rubocop/cop/mixin/string_help.rb +2 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -13
- data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -21
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -10
- data/lib/rubocop/cop/mixin/unused_argument.rb +2 -15
- data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
- data/lib/rubocop/cop/rails/action_filter.rb +3 -2
- data/lib/rubocop/cop/rails/active_support_aliases.rb +3 -2
- data/lib/rubocop/cop/rails/application_job.rb +6 -0
- data/lib/rubocop/cop/rails/application_record.rb +6 -0
- data/lib/rubocop/cop/rails/blank.rb +10 -9
- data/lib/rubocop/cop/rails/date.rb +22 -14
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -2
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +4 -2
- data/lib/rubocop/cop/rails/environment_comparison.rb +2 -2
- data/lib/rubocop/cop/rails/file_path.rb +1 -1
- data/lib/rubocop/cop/rails/find_by.rb +2 -2
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +15 -7
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +2 -2
- data/lib/rubocop/cop/rails/inverse_of.rb +130 -8
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
- data/lib/rubocop/cop/rails/presence.rb +31 -18
- data/lib/rubocop/cop/rails/present.rb +11 -8
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +52 -10
- data/lib/rubocop/cop/rails/request_referer.rb +2 -3
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +9 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +38 -10
- data/lib/rubocop/cop/style/class_and_module_children.rb +76 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +24 -4
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +46 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +14 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +79 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +13 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +19 -0
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_while.rb +6 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +4 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +4 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -0
- data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +4 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +33 -24
- data/lib/rubocop/options.rb +33 -10
- data/lib/rubocop/path_util.rb +7 -0
- data/lib/rubocop/token.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +14 -4
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -149
- data/lib/rubocop/cop/style/extend_self.rb +0 -92
@@ -5,6 +5,13 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# Use a consistent style for named format string tokens.
|
7
7
|
#
|
8
|
+
# **Note:**
|
9
|
+
# `unannotated` style cop only works for strings
|
10
|
+
# which are passed as arguments to those methods:
|
11
|
+
# `sprintf`, `format`, `%`.
|
12
|
+
# The reason is that *unannotated* format is very similar
|
13
|
+
# to encoded URLs or Date/Time formatting strings.
|
14
|
+
#
|
8
15
|
# @example EnforcedStyle: annotated (default)
|
9
16
|
#
|
10
17
|
# # bad
|
@@ -35,6 +42,7 @@ module RuboCop
|
|
35
42
|
include ConfigurableEnforcedStyle
|
36
43
|
|
37
44
|
FIELD_CHARACTERS = Regexp.union(%w[A B E G X a b c d e f g i o p s u x])
|
45
|
+
FORMAT_STRING_METHODS = %i[sprintf format %].freeze
|
38
46
|
|
39
47
|
STYLE_PATTERNS = {
|
40
48
|
annotated: /(?<token>%<[^>]+>#{FIELD_CHARACTERS})/,
|
@@ -42,13 +50,12 @@ module RuboCop
|
|
42
50
|
unannotated: /(?<token>%#{FIELD_CHARACTERS})/
|
43
51
|
}.freeze
|
44
52
|
|
45
|
-
TOKEN_PATTERN = Regexp.union(STYLE_PATTERNS.values)
|
46
|
-
|
47
53
|
def on_str(node)
|
48
|
-
return if node.each_ancestor(:xstr).any?
|
54
|
+
return if node.each_ancestor(:xstr, :regexp).any?
|
49
55
|
|
50
56
|
tokens(node) do |detected_style, token_range|
|
51
|
-
if detected_style == style
|
57
|
+
if detected_style == style ||
|
58
|
+
unannotated_format?(node, detected_style)
|
52
59
|
correct_style_detected
|
53
60
|
else
|
54
61
|
style_detected(detected_style)
|
@@ -60,6 +67,19 @@ module RuboCop
|
|
60
67
|
|
61
68
|
private
|
62
69
|
|
70
|
+
def includes_format_methods?(node)
|
71
|
+
root_node = node.ancestors.last
|
72
|
+
return unless root_node
|
73
|
+
|
74
|
+
root_node.descendants.any? do |desc_node|
|
75
|
+
FORMAT_STRING_METHODS.include?(desc_node.method_name)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def unannotated_format?(node, detected_style)
|
80
|
+
detected_style == :unannotated && !includes_format_methods?(node)
|
81
|
+
end
|
82
|
+
|
63
83
|
def message(detected_style)
|
64
84
|
"Prefer #{message_text(style)} over #{message_text(detected_style)}."
|
65
85
|
end
|
@@ -8,6 +8,52 @@ module RuboCop
|
|
8
8
|
# enable frozen string literals. Frozen string literals may be default
|
9
9
|
# in Ruby 3.0. The comment will be added below a shebang and encoding
|
10
10
|
# comment. The frozen string literal comment is only valid in Ruby 2.3+.
|
11
|
+
#
|
12
|
+
# @example EnforcedStyle: when_needed (default)
|
13
|
+
# # The `when_needed` style will add the frozen string literal comment
|
14
|
+
# # to files only when the `TargetRubyVersion` is set to 2.3+.
|
15
|
+
# # bad
|
16
|
+
# module Foo
|
17
|
+
# # ...
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# # frozen_string_literal: true
|
22
|
+
#
|
23
|
+
# module Foo
|
24
|
+
# # ...
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# @example EnforcedStyle: always
|
28
|
+
# # The `always` style will always add the frozen string literal comment
|
29
|
+
# # to a file, regardless of the Ruby version or if `freeze` or `<<` are
|
30
|
+
# # called on a string literal.
|
31
|
+
# # bad
|
32
|
+
# module Bar
|
33
|
+
# # ...
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# # good
|
37
|
+
# # frozen_string_literal: true
|
38
|
+
#
|
39
|
+
# module Bar
|
40
|
+
# # ...
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# @example EnforcedStyle: never
|
44
|
+
# # The `never` will enforce that the frozen string literal comment does
|
45
|
+
# # not exist in a file.
|
46
|
+
# # bad
|
47
|
+
# # frozen_string_literal: true
|
48
|
+
#
|
49
|
+
# module Baz
|
50
|
+
# # ...
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# # good
|
54
|
+
# module Baz
|
55
|
+
# # ...
|
56
|
+
# end
|
11
57
|
class FrozenStringLiteralComment < Cop
|
12
58
|
include ConfigurableEnforcedStyle
|
13
59
|
include FrozenStringLiteral
|
@@ -173,11 +173,12 @@ module RuboCop
|
|
173
173
|
range = range_between(key.source_range.begin_pos, op.end_pos)
|
174
174
|
range = range_with_surrounding_space(range: range, side: :right)
|
175
175
|
|
176
|
-
new_key = key.sym_type? ? key.value : key.source
|
177
|
-
|
178
176
|
space = argument_without_space?(pair_node.parent) ? ' ' : ''
|
179
177
|
|
180
|
-
corrector.replace(
|
178
|
+
corrector.replace(
|
179
|
+
range,
|
180
|
+
range.source.sub(/^:(.*\S)\s*=>\s*$/, space.to_s + '\1: ')
|
181
|
+
)
|
181
182
|
end
|
182
183
|
|
183
184
|
def argument_without_space?(node)
|
@@ -6,6 +6,20 @@ module RuboCop
|
|
6
6
|
# Checks for if and unless statements that would fit on one line
|
7
7
|
# if written as a modifier if/unless. The maximum line length is
|
8
8
|
# configured in the `Metrics/LineLength` cop.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# if condition
|
13
|
+
# do_stuff(bar)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# unless qux.empty?
|
17
|
+
# Foo.do_something
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# do_stuff(bar) if condition
|
22
|
+
# Foo.do_something unless qux.empty?
|
9
23
|
class IfUnlessModifier < Cop
|
10
24
|
include StatementModifier
|
11
25
|
|
@@ -5,6 +5,85 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# This cops checks for parentheses around the arguments in method
|
7
7
|
# definitions. Both instance and class/singleton methods are checked.
|
8
|
+
#
|
9
|
+
# @example EnforcedStyle: require_parentheses (default)
|
10
|
+
# # The `require_parentheses` style requires method definitions
|
11
|
+
# # to always use parentheses
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# def bar num1, num2
|
15
|
+
# num1 + num2
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# def foo descriptive_var_name,
|
19
|
+
# another_descriptive_var_name,
|
20
|
+
# last_descriptive_var_name
|
21
|
+
# do_something
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# # good
|
25
|
+
# def bar(num1, num2)
|
26
|
+
# num1 + num2
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def foo(descriptive_var_name,
|
30
|
+
# another_descriptive_var_name,
|
31
|
+
# last_descriptive_var_name)
|
32
|
+
# do_something
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# @example EnforcedStyle: require_no_parentheses
|
36
|
+
# # The `require_no_parentheses` style requires method definitions
|
37
|
+
# # to never use parentheses
|
38
|
+
#
|
39
|
+
# # bad
|
40
|
+
# def bar(num1, num2)
|
41
|
+
# num1 + num2
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# def foo(descriptive_var_name,
|
45
|
+
# another_descriptive_var_name,
|
46
|
+
# last_descriptive_var_name)
|
47
|
+
# do_something
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# # good
|
51
|
+
# def bar num1, num2
|
52
|
+
# num1 + num2
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def foo descriptive_var_name,
|
56
|
+
# another_descriptive_var_name,
|
57
|
+
# last_descriptive_var_name
|
58
|
+
# do_something
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# @example EnforcedStyle: require_no_parentheses_except_multiline
|
62
|
+
# # The `require_no_parentheses_except_multiline` style prefers no
|
63
|
+
# # parantheses when method definition arguments fit on single line,
|
64
|
+
# # but prefers parantheses when arguments span multiple lines.
|
65
|
+
#
|
66
|
+
# # bad
|
67
|
+
# def bar(num1, num2)
|
68
|
+
# num1 + num2
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# def foo descriptive_var_name,
|
72
|
+
# another_descriptive_var_name,
|
73
|
+
# last_descriptive_var_name
|
74
|
+
# do_something
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# # good
|
78
|
+
# def bar num1, num2
|
79
|
+
# num1 + num2
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# def foo(descriptive_var_name,
|
83
|
+
# another_descriptive_var_name,
|
84
|
+
# last_descriptive_var_name)
|
85
|
+
# do_something
|
86
|
+
# end
|
8
87
|
class MethodDefParentheses < Cop
|
9
88
|
include ConfigurableEnforcedStyle
|
10
89
|
|
@@ -53,8 +53,9 @@ module RuboCop
|
|
53
53
|
|
54
54
|
def on_send(node)
|
55
55
|
include_statement(node) do |statement|
|
56
|
-
return if node.argument?
|
57
|
-
|
56
|
+
return if node.argument? ||
|
57
|
+
accepted_include?(node) ||
|
58
|
+
belongs_to_class_or_module?(node)
|
58
59
|
|
59
60
|
add_offense(node, message: format(MSG, statement: statement))
|
60
61
|
end
|
@@ -65,6 +66,16 @@ module RuboCop
|
|
65
66
|
def accepted_include?(node)
|
66
67
|
node.parent && node.macro?
|
67
68
|
end
|
69
|
+
|
70
|
+
def belongs_to_class_or_module?(node)
|
71
|
+
if !node.parent
|
72
|
+
false
|
73
|
+
else
|
74
|
+
return true if node.parent.class_type? || node.parent.module_type?
|
75
|
+
|
76
|
+
belongs_to_class_or_module?(node.parent)
|
77
|
+
end
|
78
|
+
end
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end
|
@@ -16,7 +16,7 @@ module RuboCop
|
|
16
16
|
# { result: 'ok' } if cond
|
17
17
|
class MultilineIfModifier < Cop
|
18
18
|
include StatementModifier
|
19
|
-
include
|
19
|
+
include Alignment
|
20
20
|
|
21
21
|
MSG = 'Favor a normal %<keyword>s-statement over a modifier' \
|
22
22
|
' clause in a multiline statement.'.freeze
|
@@ -4,6 +4,25 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# This cop checks for multi-line ternary op expressions.
|
7
|
+
#
|
8
|
+
# @example
|
9
|
+
# # bad
|
10
|
+
# a = cond ?
|
11
|
+
# b : c
|
12
|
+
# a = cond ? b :
|
13
|
+
# c
|
14
|
+
# a = cond ?
|
15
|
+
# b :
|
16
|
+
# c
|
17
|
+
#
|
18
|
+
# # good
|
19
|
+
# a = cond ? b : c
|
20
|
+
# a =
|
21
|
+
# if cond
|
22
|
+
# b
|
23
|
+
# else
|
24
|
+
# c
|
25
|
+
# end
|
7
26
|
class MultilineTernaryOperator < Cop
|
8
27
|
MSG = 'Avoid multi-line ternary operators, ' \
|
9
28
|
'use `if` or `unless` instead.'.freeze
|
@@ -15,12 +15,14 @@ module RuboCop
|
|
15
15
|
check_negative_conditional(node)
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def autocorrect(node)
|
19
|
+
ConditionCorrector.correct_negative_condition(node)
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
private
|
23
|
+
|
24
|
+
def message(node)
|
25
|
+
format(MSG, inverse: node.inverse_keyword, current: node.keyword)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|