rbhint 0.85.1.rc1 → 0.85.1.rc2
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 -2
- data/assets/output.html.erb +1 -1
- data/config/default.yml +13 -1
- data/lib/rbhint.rb +8 -0
- data/lib/rbhint/version.rb +1 -1
- data/lib/rubocop.rb +2 -0
- data/lib/rubocop/config.rb +1 -1
- data/lib/rubocop/config_loader_resolver.rb +1 -1
- data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
- data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
- data/lib/rubocop/cop/layout/assignment_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/block_end_newline.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +4 -4
- data/lib/rubocop/cop/layout/condition_position.rb +1 -1
- data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +1 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_comment.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -0
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +2 -2
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
- data/lib/rubocop/cop/layout/extra_spacing.rb +6 -6
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +2 -2
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_style.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +2 -2
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/layout/leading_empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/line_length.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/parameter_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_colon.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +6 -6
- data/lib/rubocop/cop/layout/space_around_operators.rb +2 -2
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +14 -0
- data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/constant_resolution.rb +89 -0
- data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +6 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +4 -4
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +4 -2
- data/lib/rubocop/cop/lint/safe_navigation_with_empty.rb +1 -1
- data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
- data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +35 -3
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/iterating_block.rb +61 -0
- data/lib/rubocop/cop/mixin/configurable_naming.rb +1 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +1 -1
- data/lib/rubocop/cop/mixin/parentheses.rb +1 -2
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +1 -1
- data/lib/rubocop/cop/mixin/range_help.rb +1 -1
- data/lib/rubocop/cop/mixin/regexp_literal_help.rb +27 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/mixin/uncommunicative_name.rb +2 -2
- data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -3
- data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -4
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/command_literal.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
- data/lib/rubocop/cop/style/copyright.rb +3 -3
- data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +1 -1
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +8 -6
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/exponential_notation.rb +2 -2
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_inside_else.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
- data/lib/rubocop/cop/style/ip_addresses.rb +1 -1
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +17 -6
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +27 -0
- data/lib/rubocop/cop/style/next.rb +2 -2
- data/lib/rubocop/cop/style/numeric_literal_prefix.rb +2 -2
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +2 -2
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +14 -23
- data/lib/rubocop/cop/style/redundant_self.rb +6 -9
- data/lib/rubocop/cop/style/sample.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +1 -1
- data/lib/rubocop/cop/style/struct_inheritance.rb +21 -0
- data/lib/rubocop/cop/style/symbol_array.rb +5 -5
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/util.rb +2 -2
- data/lib/rubocop/cop/utils/format_string.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/name_similarity.rb +6 -0
- data/lib/rubocop/path_util.rb +2 -2
- data/lib/rubocop/platform.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +12 -2
- data/lib/rubocop/target_finder.rb +1 -1
- data/lib/rubocop/target_ruby.rb +1 -1
- metadata +10 -2
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Metrics
|
6
|
+
module Utils
|
7
|
+
# Used to identify iterating blocks like `.map{}` and `.map(&:...)`
|
8
|
+
module IteratingBlock
|
9
|
+
enumerable = %i[
|
10
|
+
all? any? chain chunk chunk_while collect collect_concat count cycle
|
11
|
+
detect drop drop_while each each_cons each_entry each_slice
|
12
|
+
each_with_index each_with_object entries filter filter_map find
|
13
|
+
find_all find_index flat_map grep grep_v group_by inject lazy map
|
14
|
+
max max_by min min_by minmax minmax_by none? one? partition reduce
|
15
|
+
reject reverse_each select slice_after slice_before slice_when sort
|
16
|
+
sort_by sum take take_while tally to_h uniq zip
|
17
|
+
]
|
18
|
+
|
19
|
+
enumerator = %i[with_index with_object]
|
20
|
+
|
21
|
+
array = %i[
|
22
|
+
bsearch bsearch_index collect! combination d_permutation delete_if
|
23
|
+
each_index keep_if map! permutation product reject! repeat
|
24
|
+
repeated_combination select! sort sort! sort_by sort_by
|
25
|
+
]
|
26
|
+
|
27
|
+
hash = %i[
|
28
|
+
each_key each_pair each_value fetch fetch_values has_key? merge
|
29
|
+
merge! transform_keys transform_keys! transform_values
|
30
|
+
transform_values!
|
31
|
+
]
|
32
|
+
|
33
|
+
KNOWN_ITERATING_METHODS = (Set.new(enumerable) + enumerator + array + hash).freeze
|
34
|
+
|
35
|
+
# Returns the name of the method called with a block
|
36
|
+
# if node is a block node, or a block-pass node.
|
37
|
+
def block_method_name(node)
|
38
|
+
case node.type
|
39
|
+
when :block
|
40
|
+
node.method_name
|
41
|
+
when :block_pass
|
42
|
+
node.parent.method_name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns true iff name is a known iterating type (e.g. :each, :transform_values)
|
47
|
+
def iterating_method?(name)
|
48
|
+
KNOWN_ITERATING_METHODS.include? name
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns nil if node is neither a block node or a block-pass node.
|
52
|
+
# Otherwise returns true/false if method call is a known iterating call
|
53
|
+
def iterating_block?(node)
|
54
|
+
name = block_method_name(node)
|
55
|
+
name && iterating_method?(name)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -41,11 +41,11 @@ module RuboCop
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def interpreter_directive_comment?(comment)
|
44
|
-
|
44
|
+
/^#\s*(frozen_string_literal|encoding):/.match?(comment.text)
|
45
45
|
end
|
46
46
|
|
47
47
|
def rubocop_directive_comment?(comment)
|
48
|
-
comment.text
|
48
|
+
CommentConfig::COMMENT_DIRECTIVE_REGEXP.match?(comment.text)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -51,7 +51,7 @@ module RuboCop
|
|
51
51
|
|
52
52
|
def accept_end_kw_alignment?(end_loc)
|
53
53
|
end_loc.nil? || # Discard modifier forms of if/while/until.
|
54
|
-
processed_source.lines[end_loc.line - 1]
|
54
|
+
!/\A[ \t]*end/.match?(processed_source.lines[end_loc.line - 1])
|
55
55
|
end
|
56
56
|
|
57
57
|
def style_parameter_name
|
@@ -152,7 +152,7 @@ module RuboCop
|
|
152
152
|
expression
|
153
153
|
end
|
154
154
|
|
155
|
-
def argument_in_method_call(node, kind)
|
155
|
+
def argument_in_method_call(node, kind) # rubocop:todo Metrics/CyclomaticComplexity
|
156
156
|
node.each_ancestor(:send, :block).find do |a|
|
157
157
|
# If the node is inside a block, it makes no difference if that block
|
158
158
|
# is an argument in a method call. It doesn't count.
|
@@ -9,8 +9,7 @@ module RuboCop
|
|
9
9
|
def parens_required?(node)
|
10
10
|
range = node.source_range
|
11
11
|
source = range.source_buffer.source
|
12
|
-
source[range.begin_pos - 1]
|
13
|
-
source[range.end_pos] =~ /[a-z]/
|
12
|
+
/[a-z]/.match?(source[range.begin_pos - 1]) || /[a-z]/.match?(source[range.end_pos])
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -109,7 +109,7 @@ module RuboCop
|
|
109
109
|
|
110
110
|
def move_pos(src, pos, step, condition, regexp)
|
111
111
|
offset = step == -1 ? -1 : 0
|
112
|
-
pos += step while condition && src[pos + offset]
|
112
|
+
pos += step while condition && regexp.match?(src[pos + offset])
|
113
113
|
pos.negative? ? 0 : pos
|
114
114
|
end
|
115
115
|
end
|
@@ -11,6 +11,33 @@ module RuboCop
|
|
11
11
|
|
12
12
|
regopt.children.include?(:x)
|
13
13
|
end
|
14
|
+
|
15
|
+
def pattern_source(node)
|
16
|
+
freespace_mode = freespace_mode_regexp?(node)
|
17
|
+
|
18
|
+
node.children.reject(&:regopt_type?).map do |child|
|
19
|
+
source_with_comments_and_interpolations_blanked(child, freespace_mode)
|
20
|
+
end.join
|
21
|
+
end
|
22
|
+
|
23
|
+
def source_with_comments_and_interpolations_blanked(child, freespace_mode)
|
24
|
+
source = child.source
|
25
|
+
|
26
|
+
# We don't want to consider the contents of interpolations or free-space mode comments as
|
27
|
+
# part of the pattern source, but need to preserve their width, to allow offsets to
|
28
|
+
# correctly line up with the original source: spaces have no effect, and preserve width.
|
29
|
+
if child.begin_type?
|
30
|
+
replace_match_with_spaces(source, /.*/) # replace all content
|
31
|
+
elsif freespace_mode
|
32
|
+
replace_match_with_spaces(source, /(?<!\\)#.*/) # replace any comments
|
33
|
+
else
|
34
|
+
source
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def replace_match_with_spaces(source, pattern)
|
39
|
+
source.sub(pattern) { ' ' * Regexp.last_match[0].length }
|
40
|
+
end
|
14
41
|
end
|
15
42
|
end
|
16
43
|
end
|
@@ -87,15 +87,15 @@ module RuboCop
|
|
87
87
|
return false unless token
|
88
88
|
|
89
89
|
if side == :left
|
90
|
-
String(token.space_after?)
|
90
|
+
SINGLE_SPACE_REGEXP.match?(String(token.space_after?))
|
91
91
|
else
|
92
|
-
String(token.space_before?)
|
92
|
+
SINGLE_SPACE_REGEXP.match?(String(token.space_before?))
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
96
|
def reposition(src, pos, step)
|
97
97
|
offset = step == -1 ? -1 : 0
|
98
|
-
pos += step while src[pos + offset]
|
98
|
+
pos += step while SINGLE_SPACE_REGEXP.match?(src[pos + offset])
|
99
99
|
pos.negative? ? 0 : pos
|
100
100
|
end
|
101
101
|
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
# If there is any heredoc in items, then match the comma succeeding
|
32
32
|
# any whitespace (except newlines), otherwise allow for newlines
|
33
33
|
comma_regex = any_heredoc?(items) ? /\A[^\S\n]*,/ : /\A\s*,/
|
34
|
-
range.source
|
34
|
+
comma_regex.match?(range.source) && range.source.index(',')
|
35
35
|
end
|
36
36
|
|
37
37
|
def check_comma(node, kind, comma_pos)
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def uppercase?(name)
|
47
|
-
|
47
|
+
/[[:upper:]]/.match?(name)
|
48
48
|
end
|
49
49
|
|
50
50
|
def name_type(node)
|
@@ -62,7 +62,7 @@ module RuboCop
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def ends_with_num?(name)
|
65
|
-
name[-1]
|
65
|
+
/\d/.match?(name[-1])
|
66
66
|
end
|
67
67
|
|
68
68
|
def length_offense(node, range)
|
@@ -123,10 +123,9 @@ module RuboCop
|
|
123
123
|
# special handling for Action Pack Variants file names like
|
124
124
|
# some_file.xlsx+mobile.axlsx
|
125
125
|
basename = basename.sub('+', '_')
|
126
|
-
basename
|
126
|
+
basename.match?(regex || SNAKE_CASE)
|
127
127
|
end
|
128
128
|
|
129
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
130
129
|
def find_class_or_module(node, namespace)
|
131
130
|
return nil unless node
|
132
131
|
|
@@ -145,7 +144,6 @@ module RuboCop
|
|
145
144
|
|
146
145
|
nil
|
147
146
|
end
|
148
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
149
147
|
|
150
148
|
def match_namespace(node, namespace, expected)
|
151
149
|
match_partial = partial_matcher!(expected)
|
@@ -245,14 +245,13 @@ module RuboCop
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def whitespace_before?(range)
|
248
|
-
range.source_buffer.source[range.begin_pos - 1, 1]
|
248
|
+
/\s/.match?(range.source_buffer.source[range.begin_pos - 1, 1])
|
249
249
|
end
|
250
250
|
|
251
251
|
def whitespace_after?(range, length = 1)
|
252
|
-
range.source_buffer.source[range.begin_pos + length, 1]
|
252
|
+
/\s/.match?(range.source_buffer.source[range.begin_pos + length, 1])
|
253
253
|
end
|
254
254
|
|
255
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
256
255
|
def get_blocks(node, &block)
|
257
256
|
case node.type
|
258
257
|
when :block
|
@@ -270,7 +269,6 @@ module RuboCop
|
|
270
269
|
node.each_child_node { |child| get_blocks(child, &block) }
|
271
270
|
end
|
272
271
|
end
|
273
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
274
272
|
|
275
273
|
def proper_block_style?(node)
|
276
274
|
return special_method_proper_block_style?(node) if special_method?(node.method_name)
|
@@ -55,8 +55,8 @@ module RuboCop
|
|
55
55
|
|
56
56
|
def offensive?(comment)
|
57
57
|
line = line(comment)
|
58
|
-
KEYWORDS.any? { |word|
|
59
|
-
ALLOWED_COMMENTS.none? { |c|
|
58
|
+
KEYWORDS.any? { |word| /^\s*#{word}\s/.match?(line) } &&
|
59
|
+
ALLOWED_COMMENTS.none? { |c| /#\s*#{c}/.match?(line) }
|
60
60
|
end
|
61
61
|
|
62
62
|
def message(comment)
|
@@ -67,7 +67,7 @@ module RuboCop
|
|
67
67
|
|
68
68
|
private
|
69
69
|
|
70
|
-
def expand_elsif(node, elsif_branches = [])
|
70
|
+
def expand_elsif(node, elsif_branches = []) # rubocop:todo Metrics/CyclomaticComplexity
|
71
71
|
return [] if node.nil? || !node.if_type? || !node.elsif?
|
72
72
|
|
73
73
|
elsif_branches << node.if_branch
|
@@ -72,14 +72,14 @@ module RuboCop
|
|
72
72
|
return false if token_index >= processed_source.tokens.size
|
73
73
|
|
74
74
|
token = processed_source.tokens[token_index]
|
75
|
-
token.comment? && token.text
|
75
|
+
token.comment? && /^#!.*$/.match?(token.text)
|
76
76
|
end
|
77
77
|
|
78
78
|
def encoding_token?(processed_source, token_index)
|
79
79
|
return false if token_index >= processed_source.tokens.size
|
80
80
|
|
81
81
|
token = processed_source.tokens[token_index]
|
82
|
-
token.comment? &&
|
82
|
+
token.comment? && /^#.*coding\s?[:=]\s?(?:UTF|utf)-8/.match?(token.text)
|
83
83
|
end
|
84
84
|
|
85
85
|
def notice_found?(processed_source)
|
@@ -88,7 +88,7 @@ module RuboCop
|
|
88
88
|
processed_source.each_token do |token|
|
89
89
|
break unless token.comment?
|
90
90
|
|
91
|
-
notice_found =
|
91
|
+
notice_found = notice_regexp.match?(token.text)
|
92
92
|
break if notice_found
|
93
93
|
end
|
94
94
|
notice_found
|
@@ -104,7 +104,7 @@ module RuboCop
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def compact_namespace?(node)
|
107
|
-
node.loc.name.source
|
107
|
+
/::/.match?(node.loc.name.source)
|
108
108
|
end
|
109
109
|
|
110
110
|
# First checks if the :nodoc: comment is associated with the
|
@@ -123,7 +123,7 @@ module RuboCop
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def nodoc?(comment, require_all = false)
|
126
|
-
|
126
|
+
/^#\s*:nodoc:#{"\s+all\s*$" if require_all}/.match?(comment.text)
|
127
127
|
end
|
128
128
|
|
129
129
|
def nodoc(node)
|
@@ -43,13 +43,15 @@ module RuboCop
|
|
43
43
|
|
44
44
|
def on_case(case_node)
|
45
45
|
return if case_node.condition
|
46
|
-
return if case_node.when_branches.any? do |when_branch|
|
47
|
-
when_branch.each_descendant.any?(&:return_type?)
|
48
|
-
end
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
branch_bodies = [
|
48
|
+
*case_node.when_branches.map(&:body),
|
49
|
+
case_node.else_branch
|
50
|
+
].compact
|
51
|
+
|
52
|
+
return if branch_bodies.any? do |body|
|
53
|
+
body.return_type? ||
|
54
|
+
body.each_descendant.any?(&:return_type?)
|
53
55
|
end
|
54
56
|
|
55
57
|
add_offense(case_node, location: :keyword)
|
@@ -69,7 +69,7 @@ module RuboCop
|
|
69
69
|
|
70
70
|
def scientific?(node)
|
71
71
|
mantissa, = node.source.split('e')
|
72
|
-
|
72
|
+
/^-?[1-9](\.\d*[0-9])?$/.match?(mantissa)
|
73
73
|
end
|
74
74
|
|
75
75
|
def engineering?(node)
|
@@ -85,7 +85,7 @@ module RuboCop
|
|
85
85
|
|
86
86
|
def integral(node)
|
87
87
|
mantissa, = node.source.split('e')
|
88
|
-
|
88
|
+
/^-?[1-9](\d*[1-9])?$/.match?(mantissa)
|
89
89
|
end
|
90
90
|
|
91
91
|
def offense?(node)
|