rubocop-minitest 0.10.0 → 0.11.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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +18 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +5 -1
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +8 -7
- data/CHANGELOG.md +90 -49
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +18 -2
- data/Rakefile +1 -1
- data/bin/console +2 -0
- data/config/default.yml +10 -4
- data/docs/antora.yml +1 -1
- data/docs/modules/ROOT/pages/cops.adoc +13 -1
- data/docs/modules/ROOT/pages/cops_minitest.adoc +47 -8
- data/docs/modules/ROOT/pages/index.adoc +1 -1
- data/legacy-docs/cops_minitest.md +16 -16
- data/legacy-docs/index.md +1 -1
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +9 -8
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +2 -0
- data/lib/rubocop/cop/minitest/assert_nil.rb +1 -0
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +1 -0
- data/lib/rubocop/cop/minitest/assert_truthy.rb +1 -0
- data/lib/rubocop/cop/minitest/assert_with_expected_argument.rb +41 -0
- data/lib/rubocop/cop/minitest/global_expectations.rb +2 -0
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +1 -0
- data/lib/rubocop/cop/minitest/refute_equal.rb +2 -1
- data/lib/rubocop/cop/minitest/refute_false.rb +1 -0
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +2 -0
- data/lib/rubocop/cop/minitest/refute_nil.rb +1 -0
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +1 -0
- data/lib/rubocop/cop/minitest/test_method_name.rb +10 -1
- data/lib/rubocop/cop/minitest_cops.rb +1 -0
- data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +2 -1
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +14 -1
- data/lib/rubocop/minitest/version.rb +8 -1
- data/mkdocs.yml +2 -2
- data/relnotes/v0.1.0.md +1 -1
- data/relnotes/v0.10.0.md +12 -12
- data/relnotes/v0.10.1.md +5 -0
- data/relnotes/v0.10.2.md +5 -0
- data/relnotes/v0.10.3.md +5 -0
- data/relnotes/v0.11.0.md +16 -0
- data/relnotes/v0.11.1.md +5 -0
- data/relnotes/v0.2.0.md +4 -4
- data/relnotes/v0.2.1.md +1 -1
- data/relnotes/v0.3.0.md +6 -6
- data/relnotes/v0.4.0.md +5 -5
- data/relnotes/v0.4.1.md +1 -1
- data/relnotes/v0.5.0.md +1 -1
- data/relnotes/v0.5.1.md +1 -1
- data/relnotes/v0.6.0.md +1 -1
- data/relnotes/v0.6.1.md +2 -2
- data/relnotes/v0.6.2.md +1 -1
- data/relnotes/v0.7.0.md +5 -5
- data/relnotes/v0.8.0.md +4 -4
- data/relnotes/v0.8.1.md +1 -1
- data/relnotes/v0.9.0.md +3 -3
- data/rubocop-minitest.gemspec +6 -6
- data/tasks/cops_documentation.rake +15 -295
- data/tasks/cut_release.rake +1 -1
- metadata +26 -14
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'yard'
|
4
4
|
require 'rubocop'
|
5
5
|
require 'rubocop-minitest'
|
6
|
+
require 'rubocop/cops_documentation_generator'
|
6
7
|
|
7
8
|
YARD::Rake::YardocTask.new(:yard_for_generate_documentation) do |task|
|
8
9
|
task.files = ['lib/rubocop/cop/**/*.rb']
|
@@ -11,304 +12,23 @@ end
|
|
11
12
|
|
12
13
|
desc 'Generate docs of all cops departments'
|
13
14
|
task generate_cops_documentation: :yard_for_generate_documentation do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def cops_body(config, cop, description, examples_objects, pars)
|
19
|
-
content = h2(cop.cop_name)
|
20
|
-
content << required_ruby_version(cop)
|
21
|
-
content << properties(cop.new(config))
|
22
|
-
content << "#{description}\n"
|
23
|
-
content << examples(examples_objects) if examples_objects.count.positive?
|
24
|
-
content << configurations(pars)
|
25
|
-
content << references(config, cop)
|
26
|
-
content
|
27
|
-
end
|
28
|
-
|
29
|
-
def examples(examples_object)
|
30
|
-
examples_object.each_with_object(h3('Examples').dup) do |example, content|
|
31
|
-
content << "\n" unless content.end_with?("\n\n")
|
32
|
-
content << h4(example.name) unless example.name == ''
|
33
|
-
content << code_example(example)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def required_ruby_version(cop)
|
38
|
-
return '' unless cop.respond_to?(:required_minimum_ruby_version)
|
39
|
-
|
40
|
-
"NOTE: Required Ruby version: #{cop.required_minimum_ruby_version}\n\n"
|
41
|
-
end
|
42
|
-
|
43
|
-
# rubocop:disable Metrics/MethodLength
|
44
|
-
def properties(cop_instance)
|
45
|
-
header = [
|
46
|
-
'Enabled by default', 'Safe', 'Supports autocorrection', 'VersionAdded',
|
47
|
-
'VersionChanged'
|
48
|
-
]
|
49
|
-
autocorrect = if cop_instance.support_autocorrect?
|
50
|
-
"Yes#{' (Unsafe)' unless cop_instance.safe_autocorrect?}"
|
51
|
-
else
|
52
|
-
'No'
|
53
|
-
end
|
54
|
-
cop_config = cop_instance.cop_config
|
55
|
-
content = [[
|
56
|
-
cop_status(cop_config.fetch('Enabled')),
|
57
|
-
cop_config.fetch('Safe', true) ? 'Yes' : 'No',
|
58
|
-
autocorrect,
|
59
|
-
cop_config.fetch('VersionAdded', '-'),
|
60
|
-
cop_config.fetch('VersionChanged', '-')
|
61
|
-
]]
|
62
|
-
to_table(header, content) + "\n"
|
63
|
-
end
|
64
|
-
# rubocop:enable Metrics/MethodLength
|
65
|
-
|
66
|
-
def h2(title)
|
67
|
-
content = +"\n"
|
68
|
-
content << "== #{title}\n"
|
69
|
-
content << "\n"
|
70
|
-
content
|
71
|
-
end
|
72
|
-
|
73
|
-
def h3(title)
|
74
|
-
content = +"\n"
|
75
|
-
content << "=== #{title}\n"
|
76
|
-
content << "\n"
|
77
|
-
content
|
78
|
-
end
|
79
|
-
|
80
|
-
def h4(title)
|
81
|
-
content = +"==== #{title}\n"
|
82
|
-
content << "\n"
|
83
|
-
content
|
84
|
-
end
|
85
|
-
|
86
|
-
def code_example(ruby_code)
|
87
|
-
content = +"[source,ruby]\n----\n"
|
88
|
-
content << ruby_code.text.gsub('@good', '# good')
|
89
|
-
.gsub('@bad', '# bad').strip
|
90
|
-
content << "\n----\n"
|
91
|
-
content
|
92
|
-
end
|
93
|
-
|
94
|
-
def configurations(pars)
|
95
|
-
return '' if pars.empty?
|
96
|
-
|
97
|
-
header = ['Name', 'Default value', 'Configurable values']
|
98
|
-
configs = pars
|
99
|
-
.each_key
|
100
|
-
.reject { |key| key.start_with?('Supported') }
|
101
|
-
.reject { |key| key.start_with?('AllowMultipleStyles') }
|
102
|
-
content = configs.map do |name|
|
103
|
-
configurable = configurable_values(pars, name)
|
104
|
-
default = format_table_value(pars[name])
|
105
|
-
[name, default, configurable]
|
106
|
-
end
|
107
|
-
|
108
|
-
h3('Configurable attributes') + to_table(header, content)
|
109
|
-
end
|
110
|
-
|
111
|
-
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
112
|
-
def configurable_values(pars, name)
|
113
|
-
case name
|
114
|
-
when /^Enforced/
|
115
|
-
supported_style_name = RuboCop::Cop::Util.to_supported_styles(name)
|
116
|
-
format_table_value(pars[supported_style_name])
|
117
|
-
when 'IndentationWidth'
|
118
|
-
'Integer'
|
119
|
-
else
|
120
|
-
case pars[name]
|
121
|
-
when String
|
122
|
-
'String'
|
123
|
-
when Integer
|
124
|
-
'Integer'
|
125
|
-
when Float
|
126
|
-
'Float'
|
127
|
-
when true, false
|
128
|
-
'Boolean'
|
129
|
-
when Array
|
130
|
-
'Array'
|
131
|
-
else
|
132
|
-
''
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
137
|
-
|
138
|
-
def to_table(header, content)
|
139
|
-
table = [
|
140
|
-
'|===',
|
141
|
-
"| #{header.join(' | ')}\n\n"
|
142
|
-
].join("\n")
|
143
|
-
marked_contents = content.map do |plain_content|
|
144
|
-
plain_content.map { |c| "| #{c}" }.join("\n")
|
145
|
-
end
|
146
|
-
table << marked_contents.join("\n\n")
|
147
|
-
table << "\n|===\n"
|
148
|
-
end
|
149
|
-
|
150
|
-
def format_table_value(val)
|
151
|
-
value =
|
152
|
-
case val
|
153
|
-
when Array
|
154
|
-
if val.empty?
|
155
|
-
'`[]`'
|
156
|
-
else
|
157
|
-
val.map { |config| format_table_value(config) }.join(', ')
|
158
|
-
end
|
159
|
-
else
|
160
|
-
wrap_backtick(val.nil? ? '<none>' : val)
|
161
|
-
end
|
162
|
-
value.gsub("#{Dir.pwd}/", '').rstrip
|
163
|
-
end
|
164
|
-
|
165
|
-
def wrap_backtick(value)
|
166
|
-
if value.is_a?(String)
|
167
|
-
# Use `+` to prevent text like `**/*.gemspec` from being bold.
|
168
|
-
value.start_with?('*') ? "`+#{value}+`" : "`#{value}`"
|
169
|
-
else
|
170
|
-
"`#{value}`"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def references(config, cop)
|
175
|
-
cop_config = config.for_cop(cop)
|
176
|
-
urls = RuboCop::Cop::MessageAnnotator.new(
|
177
|
-
config, cop.name, cop_config, {}
|
178
|
-
).urls
|
179
|
-
return '' if urls.empty?
|
180
|
-
|
181
|
-
content = h3('References')
|
182
|
-
content << urls.map { |url| "* #{url}" }.join("\n")
|
183
|
-
content << "\n"
|
184
|
-
content
|
185
|
-
end
|
186
|
-
|
187
|
-
# rubocop:disable Metrics/AbcSize
|
188
|
-
def print_cops_of_department(cops, department, config)
|
189
|
-
selected_cops = cops_of_department(cops, department).select do |cop|
|
190
|
-
cop.to_s.start_with?('RuboCop::Cop::Minitest')
|
191
|
-
end
|
192
|
-
return if selected_cops.empty?
|
193
|
-
|
194
|
-
selected_cops = cops_of_department(cops, department)
|
195
|
-
content = +"= #{department}\n"
|
196
|
-
selected_cops.each do |cop|
|
197
|
-
content << print_cop_with_doc(cop, config)
|
198
|
-
end
|
199
|
-
file_name = "#{Dir.pwd}/docs/modules/ROOT/pages/cops_#{department.downcase}.adoc"
|
200
|
-
File.open(file_name, 'w') do |file|
|
201
|
-
puts "* generated #{file_name}"
|
202
|
-
file.write(content.strip + "\n")
|
203
|
-
end
|
204
|
-
end
|
205
|
-
# rubocop:enable Metrics/AbcSize
|
206
|
-
|
207
|
-
def print_cop_with_doc(cop, config)
|
208
|
-
t = config.for_cop(cop)
|
209
|
-
non_display_keys = %w[
|
210
|
-
Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded
|
211
|
-
VersionChanged
|
212
|
-
]
|
213
|
-
pars = t.reject { |k| non_display_keys.include? k }
|
214
|
-
description = 'No documentation'
|
215
|
-
examples_object = []
|
216
|
-
cop_code(cop) do |code_object|
|
217
|
-
description = code_object.docstring unless code_object.docstring.blank?
|
218
|
-
examples_object = code_object.tags('example')
|
219
|
-
end
|
220
|
-
cops_body(config, cop, description, examples_object, pars)
|
221
|
-
end
|
222
|
-
|
223
|
-
def cop_code(cop)
|
224
|
-
YARD::Registry.all(:class).detect do |code_object|
|
225
|
-
next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
|
226
|
-
|
227
|
-
yield code_object
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
# rubocop:disable Metrics/AbcSize
|
232
|
-
def table_of_content_for_department(cops, department)
|
233
|
-
selected_cops = cops_of_department(cops, department.to_sym).select do |cop|
|
234
|
-
cop.to_s.start_with?('RuboCop::Cop::Minitest')
|
235
|
-
end
|
236
|
-
return if selected_cops.empty?
|
237
|
-
|
238
|
-
type_title = department[0].upcase + department[1..-1]
|
239
|
-
filename = "cops_#{department.downcase}.adoc"
|
240
|
-
content = +"= Department xref:#{filename}[#{type_title}]\n\n"
|
241
|
-
cops_of_department(cops, department.to_sym).each do |cop|
|
242
|
-
anchor = cop.cop_name.sub('/', '').downcase
|
243
|
-
content << "* xref:#{filename}##{anchor}[#{cop.cop_name}]\n"
|
244
|
-
end
|
245
|
-
|
246
|
-
content
|
247
|
-
end
|
248
|
-
# rubocop:enable Metrics/AbcSize
|
249
|
-
|
250
|
-
def print_table_of_contents(cops)
|
251
|
-
path = "#{Dir.pwd}/docs/modules/ROOT/pages/cops.adoc"
|
252
|
-
original = File.read(path)
|
253
|
-
content = +"// START_COP_LIST\n\n"
|
254
|
-
|
255
|
-
content << table_contents(cops)
|
256
|
-
|
257
|
-
content << "\n// END_COP_LIST"
|
258
|
-
|
259
|
-
content = original.sub(
|
260
|
-
%r{// START_COP_LIST.+// END_COP_LIST}m, content
|
261
|
-
)
|
262
|
-
File.write(path, content)
|
263
|
-
end
|
264
|
-
|
265
|
-
def table_contents(cops)
|
266
|
-
cops
|
267
|
-
.departments
|
268
|
-
.map(&:to_s)
|
269
|
-
.sort
|
270
|
-
.map { |department| table_of_content_for_department(cops, department) }
|
271
|
-
.compact
|
272
|
-
.join("\n")
|
273
|
-
end
|
274
|
-
|
275
|
-
def cop_status(status)
|
276
|
-
return 'Disabled' unless status
|
277
|
-
|
278
|
-
status == 'pending' ? 'Pending' : 'Enabled'
|
279
|
-
end
|
280
|
-
|
281
|
-
def assert_docs_synchronized
|
282
|
-
# Do not print diff and yield whether exit code was zero
|
283
|
-
sh('git diff --quiet docs') do |outcome, _|
|
284
|
-
return if outcome
|
285
|
-
|
286
|
-
# Output diff before raising error
|
287
|
-
sh('GIT_PAGER=cat git diff docs')
|
288
|
-
|
289
|
-
warn 'The docs directory is out of sync. ' \
|
290
|
-
'Run `rake generate_cops_documentation` and commit the results.'
|
291
|
-
exit!
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def main
|
296
|
-
cops = RuboCop::Cop::Cop.registry
|
297
|
-
config = RuboCop::ConfigLoader.load_file('config/default.yml')
|
15
|
+
deps = ['Minitest']
|
16
|
+
CopsDocumentationGenerator.new(departments: deps).call
|
17
|
+
end
|
298
18
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
19
|
+
desc 'Verify that documentation is up to date'
|
20
|
+
task verify_cops_documentation: :generate_cops_documentation do
|
21
|
+
# Do not print diff and yield whether exit code was zero
|
22
|
+
sh('git diff --quiet docs') do |outcome, _|
|
23
|
+
exit if outcome
|
303
24
|
|
304
|
-
|
25
|
+
# Output diff before raising error
|
26
|
+
sh('GIT_PAGER=cat git diff docs')
|
305
27
|
|
306
|
-
|
307
|
-
|
308
|
-
|
28
|
+
warn 'The docs directory is out of sync. ' \
|
29
|
+
'Run `rake generate_cops_documentation` and commit the results.'
|
30
|
+
exit!
|
309
31
|
end
|
310
|
-
|
311
|
-
main
|
312
32
|
end
|
313
33
|
|
314
34
|
desc 'Syntax check for the documentation comments'
|
@@ -317,7 +37,7 @@ task documentation_syntax_check: :yard_for_generate_documentation do
|
|
317
37
|
|
318
38
|
ok = true
|
319
39
|
YARD::Registry.load!
|
320
|
-
cops = RuboCop::Cop::
|
40
|
+
cops = RuboCop::Cop::Registry.global
|
321
41
|
cops.each do |cop|
|
322
42
|
examples = YARD::Registry.all(:class).find do |code_object|
|
323
43
|
next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
|
data/tasks/cut_release.rake
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
8
8
|
- Jonas Arvidsson
|
9
9
|
- Koichi ITO
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-03-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rubocop
|
@@ -18,14 +18,20 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0.
|
21
|
+
version: '0.90'
|
22
|
+
- - "<"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '2.0'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
27
|
version_requirements: !ruby/object:Gem::Requirement
|
25
28
|
requirements:
|
26
29
|
- - ">="
|
27
30
|
- !ruby/object:Gem::Version
|
28
|
-
version: '0.
|
31
|
+
version: '0.90'
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.0'
|
29
35
|
- !ruby/object:Gem::Dependency
|
30
36
|
name: minitest
|
31
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,7 +49,7 @@ dependencies:
|
|
43
49
|
description: |
|
44
50
|
Automatic Minitest code style checking tool.
|
45
51
|
A RuboCop extension focused on enforcing Minitest best practices and coding conventions.
|
46
|
-
email:
|
52
|
+
email:
|
47
53
|
executables: []
|
48
54
|
extensions: []
|
49
55
|
extra_rdoc_files: []
|
@@ -94,6 +100,7 @@ files:
|
|
94
100
|
- lib/rubocop/cop/minitest/assert_respond_to.rb
|
95
101
|
- lib/rubocop/cop/minitest/assert_silent.rb
|
96
102
|
- lib/rubocop/cop/minitest/assert_truthy.rb
|
103
|
+
- lib/rubocop/cop/minitest/assert_with_expected_argument.rb
|
97
104
|
- lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb
|
98
105
|
- lib/rubocop/cop/minitest/global_expectations.rb
|
99
106
|
- lib/rubocop/cop/minitest/literal_as_actual_argument.rb
|
@@ -123,6 +130,11 @@ files:
|
|
123
130
|
- readthedocs.yml
|
124
131
|
- relnotes/v0.1.0.md
|
125
132
|
- relnotes/v0.10.0.md
|
133
|
+
- relnotes/v0.10.1.md
|
134
|
+
- relnotes/v0.10.2.md
|
135
|
+
- relnotes/v0.10.3.md
|
136
|
+
- relnotes/v0.11.0.md
|
137
|
+
- relnotes/v0.11.1.md
|
126
138
|
- relnotes/v0.2.0.md
|
127
139
|
- relnotes/v0.2.1.md
|
128
140
|
- relnotes/v0.3.0.md
|
@@ -140,16 +152,16 @@ files:
|
|
140
152
|
- rubocop-minitest.gemspec
|
141
153
|
- tasks/cops_documentation.rake
|
142
154
|
- tasks/cut_release.rake
|
143
|
-
homepage:
|
155
|
+
homepage:
|
144
156
|
licenses:
|
145
157
|
- MIT
|
146
158
|
metadata:
|
147
159
|
homepage_uri: https://docs.rubocop.org/rubocop-minitest/
|
148
|
-
changelog_uri: https://github.com/rubocop
|
149
|
-
source_code_uri: https://github.com/rubocop
|
150
|
-
documentation_uri: https://docs.rubocop.org/rubocop-minitest/
|
151
|
-
bug_tracker_uri: https://github.com/rubocop
|
152
|
-
post_install_message:
|
160
|
+
changelog_uri: https://github.com/rubocop/rubocop-minitest/blob/master/CHANGELOG.md
|
161
|
+
source_code_uri: https://github.com/rubocop/rubocop-minitest
|
162
|
+
documentation_uri: https://docs.rubocop.org/rubocop-minitest/0.11
|
163
|
+
bug_tracker_uri: https://github.com/rubocop/rubocop-minitest/issues
|
164
|
+
post_install_message:
|
153
165
|
rdoc_options: []
|
154
166
|
require_paths:
|
155
167
|
- lib
|
@@ -164,8 +176,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
176
|
- !ruby/object:Gem::Version
|
165
177
|
version: '0'
|
166
178
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
168
|
-
signing_key:
|
179
|
+
rubygems_version: 3.2.13
|
180
|
+
signing_key:
|
169
181
|
specification_version: 4
|
170
182
|
summary: Automatic Minitest code style checking tool.
|
171
183
|
test_files: []
|