rubocop 0.91.0 → 0.91.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +9 -1
  4. data/lib/rubocop.rb +1 -1
  5. data/lib/rubocop/comment_config.rb +9 -5
  6. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  7. data/lib/rubocop/cop/layout/case_indentation.rb +4 -7
  8. data/lib/rubocop/cop/layout/class_structure.rb +1 -1
  9. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
  10. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +4 -13
  11. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +14 -8
  12. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +1 -1
  13. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -2
  14. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +10 -1
  15. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -2
  16. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -7
  17. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +4 -18
  18. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +2 -2
  19. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -2
  20. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +23 -3
  21. data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +2 -4
  22. data/lib/rubocop/cop/lint/identity_comparison.rb +5 -3
  23. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -5
  24. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +22 -12
  25. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -4
  26. data/lib/rubocop/cop/lint/rescue_type.rb +0 -1
  27. data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -6
  28. data/lib/rubocop/cop/lint/unreachable_loop.rb +1 -5
  29. data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -9
  30. data/lib/rubocop/cop/lint/useless_times.rb +11 -2
  31. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +25 -16
  32. data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
  33. data/lib/rubocop/cop/mixin/rescue_node.rb +1 -0
  34. data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -3
  35. data/lib/rubocop/cop/mixin/visibility_help.rb +4 -16
  36. data/lib/rubocop/cop/style/combinable_loops.rb +5 -10
  37. data/lib/rubocop/cop/style/commented_keyword.rb +7 -8
  38. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +15 -6
  39. data/lib/rubocop/cop/style/if_unless_modifier.rb +0 -4
  40. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -6
  41. data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -2
  42. data/lib/rubocop/cop/style/multiline_when_then.rb +1 -0
  43. data/lib/rubocop/cop/style/one_line_conditional.rb +3 -1
  44. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +3 -0
  45. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  46. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -9
  47. data/lib/rubocop/cop/style/redundant_conditional.rb +4 -5
  48. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -3
  49. data/lib/rubocop/cop/style/redundant_percent_q.rb +9 -11
  50. data/lib/rubocop/cop/style/redundant_return.rb +17 -17
  51. data/lib/rubocop/cop/style/redundant_self.rb +7 -9
  52. data/lib/rubocop/cop/style/redundant_sort.rb +13 -24
  53. data/lib/rubocop/cop/style/redundant_sort_by.rb +5 -9
  54. data/lib/rubocop/cop/style/rescue_standard_error.rb +20 -16
  55. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -2
  56. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +4 -3
  57. data/lib/rubocop/cop/util.rb +0 -1
  58. data/lib/rubocop/directive_comment.rb +32 -0
  59. data/lib/rubocop/version.rb +1 -1
  60. metadata +3 -3
  61. data/lib/rubocop/cop/tokens_util.rb +0 -84
@@ -211,8 +211,7 @@ module RuboCop
211
211
  end
212
212
 
213
213
  def whitespace_after?(node)
214
- index = index_of_last_token(node)
215
- last_token = processed_source.tokens[index]
214
+ last_token = processed_source.last_token_of(node)
216
215
  last_token.space_after?
217
216
  end
218
217
  end
@@ -76,12 +76,13 @@ module RuboCop
76
76
  end
77
77
 
78
78
  def argument_tokens(node)
79
- pipes = tokens(node).select { |token| token.type == :tPIPE }
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(node).index(pipe)
82
+ tokens.index(pipe)
82
83
  end
83
84
 
84
- tokens(node)[begin_pos + 1..end_pos - 1]
85
+ tokens[begin_pos + 1..end_pos - 1]
85
86
  end
86
87
  end
87
88
  end
@@ -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
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.91.0'
6
+ STRING = '0.91.1'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
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.0
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-15 00:00:00.000000000 Z
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