rubocop 0.91.0 → 0.91.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 +1 -1
- data/config/default.yml +9 -1
- data/lib/rubocop.rb +1 -1
- data/lib/rubocop/comment_config.rb +9 -5
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +4 -7
- data/lib/rubocop/cop/layout/class_structure.rb +1 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
- data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +4 -13
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +14 -8
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +10 -1
- data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -7
- data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +4 -18
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -2
- data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -2
- data/lib/rubocop/cop/lint/constant_definition_in_block.rb +23 -3
- data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +2 -4
- data/lib/rubocop/cop/lint/identity_comparison.rb +5 -3
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -5
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +22 -12
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -4
- data/lib/rubocop/cop/lint/rescue_type.rb +0 -1
- data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -6
- data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -5
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -9
- data/lib/rubocop/cop/lint/useless_times.rb +11 -2
- data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +25 -16
- data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
- data/lib/rubocop/cop/mixin/rescue_node.rb +1 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -3
- data/lib/rubocop/cop/mixin/visibility_help.rb +4 -16
- data/lib/rubocop/cop/style/combinable_loops.rb +5 -10
- data/lib/rubocop/cop/style/commented_keyword.rb +7 -8
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +15 -6
- data/lib/rubocop/cop/style/if_unless_modifier.rb +0 -4
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -6
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -2
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -0
- data/lib/rubocop/cop/style/one_line_conditional.rb +3 -1
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +3 -0
- data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
- data/lib/rubocop/cop/style/redundant_assignment.rb +1 -9
- data/lib/rubocop/cop/style/redundant_conditional.rb +4 -5
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -3
- data/lib/rubocop/cop/style/redundant_percent_q.rb +9 -11
- data/lib/rubocop/cop/style/redundant_return.rb +17 -17
- data/lib/rubocop/cop/style/redundant_self.rb +7 -9
- data/lib/rubocop/cop/style/redundant_sort.rb +13 -24
- data/lib/rubocop/cop/style/redundant_sort_by.rb +5 -9
- data/lib/rubocop/cop/style/rescue_standard_error.rb +20 -16
- data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -2
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +4 -3
- data/lib/rubocop/cop/util.rb +0 -1
- data/lib/rubocop/directive_comment.rb +32 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +3 -3
- data/lib/rubocop/cop/tokens_util.rb +0 -84
@@ -76,12 +76,13 @@ module RuboCop
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def argument_tokens(node)
|
79
|
-
|
79
|
+
tokens = processed_source.tokens_within(node)
|
80
|
+
pipes = tokens.select { |token| token.type == :tPIPE }
|
80
81
|
begin_pos, end_pos = pipes.map do |pipe|
|
81
|
-
tokens
|
82
|
+
tokens.index(pipe)
|
82
83
|
end
|
83
84
|
|
84
|
-
tokens
|
85
|
+
tokens[begin_pos + 1..end_pos - 1]
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
data/lib/rubocop/cop/util.rb
CHANGED
@@ -5,7 +5,6 @@ module RuboCop
|
|
5
5
|
# This module contains a collection of useful utility methods.
|
6
6
|
module Util
|
7
7
|
include PathUtil
|
8
|
-
include TokensUtil
|
9
8
|
|
10
9
|
# Match literal regex characters, not including anchors, character
|
11
10
|
# classes, alternatives, groups, repetitions, references, etc
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
# This class wraps the `Parser::Source::Comment` object that represents a
|
5
|
+
# special `rubocop:disable` and `rubocop:enable` comment and exposes what
|
6
|
+
# cops it contains.
|
7
|
+
class DirectiveComment
|
8
|
+
attr_reader :comment
|
9
|
+
|
10
|
+
def initialize(comment)
|
11
|
+
@comment = comment
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return all the cops specified in the directive
|
15
|
+
def cops
|
16
|
+
match = comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
|
17
|
+
return unless match
|
18
|
+
|
19
|
+
cops_string = match.captures[1]
|
20
|
+
cops_string.split(/,\s*/).uniq.sort
|
21
|
+
end
|
22
|
+
|
23
|
+
# Checks if this directive contains all the given cop names
|
24
|
+
def match?(cop_names)
|
25
|
+
cops == cop_names.uniq.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
def range
|
29
|
+
comment.location.expression
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/rubocop/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.91.
|
4
|
+
version: 0.91.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-09-
|
13
|
+
date: 2020-09-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -744,7 +744,6 @@ files:
|
|
744
744
|
- lib/rubocop/cop/style/yoda_condition.rb
|
745
745
|
- lib/rubocop/cop/style/zero_length_predicate.rb
|
746
746
|
- lib/rubocop/cop/team.rb
|
747
|
-
- lib/rubocop/cop/tokens_util.rb
|
748
747
|
- lib/rubocop/cop/util.rb
|
749
748
|
- lib/rubocop/cop/utils/format_string.rb
|
750
749
|
- lib/rubocop/cop/variable_force.rb
|
@@ -757,6 +756,7 @@ files:
|
|
757
756
|
- lib/rubocop/cop/variable_force/variable_table.rb
|
758
757
|
- lib/rubocop/cops_documentation_generator.rb
|
759
758
|
- lib/rubocop/core_ext/string.rb
|
759
|
+
- lib/rubocop/directive_comment.rb
|
760
760
|
- lib/rubocop/error.rb
|
761
761
|
- lib/rubocop/ext/processed_source.rb
|
762
762
|
- lib/rubocop/ext/regexp_node.rb
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
# Common methods and behaviors for dealing with tokens.
|
5
|
-
module TokensUtil
|
6
|
-
module_function
|
7
|
-
|
8
|
-
# rubocop:disable Metrics/AbcSize
|
9
|
-
def tokens(node)
|
10
|
-
@tokens ||= {}
|
11
|
-
return @tokens[node.object_id] if @tokens[node.object_id]
|
12
|
-
|
13
|
-
@tokens[node.object_id] =
|
14
|
-
# The tokens list is always sorted by token position,
|
15
|
-
# except for cases when heredoc is passed as a method argument.
|
16
|
-
# In this case tokens are interleaved by heredoc contents' tokens.
|
17
|
-
# We can try a fast (binary) search, assuming the mentioned cases are rare,
|
18
|
-
# and fallback to linear search if failed.
|
19
|
-
if (tokens = fast_tokens(node))
|
20
|
-
tokens
|
21
|
-
else
|
22
|
-
begin_pos = node.source_range.begin_pos
|
23
|
-
end_pos = node.source_range.end_pos
|
24
|
-
|
25
|
-
processed_source.tokens.select do |token|
|
26
|
-
token.end_pos <= end_pos && token.begin_pos >= begin_pos
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
# rubocop:enable Metrics/AbcSize
|
31
|
-
|
32
|
-
def index_of_first_token(node)
|
33
|
-
index = fast_index_of_first_token(node)
|
34
|
-
return index if index
|
35
|
-
|
36
|
-
begin_pos = node.source_range.begin_pos
|
37
|
-
processed_source.tokens.index { |token| token.begin_pos == begin_pos }
|
38
|
-
end
|
39
|
-
|
40
|
-
def index_of_last_token(node)
|
41
|
-
index = fast_index_of_last_token(node)
|
42
|
-
return index if index
|
43
|
-
|
44
|
-
end_pos = node.source_range.end_pos
|
45
|
-
processed_source.tokens.index { |token| token.end_pos == end_pos }
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def fast_index_of_first_token(node)
|
51
|
-
begin_pos = node.source_range.begin_pos
|
52
|
-
tokens = processed_source.tokens
|
53
|
-
|
54
|
-
index = tokens.bsearch_index { |token| token.begin_pos >= begin_pos }
|
55
|
-
index if index && tokens[index].begin_pos == begin_pos
|
56
|
-
end
|
57
|
-
|
58
|
-
def fast_index_of_last_token(node)
|
59
|
-
end_pos = node.source_range.end_pos
|
60
|
-
tokens = processed_source.tokens
|
61
|
-
|
62
|
-
index = tokens.bsearch_index { |token| token.end_pos >= end_pos }
|
63
|
-
index if index && tokens[index].end_pos == end_pos
|
64
|
-
end
|
65
|
-
|
66
|
-
def fast_tokens(node)
|
67
|
-
begin_index = index_of_first_token(node)
|
68
|
-
end_index = index_of_last_token(node)
|
69
|
-
|
70
|
-
tokens = processed_source.tokens[begin_index..end_index]
|
71
|
-
tokens if sorted_tokens?(tokens)
|
72
|
-
end
|
73
|
-
|
74
|
-
def sorted_tokens?(tokens)
|
75
|
-
prev_begin_pos = -1
|
76
|
-
tokens.each do |token|
|
77
|
-
return false if token.begin_pos < prev_begin_pos
|
78
|
-
|
79
|
-
prev_begin_pos = token.begin_pos
|
80
|
-
end
|
81
|
-
true
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|