rubocop 1.28.2 → 1.29.0
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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/config/default.yml +21 -6
- data/lib/rubocop/cop/badge.rb +1 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
- data/lib/rubocop/cop/gemspec/dependency_version.rb +156 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +3 -6
- data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/method_name_end_with.rb +80 -0
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
- data/lib/rubocop/cop/layout/trailing_empty_lines.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +2 -2
- data/lib/rubocop/cop/lint/erb_new_arguments.rb +0 -3
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +1 -1
- data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/raise_exception.rb +1 -1
- data/lib/rubocop/cop/lint/return_in_void_context.rb +5 -17
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/mixin/duplication.rb +1 -1
- data/lib/rubocop/cop/mixin/preferred_delimiters.rb +2 -2
- data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/naming/block_forwarding.rb +1 -1
- data/lib/rubocop/cop/naming/file_name.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_name.rb +2 -2
- data/lib/rubocop/cop/naming/variable_name.rb +9 -0
- data/lib/rubocop/cop/naming/variable_number.rb +10 -0
- data/lib/rubocop/cop/security/yaml_load.rb +1 -1
- data/lib/rubocop/cop/style/alias.rb +3 -3
- data/lib/rubocop/cop/style/and_or.rb +1 -1
- data/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb +1 -1
- data/lib/rubocop/cop/style/case_like_if.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/collection_compact.rb +3 -3
- data/lib/rubocop/cop/style/date_time.rb +1 -1
- data/lib/rubocop/cop/style/double_negation.rb +28 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +1 -1
- data/lib/rubocop/cop/style/env_home.rb +56 -0
- data/lib/rubocop/cop/style/fetch_env_var.rb +238 -11
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -2
- data/lib/rubocop/cop/style/map_to_hash.rb +0 -3
- data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +5 -1
- data/lib/rubocop/cop/style/next.rb +1 -1
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -1
- data/lib/rubocop/cop/style/optional_boolean_parameter.rb +1 -1
- data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
- data/lib/rubocop/cop/style/raise_args.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +77 -7
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -2
- data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
- data/lib/rubocop/cop/style/slicing_with_range.rb +0 -3
- data/lib/rubocop/cop/style/string_chars.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +7 -8
- data/lib/rubocop/cops_documentation_generator.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +1 -0
- data/lib/rubocop/formatter/html_formatter.rb +2 -9
- data/lib/rubocop/formatter/markdown_formatter.rb +76 -0
- data/lib/rubocop/magic_comment.rb +4 -3
- data/lib/rubocop/options.rb +4 -3
- data/lib/rubocop/result_cache.rb +1 -1
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/parallel_formatter.rb +1 -1
- data/lib/rubocop/rspec/shared_contexts.rb +1 -5
- data/lib/rubocop/runner.rb +1 -1
- data/lib/rubocop/string_interpreter.rb +4 -4
- data/lib/rubocop/target_ruby.rb +8 -2
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +3 -1
- metadata +17 -8
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -45
@@ -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.
|
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
|
-
|
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
|
-
|
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
|
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.
|
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
|
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
|
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
|
-
|
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)
|
@@ -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
|
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?(
|
171
|
-
!
|
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?(
|
199
|
-
allow_dsl_writers? && dsl_writer?(
|
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
|
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
|
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
|
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|
|
@@ -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
|
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
|
-
#
|
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://
|
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://
|
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
|
data/lib/rubocop/options.rb
CHANGED
@@ -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
|
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, '--
|
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] &&
|
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?
|
data/lib/rubocop/result_cache.rb
CHANGED
@@ -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(
|
84
|
+
File.join(File.realpath(Dir.home), '.cache')
|
85
85
|
end
|
86
86
|
File.join(root, 'rubocop_cache')
|
87
87
|
end
|
@@ -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
|
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 =
|
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
|
data/lib/rubocop/runner.rb
CHANGED
@@ -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
|
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
|
45
|
+
escape[3..].split(/\s+/).map(&:hex).pack('U*')
|
46
46
|
else
|
47
|
-
[escape[2
|
47
|
+
[escape[2..].hex].pack('U')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
def interpret_hex(escape)
|
52
|
-
[escape[2
|
52
|
+
[escape[2..].hex].pack('C')
|
53
53
|
end
|
54
54
|
|
55
55
|
def interpret_octal(escape)
|
56
|
-
[escape[1
|
56
|
+
[escape[1..].to_i(8)].pack('C')
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/rubocop/target_ruby.rb
CHANGED
@@ -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.
|
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',
|
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
|
|
data/lib/rubocop/version.rb
CHANGED
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'
|