rubocop 1.28.2 → 1.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/config/default.yml +21 -6
  4. data/lib/rubocop/cop/badge.rb +1 -1
  5. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  6. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  7. data/lib/rubocop/cop/gemspec/dependency_version.rb +156 -0
  8. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -6
  9. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
  10. data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +80 -0
  11. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  12. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  13. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +1 -1
  14. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  15. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
  16. data/lib/rubocop/cop/layout/trailing_empty_lines.rb +1 -1
  17. data/lib/rubocop/cop/lint/ambiguous_range.rb +2 -2
  18. data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -3
  19. data/lib/rubocop/cop/lint/loop.rb +1 -1
  20. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -1
  21. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
  22. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  23. data/lib/rubocop/cop/lint/raise_exception.rb +1 -1
  24. data/lib/rubocop/cop/lint/return_in_void_context.rb +5 -17
  25. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  26. data/lib/rubocop/cop/mixin/duplication.rb +1 -1
  27. data/lib/rubocop/cop/mixin/preferred_delimiters.rb +2 -2
  28. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
  29. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  30. data/lib/rubocop/cop/naming/block_forwarding.rb +1 -1
  31. data/lib/rubocop/cop/naming/file_name.rb +1 -1
  32. data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
  33. data/lib/rubocop/cop/naming/variable_name.rb +9 -0
  34. data/lib/rubocop/cop/naming/variable_number.rb +10 -0
  35. data/lib/rubocop/cop/security/yaml_load.rb +1 -1
  36. data/lib/rubocop/cop/style/alias.rb +3 -3
  37. data/lib/rubocop/cop/style/and_or.rb +1 -1
  38. data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +1 -1
  39. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  40. data/lib/rubocop/cop/style/character_literal.rb +1 -1
  41. data/lib/rubocop/cop/style/collection_compact.rb +3 -3
  42. data/lib/rubocop/cop/style/date_time.rb +1 -1
  43. data/lib/rubocop/cop/style/double_negation.rb +28 -2
  44. data/lib/rubocop/cop/style/empty_case_condition.rb +1 -1
  45. data/lib/rubocop/cop/style/empty_literal.rb +1 -1
  46. data/lib/rubocop/cop/style/env_home.rb +56 -0
  47. data/lib/rubocop/cop/style/fetch_env_var.rb +238 -11
  48. data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -2
  49. data/lib/rubocop/cop/style/map_to_hash.rb +0 -3
  50. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  51. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -1
  52. data/lib/rubocop/cop/style/next.rb +1 -1
  53. data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
  54. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +1 -1
  55. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
  56. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  57. data/lib/rubocop/cop/style/redundant_condition.rb +77 -7
  58. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
  59. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
  60. data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -2
  61. data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
  62. data/lib/rubocop/cop/style/slicing_with_range.rb +0 -3
  63. data/lib/rubocop/cop/style/string_chars.rb +1 -1
  64. data/lib/rubocop/cop/style/trivial_accessors.rb +7 -8
  65. data/lib/rubocop/cops_documentation_generator.rb +1 -1
  66. data/lib/rubocop/formatter/formatter_set.rb +1 -0
  67. data/lib/rubocop/formatter/html_formatter.rb +2 -9
  68. data/lib/rubocop/formatter/markdown_formatter.rb +76 -0
  69. data/lib/rubocop/magic_comment.rb +4 -3
  70. data/lib/rubocop/options.rb +4 -3
  71. data/lib/rubocop/result_cache.rb +1 -1
  72. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  73. data/lib/rubocop/rspec/parallel_formatter.rb +1 -1
  74. data/lib/rubocop/rspec/shared_contexts.rb +1 -5
  75. data/lib/rubocop/runner.rb +1 -1
  76. data/lib/rubocop/string_interpreter.rb +4 -4
  77. data/lib/rubocop/target_ruby.rb +8 -2
  78. data/lib/rubocop/version.rb +1 -1
  79. data/lib/rubocop.rb +3 -1
  80. metadata +17 -8
  81. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -45
@@ -185,7 +185,7 @@ module RuboCop
185
185
  end
186
186
 
187
187
  def end_followed_by_whitespace_only?(source_buffer, end_pos)
188
- /\A\s*$/.match?(source_buffer.source[end_pos..-1])
188
+ /\A\s*$/.match?(source_buffer.source[end_pos..])
189
189
  end
190
190
 
191
191
  def reindentable_lines(node)
@@ -8,7 +8,7 @@ module RuboCop
8
8
  #
9
9
  # @safety
10
10
  # This cop is unsafe because changing a method signature will
11
- # implicitly change behaviour.
11
+ # implicitly change behavior.
12
12
  #
13
13
  # @example
14
14
  # # bad
@@ -9,7 +9,7 @@ module RuboCop
9
9
  #
10
10
  # @safety
11
11
  # This cop is unsafe because changing a method signature will
12
- # implicitly change behaviour.
12
+ # implicitly change behavior.
13
13
  #
14
14
  # @example
15
15
  # # bad
@@ -116,7 +116,7 @@ module RuboCop
116
116
  def wrong_quotes?(node)
117
117
  return super if hash_key?(node)
118
118
 
119
- super(node.source[1..-1])
119
+ super(node.source[1..])
120
120
  end
121
121
  end
122
122
  end
@@ -80,7 +80,7 @@ module RuboCop
80
80
  return node.source if message_nodes.size > 1
81
81
 
82
82
  argument = message_nodes.first.source
83
- exception_class = exception_node.const_name || exception_node.receiver.source
83
+ exception_class = exception_node.receiver&.source || exception_node.source
84
84
 
85
85
  if node.parent && requires_parens?(node.parent)
86
86
  "#{node.method_name}(#{exception_class}.new(#{argument}))"
@@ -73,13 +73,12 @@ module RuboCop
73
73
  end
74
74
 
75
75
  def offense?(node)
76
- condition, if_branch, else_branch = *node
76
+ _condition, _if_branch, else_branch = *node
77
77
 
78
78
  return false if use_if_branch?(else_branch) || use_hash_key_assignment?(else_branch)
79
79
 
80
- condition == if_branch && !node.elsif? && (
81
- node.ternary? || !else_branch.instance_of?(AST::Node) || else_branch.single_line?
82
- )
80
+ synonymous_condition_and_branch?(node) && !node.elsif? &&
81
+ (node.ternary? || !else_branch.instance_of?(AST::Node) || else_branch.single_line?)
83
82
  end
84
83
 
85
84
  def use_if_branch?(else_branch)
@@ -90,16 +89,87 @@ module RuboCop
90
89
  else_branch&.send_type? && else_branch&.method?(:[]=)
91
90
  end
92
91
 
92
+ def synonymous_condition_and_branch?(node)
93
+ condition, if_branch, _else_branch = *node
94
+ # e.g.
95
+ # if var
96
+ # var
97
+ # else
98
+ # 'foo'
99
+ # end
100
+ return true if condition == if_branch
101
+
102
+ # e.g.
103
+ # if foo
104
+ # @value = foo
105
+ # else
106
+ # @value = another_value?
107
+ # end
108
+ return true if branches_have_assignment?(node) && condition == if_branch.expression
109
+
110
+ # e.g.
111
+ # if foo
112
+ # test.value = foo
113
+ # else
114
+ # test.value = another_value?
115
+ # end
116
+ branches_have_method?(node) && condition == if_branch.first_argument
117
+ end
118
+
119
+ def branches_have_assignment?(node)
120
+ _condition, if_branch, else_branch = *node
121
+
122
+ return false unless if_branch && else_branch
123
+
124
+ asgn_type?(if_branch) && (if_branch_variable_name = if_branch.name) &&
125
+ asgn_type?(else_branch) && (else_branch_variable_name = else_branch.name) &&
126
+ if_branch_variable_name == else_branch_variable_name
127
+ end
128
+
129
+ def asgn_type?(node)
130
+ node.lvasgn_type? || node.ivasgn_type? || node.cvasgn_type? || node.gvasgn_type?
131
+ end
132
+
133
+ def branches_have_method?(node)
134
+ _condition, if_branch, else_branch = *node
135
+
136
+ return false unless if_branch && else_branch
137
+
138
+ if_branch.send_type? && if_branch.arguments.count == 1 &&
139
+ else_branch.send_type? && else_branch.arguments.count == 1 &&
140
+ if_branch.method?(else_branch.method_name)
141
+ end
142
+
93
143
  def else_source(else_branch)
94
- if require_parentheses?(else_branch)
144
+ if branches_have_method?(else_branch.parent)
145
+ else_source_if_has_method(else_branch)
146
+ elsif require_parentheses?(else_branch)
95
147
  "(#{else_branch.source})"
96
148
  elsif without_argument_parentheses_method?(else_branch)
97
149
  "#{else_branch.method_name}(#{else_branch.arguments.map(&:source).join(', ')})"
150
+ elsif branches_have_assignment?(else_branch.parent)
151
+ else_source_if_has_assignment(else_branch)
98
152
  else
99
153
  else_branch.source
100
154
  end
101
155
  end
102
156
 
157
+ def else_source_if_has_method(else_branch)
158
+ if require_parentheses?(else_branch.first_argument)
159
+ "(#{else_branch.first_argument.source})"
160
+ else
161
+ else_branch.first_argument.source
162
+ end
163
+ end
164
+
165
+ def else_source_if_has_assignment(else_branch)
166
+ if require_parentheses?(else_branch.expression)
167
+ "(#{else_branch.expression.source})"
168
+ else
169
+ else_branch.expression.source
170
+ end
171
+ end
172
+
103
173
  def make_ternary_form(node)
104
174
  _condition, if_branch, else_branch = *node
105
175
  ternary_form = [if_branch.source, else_source(else_branch)].join(' || ')
@@ -127,8 +197,8 @@ module RuboCop
127
197
  end
128
198
 
129
199
  def without_argument_parentheses_method?(node)
130
- node.send_type? &&
131
- !node.arguments.empty? && !node.parenthesized? && !node.operator_method?
200
+ node.send_type? && !node.arguments.empty? &&
201
+ !node.parenthesized? && !node.operator_method? && !node.assignment_method?
132
202
  end
133
203
  end
134
204
  end
@@ -99,7 +99,7 @@ module RuboCop
99
99
  end
100
100
 
101
101
  def backslash_b?(elem)
102
- # \b's behaviour is different inside and outside of a character class, matching word
102
+ # \b's behavior is different inside and outside of a character class, matching word
103
103
  # boundaries outside but backspace (0x08) when inside.
104
104
  elem == '\b'
105
105
  end
@@ -59,7 +59,7 @@ module RuboCop
59
59
  def allowed_escape?(node, char, within_character_class)
60
60
  # Strictly speaking a few single-letter metachars are currently
61
61
  # unnecessary to "escape", e.g. i, E, F, but enumerating them is
62
- # rather difficult, and their behaviour could change over time with
62
+ # rather difficult, and their behavior could change over time with
63
63
  # different versions of Ruby so that e.g. /\i/ != /i/
64
64
  return true if /[[:alnum:]]/.match?(char)
65
65
  return true if ALLOWED_ALWAYS_ESCAPES.include?(char) || delimiter?(node, char)
@@ -67,8 +67,7 @@ module RuboCop
67
67
  alias on_gvasgn on_lvasgn
68
68
 
69
69
  def on_send(node)
70
- # TODO: Remove `Symbol#to_s` after supporting only Ruby >= 2.7.
71
- return unless node.method_name.to_s.end_with?('=')
70
+ return unless node.assignment_method?
72
71
  return unless redundant_assignment?(node)
73
72
 
74
73
  message = format(MSG, method_name: node.first_argument.method_name)
@@ -23,7 +23,7 @@ module RuboCop
23
23
  #
24
24
  # @safety
25
25
  # Autocorrection is unsafe because if a value is `false`, the resulting
26
- # code will have different behaviour or raise an error.
26
+ # code will have different behavior or raise an error.
27
27
  #
28
28
  # [source,ruby]
29
29
  # ----
@@ -27,9 +27,6 @@ module RuboCop
27
27
  # items[1..]
28
28
  class SlicingWithRange < Base
29
29
  extend AutoCorrector
30
- extend TargetRubyVersion
31
-
32
- minimum_target_ruby_version 2.6
33
30
 
34
31
  MSG = 'Prefer ary[n..] over ary[n..-1].'
35
32
  RESTRICT_ON_SEND = %i[[]].freeze
@@ -8,7 +8,7 @@ module RuboCop
8
8
  # @safety
9
9
  # This cop is unsafe because it cannot be guaranteed that the receiver
10
10
  # is actually a string. If another class has a `split` method with
11
- # different behaviour, it would be registered as a false positive.
11
+ # different behavior, it would be registered as a false positive.
12
12
  #
13
13
  # @example
14
14
  # # bad
@@ -167,8 +167,8 @@ module RuboCop
167
167
  allowed_methods.map(&:to_sym) + [:initialize]
168
168
  end
169
169
 
170
- def dsl_writer?(method_name)
171
- !method_name.to_s.end_with?('=')
170
+ def dsl_writer?(node)
171
+ !node.assignment_method?
172
172
  end
173
173
 
174
174
  def trivial_reader?(node)
@@ -180,8 +180,7 @@ module RuboCop
180
180
  end
181
181
 
182
182
  def trivial_writer?(node)
183
- looks_like_trivial_writer?(node) &&
184
- !allowed_method_name?(node) && !allowed_writer?(node.method_name)
183
+ looks_like_trivial_writer?(node) && !allowed_method_name?(node) && !allowed_writer?(node)
185
184
  end
186
185
 
187
186
  # @!method looks_like_trivial_writer?(node)
@@ -195,8 +194,8 @@ module RuboCop
195
194
  (exact_name_match? && !names_match?(node))
196
195
  end
197
196
 
198
- def allowed_writer?(method_name)
199
- allow_dsl_writers? && dsl_writer?(method_name)
197
+ def allowed_writer?(node)
198
+ allow_dsl_writers? && dsl_writer?(node)
200
199
  end
201
200
 
202
201
  def allowed_reader?(node)
@@ -206,11 +205,11 @@ module RuboCop
206
205
  def names_match?(node)
207
206
  ivar_name, = *node.body
208
207
 
209
- node.method_name.to_s.sub(/[=?]$/, '') == ivar_name[1..-1]
208
+ node.method_name.to_s.sub(/[=?]$/, '') == ivar_name[1..]
210
209
  end
211
210
 
212
211
  def trivial_accessor_kind(node)
213
- if trivial_writer?(node) && !dsl_writer?(node.method_name)
212
+ if trivial_writer?(node) && !dsl_writer?(node)
214
213
  'writer'
215
214
  elsif trivial_reader?(node)
216
215
  'reader'
@@ -246,7 +246,7 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
246
246
  end
247
247
 
248
248
  def table_of_content_for_department(department)
249
- type_title = department[0].upcase + department[1..-1]
249
+ type_title = department[0].upcase + department[1..]
250
250
  filename = "#{department_to_basename(department)}.adoc"
251
251
  content = +"=== Department xref:#{filename}[#{type_title}]\n\n"
252
252
  cops_of_department(department).each do |cop|
@@ -18,6 +18,7 @@ module RuboCop
18
18
  '[h]tml' => HTMLFormatter,
19
19
  '[j]son' => JSONFormatter,
20
20
  '[ju]nit' => JUnitFormatter,
21
+ '[m]arkdown' => MarkdownFormatter,
21
22
  '[o]ffenses' => OffenseCountFormatter,
22
23
  '[pa]cman' => PacmanFormatter,
23
24
  '[p]rogress' => ProgressFormatter,
@@ -53,14 +53,7 @@ module RuboCop
53
53
  context = ERBContext.new(files, summary)
54
54
 
55
55
  template = File.read(TEMPLATE_PATH, encoding: Encoding::UTF_8)
56
-
57
- # The following condition is workaround for until Ruby 2.6 is released.
58
- # https://github.com/ruby/ruby/commit/cc777d09f44fa909a336ba14f3aa802ffe16e010
59
- erb = if RUBY_VERSION >= '2.6'
60
- ERB.new(template, trim_mode: '-')
61
- else
62
- ERB.new(template, nil, '-')
63
- end
56
+ erb = ERB.new(template, trim_mode: '-')
64
57
  html = erb.result(context.binding)
65
58
 
66
59
  output.write html
@@ -119,7 +112,7 @@ module RuboCop
119
112
 
120
113
  def source_after_highlight(offense)
121
114
  source_line = offense.location.source_line
122
- escape(source_line[offense.highlighted_area.end_pos..-1])
115
+ escape(source_line[offense.highlighted_area.end_pos..])
123
116
  end
124
117
 
125
118
  def possible_ellipses(location)
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Formatter
5
+ # This formatter displays the report data in markdown
6
+ class MarkdownFormatter < BaseFormatter
7
+ include TextUtil
8
+ include PathUtil
9
+ attr_reader :files, :summary
10
+
11
+ def initialize(output, options = {})
12
+ super
13
+ @files = []
14
+ @summary = Struct.new(:offense_count, :inspected_files, :target_files).new(0)
15
+ end
16
+
17
+ def started(target_files)
18
+ summary.target_files = target_files
19
+ end
20
+
21
+ def file_finished(file, offenses)
22
+ files << Struct.new(:path, :offenses).new(file, offenses)
23
+ summary.offense_count += offenses.count
24
+ end
25
+
26
+ def finished(inspected_files)
27
+ summary.inspected_files = inspected_files
28
+ render_markdown
29
+ end
30
+
31
+ private
32
+
33
+ def render_markdown
34
+ n_files = pluralize(summary.inspected_files.count, 'file')
35
+ n_offenses = pluralize(summary.offense_count, 'offense', no_for_zero: true)
36
+
37
+ output.write "# RuboCop Inspection Report\n\n"
38
+ output.write "#{n_files} inspected, #{n_offenses} detected:\n\n"
39
+ write_file_messages
40
+ end
41
+
42
+ def write_file_messages
43
+ files.each do |file|
44
+ write_heading(file)
45
+ file.offenses.each do |offense|
46
+ write_context(offense)
47
+ write_code(offense)
48
+ end
49
+ end
50
+ end
51
+
52
+ def write_heading(file)
53
+ filename = relative_path(file.path)
54
+ n_offenses = pluralize(file.offenses.count, 'offense')
55
+
56
+ output.write "### #{filename} - (#{n_offenses})\n"
57
+ end
58
+
59
+ def write_context(offense)
60
+ output.write(
61
+ " * **Line # #{offense.location.line} - #{offense.severity}:** #{offense.message}\n\n"
62
+ )
63
+ end
64
+
65
+ def write_code(offense)
66
+ code = offense.location.source_line + possible_ellipses(offense.location)
67
+
68
+ output.write " ```rb\n #{code}\n ```\n\n" unless code.blank?
69
+ end
70
+
71
+ def possible_ellipses(location)
72
+ location.first_line == location.last_line ? '' : ' ...'
73
+ end
74
+ end
75
+ end
76
+ end
@@ -5,7 +5,8 @@ module RuboCop
5
5
  #
6
6
  # @abstract parent of three different magic comment handlers
7
7
  class MagicComment
8
- # @see https://git.io/vMC1C IRB's pattern for matching magic comment tokens
8
+ # IRB's pattern for matching magic comment tokens.
9
+ # @see https://github.com/ruby/ruby/blob/b4a55c1/lib/irb/magic-file.rb#L5
9
10
  TOKEN = /[[:alnum:]\-_]+/.freeze
10
11
  KEYWORDS = {
11
12
  encoding: '(?:en)?coding',
@@ -170,7 +171,7 @@ module RuboCop
170
171
  # comment.encoding # => 'ascii-8bit'
171
172
  #
172
173
  # @see https://www.gnu.org/software/emacs/manual/html_node/emacs/Specify-Coding.html
173
- # @see https://git.io/vMCXh Emacs handling in Ruby's parse.y
174
+ # @see https://github.com/ruby/ruby/blob/3f306dc/parse.y#L6873-L6892 Emacs handling in parse.y
174
175
  class EmacsComment < EditorComment
175
176
  REGEXP = /-\*-(.+)-\*-/.freeze
176
177
  FORMAT = '# -*- %s -*-'
@@ -259,7 +260,7 @@ module RuboCop
259
260
  # is the only text in the comment.
260
261
  #
261
262
  # Case-insensitive and dashes/underscores are acceptable.
262
- # @see https://git.io/vM7Mg
263
+ # @see https://github.com/ruby/ruby/blob/78b95b4/parse.y#L7134-L7138
263
264
  def extract_frozen_string_literal
264
265
  extract(/\A\s*#\s*#{KEYWORDS[:frozen_string_literal]}:\s*(#{TOKEN})\s*\z/io)
265
266
  end
@@ -239,7 +239,7 @@ module RuboCop
239
239
  # e.g. [..., '--auto-correct', ...] to :auto_correct.
240
240
  def long_opt_symbol(args)
241
241
  long_opt = args.find { |arg| arg.start_with?('--') }
242
- long_opt[2..-1].sub('[no-]', '').sub(/ .*/, '').tr('-', '_').gsub(/[\[\]]/, '').to_sym
242
+ long_opt[2..].sub('[no-]', '').sub(/ .*/, '').tr('-', '_').gsub(/[\[\]]/, '').to_sym
243
243
  end
244
244
 
245
245
  def require_feature(file)
@@ -309,7 +309,7 @@ module RuboCop
309
309
  end
310
310
 
311
311
  if display_only_fail_level_offenses_with_autocorrect?
312
- raise OptionArgumentError, '--autocorrect cannot be used with ' \
312
+ raise OptionArgumentError, '--auto-correct cannot be used with ' \
313
313
  '--display-only-fail-level-offenses'
314
314
  end
315
315
 
@@ -402,7 +402,8 @@ module RuboCop
402
402
  end
403
403
 
404
404
  def display_only_fail_level_offenses_with_autocorrect?
405
- @options[:display_only_fail_level_offenses] && @options[:autocorrect]
405
+ @options[:display_only_fail_level_offenses] &&
406
+ (@options.key?(:auto_correct) || @options.key?(:safe_auto_correct))
406
407
  end
407
408
 
408
409
  def except_syntax?
@@ -81,7 +81,7 @@ module RuboCop
81
81
  #
82
82
  # To avoid raising warn log messages on FreeBSD, we retrieve
83
83
  # the real path of the home folder.
84
- File.join(File.realpath(ENV.fetch('HOME')), '.cache')
84
+ File.join(File.realpath(Dir.home), '.cache')
85
85
  end
86
86
  File.join(root, 'rubocop_cache')
87
87
  end
@@ -6,7 +6,7 @@ require 'tempfile'
6
6
  module CopHelper
7
7
  extend RSpec::SharedContext
8
8
 
9
- let(:ruby_version) { 2.5 }
9
+ let(:ruby_version) { 2.6 }
10
10
  let(:rails_version) { false }
11
11
 
12
12
  def inspect_source(source, file = nil)
@@ -65,7 +65,7 @@ module RuboCop
65
65
  # removed!
66
66
  def output_rerun_commands(summary)
67
67
  output.puts '# RERUN BEGIN'
68
- output.puts summary.colorized_rerun_commands.lines[3..-1].join
68
+ output.puts summary.colorized_rerun_commands.lines[3..].join
69
69
  output.puts '# RERUN END'
70
70
  end
71
71
 
@@ -5,7 +5,7 @@ require 'tmpdir'
5
5
  RSpec.shared_context 'isolated environment', :isolated_environment do
6
6
  around do |example|
7
7
  Dir.mktmpdir do |tmpdir|
8
- original_home = ENV.fetch('HOME', nil)
8
+ original_home = Dir.home
9
9
  original_xdg_config_home = ENV.fetch('XDG_CONFIG_HOME', nil)
10
10
 
11
11
  # Make sure to expand all symlinks in the path first. Otherwise we may
@@ -116,10 +116,6 @@ RSpec.shared_context 'mock console output' do
116
116
  end
117
117
  end
118
118
 
119
- RSpec.shared_context 'ruby 2.5', :ruby25 do
120
- let(:ruby_version) { 2.5 }
121
- end
122
-
123
119
  RSpec.shared_context 'ruby 2.6', :ruby26 do
124
120
  let(:ruby_version) { 2.6 }
125
121
  end
@@ -13,7 +13,7 @@ module RuboCop
13
13
 
14
14
  def initialize(path, offenses_by_iteration, loop_start: -1)
15
15
  @offenses = offenses_by_iteration.flatten.uniq
16
- root_cause = offenses_by_iteration[loop_start..-1]
16
+ root_cause = offenses_by_iteration[loop_start..]
17
17
  .map { |x| x.map(&:cop_name).uniq.join(', ') }
18
18
  .join(' -> ')
19
19
 
@@ -42,18 +42,18 @@ module RuboCop
42
42
 
43
43
  def interpret_unicode(escape)
44
44
  if escape[2] == '{'
45
- escape[3..-1].split(/\s+/).map(&:hex).pack('U*')
45
+ escape[3..].split(/\s+/).map(&:hex).pack('U*')
46
46
  else
47
- [escape[2..-1].hex].pack('U')
47
+ [escape[2..].hex].pack('U')
48
48
  end
49
49
  end
50
50
 
51
51
  def interpret_hex(escape)
52
- [escape[2..-1].hex].pack('C')
52
+ [escape[2..].hex].pack('C')
53
53
  end
54
54
 
55
55
  def interpret_octal(escape)
56
- [escape[1..-1].to_i(8)].pack('C')
56
+ [escape[1..].to_i(8)].pack('C')
57
57
  end
58
58
  end
59
59
  end
@@ -4,11 +4,17 @@ module RuboCop
4
4
  # The kind of Ruby that code inspected by RuboCop is written in.
5
5
  # @api private
6
6
  class TargetRuby
7
- KNOWN_RUBIES = [2.5, 2.6, 2.7, 3.0, 3.1, 3.2].freeze
7
+ KNOWN_RUBIES = [2.6, 2.7, 3.0, 3.1, 3.2].freeze
8
8
  DEFAULT_VERSION = KNOWN_RUBIES.first
9
9
 
10
10
  OBSOLETE_RUBIES = {
11
- 1.9 => '0.41', 2.0 => '0.50', 2.1 => '0.57', 2.2 => '0.68', 2.3 => '0.81', 2.4 => '1.12'
11
+ 1.9 => '0.41',
12
+ 2.0 => '0.50',
13
+ 2.1 => '0.57',
14
+ 2.2 => '0.68',
15
+ 2.3 => '0.81',
16
+ 2.4 => '1.12',
17
+ 2.5 => '1.28'
12
18
  }.freeze
13
19
  private_constant :KNOWN_RUBIES, :OBSOLETE_RUBIES
14
20
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.28.2'
6
+ STRING = '1.29.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
data/lib/rubocop.rb CHANGED
@@ -161,6 +161,7 @@ require_relative 'rubocop/cop/bundler/insecure_protocol_source'
161
161
  require_relative 'rubocop/cop/bundler/ordered_gems'
162
162
 
163
163
  require_relative 'rubocop/cop/gemspec/date_assignment'
164
+ require_relative 'rubocop/cop/gemspec/dependency_version'
164
165
  require_relative 'rubocop/cop/gemspec/duplicated_assignment'
165
166
  require_relative 'rubocop/cop/gemspec/ordered_dependencies'
166
167
  require_relative 'rubocop/cop/gemspec/require_mfa'
@@ -385,7 +386,6 @@ require_relative 'rubocop/cop/lint/uri_escape_unescape'
385
386
  require_relative 'rubocop/cop/lint/uri_regexp'
386
387
  require_relative 'rubocop/cop/lint/useless_access_modifier'
387
388
  require_relative 'rubocop/cop/lint/useless_assignment'
388
- require_relative 'rubocop/cop/lint/useless_else_without_rescue'
389
389
  require_relative 'rubocop/cop/lint/useless_method_definition'
390
390
  require_relative 'rubocop/cop/lint/useless_ruby2_keywords'
391
391
  require_relative 'rubocop/cop/lint/useless_setter_call'
@@ -480,6 +480,7 @@ require_relative 'rubocop/cop/style/empty_method'
480
480
  require_relative 'rubocop/cop/style/endless_method'
481
481
  require_relative 'rubocop/cop/style/encoding'
482
482
  require_relative 'rubocop/cop/style/end_block'
483
+ require_relative 'rubocop/cop/style/env_home'
483
484
  require_relative 'rubocop/cop/style/eval_with_location'
484
485
  require_relative 'rubocop/cop/style/even_odd'
485
486
  require_relative 'rubocop/cop/style/expand_path_arguments'
@@ -675,6 +676,7 @@ require_relative 'rubocop/formatter/git_hub_actions_formatter'
675
676
  require_relative 'rubocop/formatter/html_formatter'
676
677
  require_relative 'rubocop/formatter/json_formatter'
677
678
  require_relative 'rubocop/formatter/junit_formatter'
679
+ require_relative 'rubocop/formatter/markdown_formatter'
678
680
  require_relative 'rubocop/formatter/offense_count_formatter'
679
681
  require_relative 'rubocop/formatter/progress_formatter'
680
682
  require_relative 'rubocop/formatter/quiet_formatter'