rubocop 1.18.4 → 1.21.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 +65 -13
- data/lib/rubocop/cli.rb +18 -0
- data/lib/rubocop/config_loader.rb +2 -2
- data/lib/rubocop/config_loader_resolver.rb +21 -6
- data/lib/rubocop/cop/base.rb +2 -2
- data/lib/rubocop/cop/bundler/gem_filename.rb +103 -0
- data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +12 -11
- data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
- data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/correctors/require_library_corrector.rb +23 -0
- data/lib/rubocop/cop/documentation.rb +1 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +34 -0
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +71 -0
- data/lib/rubocop/cop/internal_affairs.rb +2 -0
- data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +9 -0
- data/lib/rubocop/cop/layout/end_alignment.rb +3 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +7 -3
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +0 -7
- data/lib/rubocop/cop/layout/leading_comment_space.rb +2 -2
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +33 -14
- data/lib/rubocop/cop/layout/line_length.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +3 -0
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +22 -9
- data/lib/rubocop/cop/layout/single_line_block_chain.rb +15 -4
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -0
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_operators.rb +8 -1
- data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_parens.rb +5 -5
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +24 -1
- data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +107 -0
- data/lib/rubocop/cop/lint/ambiguous_range.rb +105 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +5 -2
- data/lib/rubocop/cop/lint/debugger.rb +2 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +8 -5
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +67 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +7 -1
- data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -1
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -3
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/annotation_comment.rb +57 -34
- data/lib/rubocop/cop/mixin/code_length.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +5 -2
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +19 -1
- data/lib/rubocop/cop/mixin/heredoc.rb +7 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -2
- data/lib/rubocop/cop/mixin/percent_array.rb +13 -7
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +9 -1
- data/lib/rubocop/cop/mixin/require_library.rb +59 -0
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
- data/lib/rubocop/cop/naming/ascii_identifiers.rb +0 -3
- data/lib/rubocop/cop/naming/constant_name.rb +1 -1
- data/lib/rubocop/cop/naming/inclusive_language.rb +27 -10
- data/lib/rubocop/cop/style/accessor_grouping.rb +2 -2
- data/lib/rubocop/cop/style/and_or.rb +4 -0
- data/lib/rubocop/cop/style/ascii_comments.rb +0 -3
- data/lib/rubocop/cop/style/block_delimiters.rb +39 -6
- data/lib/rubocop/cop/style/case_equality.rb +6 -9
- data/lib/rubocop/cop/style/collection_methods.rb +2 -1
- data/lib/rubocop/cop/style/comment_annotation.rb +25 -39
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +19 -5
- data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +23 -8
- data/lib/rubocop/cop/style/double_negation.rb +12 -1
- data/lib/rubocop/cop/style/empty_method.rb +1 -1
- data/lib/rubocop/cop/style/encoding.rb +26 -15
- data/lib/rubocop/cop/style/explicit_block_argument.rb +46 -11
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +11 -0
- data/lib/rubocop/cop/style/hash_except.rb +4 -3
- data/lib/rubocop/cop/style/hash_transform_keys.rb +0 -3
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +30 -5
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +3 -2
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -6
- data/lib/rubocop/cop/style/method_def_parentheses.rb +10 -1
- data/lib/rubocop/cop/style/missing_else.rb +7 -0
- data/lib/rubocop/cop/style/mutable_constant.rb +68 -6
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_unless.rb +1 -1
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +2 -2
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_begin.rb +25 -0
- data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
- data/lib/rubocop/cop/style/redundant_freeze.rb +4 -3
- data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -3
- data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +83 -0
- data/lib/rubocop/cop/style/redundant_sort.rb +19 -4
- data/lib/rubocop/cop/style/regexp_literal.rb +3 -3
- data/lib/rubocop/cop/style/return_nil.rb +2 -1
- data/lib/rubocop/cop/style/semicolon.rb +32 -24
- data/lib/rubocop/cop/style/single_line_block_params.rb +3 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -0
- data/lib/rubocop/cop/style/special_global_vars.rb +21 -0
- data/lib/rubocop/cop/style/static_class.rb +1 -2
- data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +3 -0
- data/lib/rubocop/cop/style/symbol_array.rb +3 -3
- data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +23 -5
- data/lib/rubocop/cop/style/yoda_condition.rb +4 -7
- data/lib/rubocop/cop/util.rb +7 -2
- data/lib/rubocop/magic_comment.rb +44 -15
- data/lib/rubocop/options.rb +1 -1
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/runner.rb +1 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +9 -2
- metadata +14 -5
@@ -46,12 +46,11 @@ module RuboCop
|
|
46
46
|
node = processed_source.ast.each_node(:regexp).find do |regexp_node|
|
47
47
|
regexp_node.source_range.begin_pos == diagnostic.location.begin_pos
|
48
48
|
end
|
49
|
-
|
50
49
|
find_offense_node(node.parent, node)
|
51
50
|
end
|
52
51
|
|
53
52
|
def find_offense_node(node, regexp_receiver)
|
54
|
-
return node
|
53
|
+
return node if first_argument_is_regexp?(node) || !node.parent
|
55
54
|
|
56
55
|
if (node.parent.send_type? && node.receiver) ||
|
57
56
|
method_chain_to_regexp_receiver?(node, regexp_receiver)
|
@@ -61,6 +60,10 @@ module RuboCop
|
|
61
60
|
node
|
62
61
|
end
|
63
62
|
|
63
|
+
def first_argument_is_regexp?(node)
|
64
|
+
node.send_type? && node.first_argument&.regexp_type?
|
65
|
+
end
|
66
|
+
|
64
67
|
def method_chain_to_regexp_receiver?(node, regexp_receiver)
|
65
68
|
return false unless (parent = node.parent)
|
66
69
|
return false unless (parent_receiver = parent.receiver)
|
@@ -7,8 +7,8 @@ module RuboCop
|
|
7
7
|
# not be kept for production code.
|
8
8
|
#
|
9
9
|
# The cop can be configured using `DebuggerMethods`. By default, a number of gems
|
10
|
-
# debug entrypoints are configured (`Kernel`, `Byebug`, `Capybara`, `
|
11
|
-
# and `WebConsole`). Additional methods can be added.
|
10
|
+
# debug entrypoints are configured (`Kernel`, `Byebug`, `Capybara`, `debug.rb`,
|
11
|
+
# `Pry`, `Rails`, `RubyJard`, and `WebConsole`). Additional methods can be added.
|
12
12
|
#
|
13
13
|
# Specific default groups can be disabled if necessary:
|
14
14
|
#
|
@@ -57,8 +57,6 @@ module RuboCop
|
|
57
57
|
class Debugger < Base
|
58
58
|
MSG = 'Remove debugger entry point `%<source>s`.'
|
59
59
|
|
60
|
-
RESTRICT_ON_SEND = [].freeze
|
61
|
-
|
62
60
|
# @!method kernel?(node)
|
63
61
|
def_node_matcher :kernel?, <<~PATTERN
|
64
62
|
(const {nil? cbase} :Kernel)
|
@@ -135,11 +135,14 @@ module RuboCop
|
|
135
135
|
def found_instance_method(node, name)
|
136
136
|
return unless (scope = node.parent_module_name)
|
137
137
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
138
|
+
# Humanize the scope
|
139
|
+
scope = scope.sub(
|
140
|
+
/(?:(?<name>.*)::)#<Class:\k<name>>|#<Class:(?<name>.*)>(?:::)?/,
|
141
|
+
'\k<name>.'
|
142
|
+
)
|
143
|
+
scope << '#' unless scope.end_with?('.')
|
144
|
+
|
145
|
+
found_method(node, "#{scope}#{name}")
|
143
146
|
end
|
144
147
|
|
145
148
|
def found_method(node, method_name)
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
|
52
52
|
def on_case_match(node)
|
53
53
|
node.in_pattern_branches.each do |branch|
|
54
|
-
next if branch.body || cop_config['AllowComments'] && comment_lines?(node)
|
54
|
+
next if branch.body || (cop_config['AllowComments'] && comment_lines?(node))
|
55
55
|
|
56
56
|
add_offense(branch)
|
57
57
|
end
|
@@ -118,7 +118,7 @@ module RuboCop
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def correct_arguments?(arguments)
|
121
|
-
arguments.size == 1 || arguments.size == 2 && arguments[1].hash_type?
|
121
|
+
arguments.size == 1 || (arguments.size == 2 && arguments[1].hash_type?)
|
122
122
|
end
|
123
123
|
|
124
124
|
def build_kwargs(node)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
#
|
7
|
+
# This cop checks for `IO.select` that is incompatible with Fiber Scheduler since Ruby 3.0.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# IO.select([io], [], [], timeout)
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# io.wait_readable(timeout)
|
16
|
+
#
|
17
|
+
# # bad
|
18
|
+
# IO.select([], [io], [], timeout)
|
19
|
+
#
|
20
|
+
# # good
|
21
|
+
# io.wait_writable(timeout)
|
22
|
+
#
|
23
|
+
class IncompatibleIoSelectWithFiberScheduler < Base
|
24
|
+
extend AutoCorrector
|
25
|
+
|
26
|
+
MSG = 'Use `%<preferred>s` instead of `%<current>s`.'
|
27
|
+
RESTRICT_ON_SEND = %i[select].freeze
|
28
|
+
|
29
|
+
# @!method io_select(node)
|
30
|
+
def_node_matcher :io_select, <<~PATTERN
|
31
|
+
(send
|
32
|
+
(const {nil? cbase} :IO) :select $_ $_ {(array) nil} $...)
|
33
|
+
PATTERN
|
34
|
+
|
35
|
+
def on_send(node)
|
36
|
+
return unless (read, write, timeout = io_select(node))
|
37
|
+
return unless scheduler_compatible?(read, write) || scheduler_compatible?(write, read)
|
38
|
+
|
39
|
+
preferred = preferred_method(read, write, timeout)
|
40
|
+
message = format(MSG, preferred: preferred, current: node.source)
|
41
|
+
|
42
|
+
add_offense(node, message: message) do |corrector|
|
43
|
+
corrector.replace(node, preferred)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def scheduler_compatible?(io1, io2)
|
50
|
+
return false unless io1.array_type? && io1.values.size == 1
|
51
|
+
|
52
|
+
io2.array_type? ? io2.values.empty? : io2.nil_type?
|
53
|
+
end
|
54
|
+
|
55
|
+
def preferred_method(read, write, timeout)
|
56
|
+
timeout_argument = timeout.empty? ? '' : "(#{timeout[0].source})"
|
57
|
+
|
58
|
+
if read.array_type? && read.values[0]
|
59
|
+
"#{read.values[0].source}.wait_readable#{timeout_argument}"
|
60
|
+
else
|
61
|
+
"#{write.values[0].source}.wait_writable#{timeout_argument}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -60,6 +60,7 @@ module RuboCop
|
|
60
60
|
'class parsing, instead of using '\
|
61
61
|
'`%<current>s`, use stricter '\
|
62
62
|
'`%<corrected_method>s`.'
|
63
|
+
CONVERSION_METHODS = %i[Integer Float Complex to_i to_f to_c].freeze
|
63
64
|
METHODS = CONVERSION_METHOD_CLASS_MAPPING.keys.map(&:inspect).join(' ')
|
64
65
|
|
65
66
|
# @!method to_method(node)
|
@@ -127,7 +128,8 @@ module RuboCop
|
|
127
128
|
end
|
128
129
|
|
129
130
|
def ignore_receiver?(receiver)
|
130
|
-
if receiver.
|
131
|
+
if receiver.numeric_type? || (receiver.send_type? &&
|
132
|
+
(conversion_method?(receiver.method_name) || ignored_method?(receiver.method_name)))
|
131
133
|
true
|
132
134
|
elsif (receiver = top_receiver(receiver))
|
133
135
|
receiver.const_type? && ignored_class?(receiver.const_name)
|
@@ -142,6 +144,10 @@ module RuboCop
|
|
142
144
|
receiver
|
143
145
|
end
|
144
146
|
|
147
|
+
def conversion_method?(method_name)
|
148
|
+
CONVERSION_METHODS.include?(method_name)
|
149
|
+
end
|
150
|
+
|
145
151
|
def ignored_classes
|
146
152
|
cop_config.fetch('IgnoredClasses', [])
|
147
153
|
end
|
@@ -87,9 +87,8 @@ module RuboCop
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def ignored_method?(body)
|
90
|
-
cop_config['IgnoreEmptyMethods'] && body.nil? ||
|
91
|
-
cop_config['IgnoreNotImplementedMethods'] &&
|
92
|
-
not_implemented?(body)
|
90
|
+
(cop_config['IgnoreEmptyMethods'] && body.nil?) ||
|
91
|
+
(cop_config['IgnoreNotImplementedMethods'] && not_implemented?(body))
|
93
92
|
end
|
94
93
|
|
95
94
|
def message(variable)
|
@@ -46,7 +46,7 @@ module RuboCop
|
|
46
46
|
visit_depth_last(@node) { |child| calculate_node(child) }
|
47
47
|
|
48
48
|
[
|
49
|
-
Math.sqrt(@assignment**2 + @branch**2 + @condition**2).round(2),
|
49
|
+
Math.sqrt((@assignment**2) + (@branch**2) + (@condition**2)).round(2),
|
50
50
|
"<#{@assignment}, #{@branch}, #{@condition}>"
|
51
51
|
]
|
52
52
|
end
|
@@ -147,7 +147,7 @@ module RuboCop
|
|
147
147
|
|
148
148
|
# Returns true for lines that shall not be included in the count.
|
149
149
|
def irrelevant_line?(source_line)
|
150
|
-
source_line.blank? || !count_comments? && comment_line?(source_line)
|
150
|
+
source_line.blank? || (!count_comments? && comment_line?(source_line))
|
151
151
|
end
|
152
152
|
|
153
153
|
def count_comments?
|
@@ -2,40 +2,63 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
5
|
+
# Representation of an annotation comment in source code (eg. `# TODO: blah blah blah`).
|
6
|
+
class AnnotationComment
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
attr_reader :comment, :margin, :keyword, :colon, :space, :note
|
10
|
+
|
11
|
+
# @param [Parser::Source::Comment] comment
|
12
|
+
# @param [Array<String>] keywords
|
13
|
+
def initialize(comment, keywords)
|
14
|
+
@comment = comment
|
15
|
+
@keywords = keywords
|
16
|
+
@margin, @keyword, @colon, @space, @note = split_comment(comment)
|
17
|
+
end
|
18
|
+
|
19
|
+
def annotation?
|
20
|
+
keyword_appearance? && !just_keyword_of_sentence?
|
21
|
+
end
|
22
|
+
|
23
|
+
def correct?(colon:)
|
24
|
+
return false unless keyword && space && note
|
25
|
+
return false unless keyword == keyword.upcase
|
26
|
+
|
27
|
+
self.colon.nil? == !colon
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the range bounds for just the annotation
|
31
|
+
def bounds
|
32
|
+
start = comment.loc.expression.begin_pos + margin.length
|
33
|
+
length = [keyword, colon, space].reduce(0) { |len, elem| len + elem.to_s.length }
|
34
|
+
[start, start + length]
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :keywords
|
40
|
+
|
41
|
+
def split_comment(comment)
|
42
|
+
# Sort keywords by reverse length so that if a keyword is in a phrase
|
43
|
+
# but also on its own, both will match properly.
|
44
|
+
keywords_regex = Regexp.new(
|
45
|
+
Regexp.union(keywords.sort_by { |w| -w.length }).source,
|
46
|
+
Regexp::IGNORECASE
|
47
|
+
)
|
48
|
+
regex = /^(# ?)(\b#{keywords_regex}\b)(\s*:)?(\s+)?(\S+)?/i
|
49
|
+
|
50
|
+
match = comment.text.match(regex)
|
51
|
+
return false unless match
|
52
|
+
|
53
|
+
match.captures
|
54
|
+
end
|
55
|
+
|
56
|
+
def keyword_appearance?
|
57
|
+
keyword && (colon || space)
|
58
|
+
end
|
59
|
+
|
60
|
+
def just_keyword_of_sentence?
|
61
|
+
keyword == keyword.capitalize && !colon && space && note
|
39
62
|
end
|
40
63
|
end
|
41
64
|
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
|
44
44
|
# Returns true for lines that shall not be included in the count.
|
45
45
|
def irrelevant_line(source_line)
|
46
|
-
source_line.blank? || !count_comments? && comment_line?(source_line)
|
46
|
+
source_line.blank? || (!count_comments? && comment_line?(source_line))
|
47
47
|
end
|
48
48
|
|
49
49
|
def build_code_length_calculator(node)
|
@@ -5,7 +5,6 @@ module RuboCop
|
|
5
5
|
# Common functionality for checking documentation.
|
6
6
|
module DocumentationComment
|
7
7
|
extend NodePattern::Macros
|
8
|
-
include Style::AnnotationComment
|
9
8
|
|
10
9
|
private
|
11
10
|
|
@@ -15,7 +14,7 @@ module RuboCop
|
|
15
14
|
return false unless preceding_comment?(node, preceding_lines.last)
|
16
15
|
|
17
16
|
preceding_lines.any? do |comment|
|
18
|
-
!
|
17
|
+
!AnnotationComment.new(comment, annotation_keywords).annotation? &&
|
19
18
|
!interpreter_directive_comment?(comment) &&
|
20
19
|
!rubocop_directive_comment?(comment)
|
21
20
|
end
|
@@ -44,6 +43,10 @@ module RuboCop
|
|
44
43
|
def rubocop_directive_comment?(comment)
|
45
44
|
!!DirectiveComment.new(comment).match_captures
|
46
45
|
end
|
46
|
+
|
47
|
+
def annotation_keywords
|
48
|
+
config.for_cop('Style/CommentAnnotation')['Keywords']
|
49
|
+
end
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
@@ -8,7 +8,9 @@ module RuboCop
|
|
8
8
|
|
9
9
|
FROZEN_STRING_LITERAL = '# frozen_string_literal:'
|
10
10
|
FROZEN_STRING_LITERAL_ENABLED = '# frozen_string_literal: true'
|
11
|
-
|
11
|
+
FROZEN_STRING_LITERAL_TYPES_RUBY27 = %i[str dstr].freeze
|
12
|
+
|
13
|
+
private_constant :FROZEN_STRING_LITERAL_TYPES_RUBY27
|
12
14
|
|
13
15
|
def frozen_string_literal_comment_exists?
|
14
16
|
leading_comment_lines.any? { |line| MagicComment.parse(line).valid_literal_value? }
|
@@ -16,6 +18,22 @@ module RuboCop
|
|
16
18
|
|
17
19
|
private
|
18
20
|
|
21
|
+
def frozen_string_literal?(node)
|
22
|
+
frozen_string = if target_ruby_version >= 3.0
|
23
|
+
node.str_type? || frozen_heredoc?(node)
|
24
|
+
else
|
25
|
+
FROZEN_STRING_LITERAL_TYPES_RUBY27.include?(node.type)
|
26
|
+
end
|
27
|
+
|
28
|
+
frozen_string && frozen_string_literals_enabled?
|
29
|
+
end
|
30
|
+
|
31
|
+
def frozen_heredoc?(node)
|
32
|
+
return false unless node.dstr_type? && node.heredoc?
|
33
|
+
|
34
|
+
node.children.all?(&:str_type?)
|
35
|
+
end
|
36
|
+
|
19
37
|
def frozen_string_literals_enabled?
|
20
38
|
ruby_version = processed_source.ruby_version
|
21
39
|
return false unless ruby_version
|
@@ -20,6 +20,13 @@ module RuboCop
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
+
def indent_level(str)
|
24
|
+
indentations = str.lines
|
25
|
+
.map { |line| line[/^\s*/] }
|
26
|
+
.reject { |line| line.end_with?("\n") }
|
27
|
+
indentations.empty? ? 0 : indentations.min_by(&:size).size
|
28
|
+
end
|
29
|
+
|
23
30
|
def delimiter_string(node)
|
24
31
|
node.source.match(OPENING_DELIMITER).captures[1]
|
25
32
|
end
|
@@ -134,7 +134,7 @@ module RuboCop
|
|
134
134
|
|
135
135
|
next if a.setter_method?
|
136
136
|
next unless kind == :with_or_without_parentheses ||
|
137
|
-
kind == :with_parentheses && parentheses?(a)
|
137
|
+
(kind == :with_parentheses && parentheses?(a))
|
138
138
|
|
139
139
|
a.arguments.any? { |arg| within_node?(node, arg) }
|
140
140
|
end
|
@@ -156,7 +156,7 @@ module RuboCop
|
|
156
156
|
|
157
157
|
def disqualified_rhs?(candidate, ancestor)
|
158
158
|
UNALIGNED_RHS_TYPES.include?(ancestor.type) ||
|
159
|
-
ancestor.block_type? && part_of_block_body?(candidate, ancestor)
|
159
|
+
(ancestor.block_type? && part_of_block_body?(candidate, ancestor))
|
160
160
|
end
|
161
161
|
|
162
162
|
def valid_rhs?(candidate, ancestor)
|