rubocop-minitest 0.8.0 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +15 -3
- data/.rubocop.yml +3 -1
- data/.rubocop_todo.yml +7 -13
- data/CHANGELOG.md +52 -0
- data/Gemfile +1 -1
- data/README.md +18 -2
- data/Rakefile +29 -0
- data/config/default.yml +96 -16
- data/docs/antora.yml +7 -0
- data/docs/modules/ROOT/nav.adoc +6 -0
- data/docs/modules/ROOT/pages/cops.adoc +48 -0
- data/docs/modules/ROOT/pages/cops_minitest.adoc +1014 -0
- data/docs/modules/ROOT/pages/index.adoc +5 -0
- data/docs/modules/ROOT/pages/installation.adoc +15 -0
- data/docs/modules/ROOT/pages/usage.adoc +32 -0
- data/{manual → legacy-docs}/cops.md +0 -0
- data/{manual → legacy-docs}/cops_minitest.md +0 -0
- data/{manual → legacy-docs}/index.md +0 -0
- data/{manual → legacy-docs}/installation.md +0 -0
- data/{manual → legacy-docs}/usage.md +0 -0
- data/lib/rubocop/cop/generator.rb +56 -0
- data/lib/rubocop/cop/minitest/assert_empty_literal.rb +15 -0
- data/lib/rubocop/cop/minitest/assert_in_delta.rb +27 -0
- data/lib/rubocop/cop/minitest/assert_kind_of.rb +25 -0
- data/lib/rubocop/cop/minitest/assert_output.rb +49 -0
- data/lib/rubocop/cop/minitest/assert_path_exists.rb +58 -0
- data/lib/rubocop/cop/minitest/assert_silent.rb +45 -0
- data/lib/rubocop/cop/minitest/assertion_in_lifecycle_hook.rb +43 -0
- data/lib/rubocop/cop/minitest/global_expectations.rb +27 -13
- data/lib/rubocop/cop/minitest/literal_as_actual_argument.rb +52 -0
- data/lib/rubocop/cop/minitest/multiple_assertions.rb +63 -0
- data/lib/rubocop/cop/minitest/refute_equal.rb +1 -1
- data/lib/rubocop/cop/minitest/refute_in_delta.rb +27 -0
- data/lib/rubocop/cop/minitest/refute_kind_of.rb +25 -0
- data/lib/rubocop/cop/minitest/refute_path_exists.rb +58 -0
- data/lib/rubocop/cop/minitest/test_method_name.rb +70 -0
- data/lib/rubocop/cop/minitest/unspecified_exception.rb +36 -0
- data/lib/rubocop/cop/minitest_cops.rb +15 -0
- data/lib/rubocop/cop/mixin/argument_range_helper.rb +10 -0
- data/lib/rubocop/cop/mixin/in_delta_mixin.rb +50 -0
- data/lib/rubocop/cop/mixin/minitest_cop_rule.rb +2 -4
- data/lib/rubocop/cop/mixin/minitest_exploration_helpers.rb +84 -0
- data/lib/rubocop/minitest/version.rb +8 -1
- data/mkdocs.yml +2 -2
- data/relnotes/v0.10.0.md +21 -0
- data/relnotes/v0.10.1.md +5 -0
- data/relnotes/v0.10.2.md +5 -0
- data/relnotes/v0.8.1.md +5 -0
- data/relnotes/v0.9.0.md +10 -0
- data/rubocop-minitest.gemspec +5 -5
- data/tasks/cops_documentation.rake +15 -264
- data/tasks/cut_release.rake +16 -0
- metadata +52 -18
@@ -22,9 +22,7 @@ module RuboCop
|
|
22
22
|
# @param inverse [Boolean] An optional param. Order of arguments replaced by auto-correction.
|
23
23
|
#
|
24
24
|
def define_rule(assertion_method, target_method:, preferred_method: nil, inverse: false)
|
25
|
-
if preferred_method.nil?
|
26
|
-
preferred_method = "#{assertion_method}_#{target_method.to_s.delete('?')}"
|
27
|
-
end
|
25
|
+
preferred_method = "#{assertion_method}_#{target_method.to_s.delete('?')}" if preferred_method.nil?
|
28
26
|
|
29
27
|
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
|
30
28
|
include ArgumentRangeHelper
|
@@ -59,7 +57,7 @@ module RuboCop
|
|
59
57
|
private
|
60
58
|
|
61
59
|
def peel_redundant_parentheses_from(arguments)
|
62
|
-
return arguments unless arguments.first
|
60
|
+
return arguments unless arguments.first&.begin_type?
|
63
61
|
|
64
62
|
peel_redundant_parentheses_from(arguments.first.children)
|
65
63
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Cop
|
7
|
+
# Helper methods for different explorations against test files and test cases.
|
8
|
+
module MinitestExplorationHelpers
|
9
|
+
extend NodePattern::Macros
|
10
|
+
|
11
|
+
ASSERTION_PREFIXES = %w[assert refute].freeze
|
12
|
+
|
13
|
+
LIFECYCLE_HOOK_METHODS = %i[
|
14
|
+
before_setup
|
15
|
+
setup
|
16
|
+
after_setup
|
17
|
+
before_teardown
|
18
|
+
teardown
|
19
|
+
after_teardown
|
20
|
+
].to_set.freeze
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def test_class?(class_node)
|
25
|
+
class_node.parent_class && class_node.identifier.source.end_with?('Test')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_case?(node)
|
29
|
+
return false unless node&.def_type? && test_case_name?(node.method_name)
|
30
|
+
|
31
|
+
class_ancestor = node.each_ancestor(:class).first
|
32
|
+
test_class?(class_ancestor)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_cases(class_node)
|
36
|
+
class_def_nodes(class_node)
|
37
|
+
.select { |def_node| test_case_name?(def_node.method_name) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def lifecycle_hooks(class_node)
|
41
|
+
class_def_nodes(class_node)
|
42
|
+
.select { |def_node| lifecycle_hook_method?(def_node) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def class_def_nodes(class_node)
|
46
|
+
class_def = class_node.body
|
47
|
+
return [] unless class_def
|
48
|
+
|
49
|
+
if class_def.def_type?
|
50
|
+
[class_def]
|
51
|
+
else
|
52
|
+
class_def.each_child_node(:def).to_a
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_case_name?(name)
|
57
|
+
name.to_s.start_with?('test_')
|
58
|
+
end
|
59
|
+
|
60
|
+
def assertions(def_node)
|
61
|
+
method_def = def_node.body
|
62
|
+
return [] unless method_def
|
63
|
+
|
64
|
+
send_nodes =
|
65
|
+
if method_def.send_type?
|
66
|
+
[method_def]
|
67
|
+
else
|
68
|
+
method_def.each_child_node(:send)
|
69
|
+
end
|
70
|
+
|
71
|
+
send_nodes.select { |send_node| assertion?(send_node) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def assertion?(node)
|
75
|
+
node.send_type? &&
|
76
|
+
ASSERTION_PREFIXES.any? { |prefix| node.method_name.to_s.start_with?(prefix) }
|
77
|
+
end
|
78
|
+
|
79
|
+
def lifecycle_hook_method?(node)
|
80
|
+
node.def_type? && LIFECYCLE_HOOK_METHODS.include?(node.method_name)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/mkdocs.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
site_name: "A RuboCop extension focused on enforcing Minitest best practices and coding conventions."
|
2
2
|
repo_url: https://github.com/rubocop-hq/rubocop-minitest
|
3
|
-
edit_uri: edit/master/
|
3
|
+
edit_uri: edit/master/legacy-docs/
|
4
4
|
copyright: "Copyright © 2019 Bozhidar Batsov, Jonas Arvidsson, Koichi ITO, and RuboCop contributors"
|
5
|
-
docs_dir:
|
5
|
+
docs_dir: legacy-docs
|
6
6
|
pages:
|
7
7
|
- Home: index.md
|
8
8
|
- Installation: installation.md
|
data/relnotes/v0.10.0.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
### New features
|
2
|
+
|
3
|
+
* [#92](https://github.com/rubocop-hq/rubocop-minitest/pull/92): Add new `Minitest/LiteralAsActualArgument` cop. ([@fatkodima][], [@tsmmark][])
|
4
|
+
* [#95](https://github.com/rubocop-hq/rubocop-minitest/pull/95): Add new `Minitest/AssertionInLifecycleHook` cop. ([@fatkodima][])
|
5
|
+
* [#91](https://github.com/rubocop-hq/rubocop-minitest/pull/91): Add new `Minitest/AssertInDelta` and `Minitest/RefuteInDelta` cops. ([@fatkodima][])
|
6
|
+
* [#89](https://github.com/rubocop-hq/rubocop-minitest/pull/89): Add new `Minitest/TestMethodName` cop. ([@fatkodima][])
|
7
|
+
* [#83](https://github.com/rubocop-hq/rubocop-minitest/pull/83): New cops `AssertPathExists` and `RefutePathExists` check for use of `assert_path_exists`/`refute_path_exists` instead of `assert(File.exist?(path))`/`refute(File.exist?(path))`. ([@fatkodima][])
|
8
|
+
* [#88](https://github.com/rubocop-hq/rubocop-minitest/pull/88): Add new `Minitest/MultipleAssertions` cop. ([@fatkodima][])
|
9
|
+
* [#87](https://github.com/rubocop-hq/rubocop-minitest/pull/87): Add new `Minitest/AssertSilent` cop. ([@fatkodima][])
|
10
|
+
* [#96](https://github.com/rubocop-hq/rubocop-minitest/pull/96): Add new `Minitest/UnspecifiedException` cop. ([@fatkodima][])
|
11
|
+
* [#98](https://github.com/rubocop-hq/rubocop-minitest/pull/98): Add new `Minitest/AssertOutput` cop. ([@fatkodima][])
|
12
|
+
* [#84](https://github.com/rubocop-hq/rubocop-minitest/pull/84): New cops `AssertKindOf` and `RefuteKindOf` check for use of `assert_kind_of`/`refute_kind_of` instead of `assert(foo.kind_of?(Class))`/`refute(foo.kind_of?(Class))`. ([@fatkodima][])
|
13
|
+
* [#85](https://github.com/rubocop-hq/rubocop-minitest/pull/85): Add autocorrect to `Rails/AssertEmptyLiteral` cop. ([@fatkodima][])
|
14
|
+
|
15
|
+
### Changes
|
16
|
+
|
17
|
+
* [#104](https://github.com/rubocop-hq/rubocop-minitest/pull/104): Require RuboCop 0.87 or higher. ([@koic][])
|
18
|
+
|
19
|
+
[@fatkodima]: https://github.com/fatkodima
|
20
|
+
[@tsmmark]: https://github.com/tsmmark
|
21
|
+
[@koic]: https://github.com/koic
|
data/relnotes/v0.10.1.md
ADDED
data/relnotes/v0.10.2.md
ADDED
data/relnotes/v0.8.1.md
ADDED
data/relnotes/v0.9.0.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
### Bug fixes
|
2
|
+
|
3
|
+
* [#75](https://github.com/rubocop-hq/rubocop-minitest/issues/75): Fix a false negative for `Minitest/GlobalExpectations` when using global expectation methods with no arguments. ([@koic][])
|
4
|
+
|
5
|
+
### Changes
|
6
|
+
|
7
|
+
* [#73](https://github.com/rubocop-hq/rubocop-minitest/issues/73): The Minitest department works on file names end with `_test.rb` by default. ([@koic][])
|
8
|
+
* [#77](https://github.com/rubocop-hq/rubocop-minitest/pull/77): **(BREAKING)** Drop support for Ruby 2.3. ([@koic][])
|
9
|
+
|
10
|
+
[@koic]: https://github.com/koic
|
data/rubocop-minitest.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'rubocop/minitest/version'
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'rubocop-minitest'
|
9
|
-
spec.version = RuboCop::Minitest::
|
9
|
+
spec.version = RuboCop::Minitest::Version::STRING
|
10
10
|
spec.authors = ['Bozhidar Batsov', 'Jonas Arvidsson', 'Koichi ITO']
|
11
11
|
|
12
12
|
spec.summary = 'Automatic Minitest code style checking tool.'
|
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
|
|
16
16
|
DESCRIPTION
|
17
17
|
spec.license = 'MIT'
|
18
18
|
|
19
|
-
spec.required_ruby_version = '>= 2.
|
19
|
+
spec.required_ruby_version = '>= 2.4.0'
|
20
20
|
spec.metadata = {
|
21
|
-
'homepage_uri' => 'https://docs.rubocop.org/
|
21
|
+
'homepage_uri' => 'https://docs.rubocop.org/rubocop-minitest/',
|
22
22
|
'changelog_uri' => 'https://github.com/rubocop-hq/rubocop-minitest/blob/master/CHANGELOG.md',
|
23
23
|
'source_code_uri' => 'https://github.com/rubocop-hq/rubocop-minitest',
|
24
|
-
'documentation_uri' =>
|
24
|
+
'documentation_uri' => "https://docs.rubocop.org/rubocop-minitest/#{RuboCop::Minitest::Version.document_version}",
|
25
25
|
'bug_tracker_uri' => 'https://github.com/rubocop-hq/rubocop-minitest/issues'
|
26
26
|
}
|
27
27
|
|
@@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
35
|
spec.require_paths = ['lib']
|
36
36
|
|
37
|
-
spec.add_runtime_dependency 'rubocop', '>= 0.
|
37
|
+
spec.add_runtime_dependency 'rubocop', '>= 0.87', '< 2.0'
|
38
38
|
spec.add_development_dependency 'minitest', '~> 5.11'
|
39
39
|
end
|
@@ -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,273 +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 << properties(config, cop)
|
21
|
-
content << "#{description}\n"
|
22
|
-
content << examples(examples_objects) if examples_objects.count.positive?
|
23
|
-
content << configurations(pars)
|
24
|
-
content << references(config, cop)
|
25
|
-
content
|
26
|
-
end
|
27
|
-
|
28
|
-
def examples(examples_object)
|
29
|
-
examples_object.each_with_object(h3('Examples').dup) do |example, content|
|
30
|
-
content << h4(example.name) unless example.name == ''
|
31
|
-
content << code_example(example)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# rubocop:disable Metrics/MethodLength
|
36
|
-
def properties(config, cop)
|
37
|
-
header = [
|
38
|
-
'Enabled by default', 'Safe', 'Supports autocorrection', 'VersionAdded',
|
39
|
-
'VersionChanged'
|
40
|
-
]
|
41
|
-
config = config.for_cop(cop)
|
42
|
-
safe_auto_correct = config.fetch('SafeAutoCorrect', true)
|
43
|
-
autocorrect = if cop.new.support_autocorrect?
|
44
|
-
"Yes #{'(Unsafe)' unless safe_auto_correct}"
|
45
|
-
else
|
46
|
-
'No'
|
47
|
-
end
|
48
|
-
content = [[
|
49
|
-
config.fetch('Enabled') ? 'Enabled' : 'Disabled',
|
50
|
-
config.fetch('Safe', true) ? 'Yes' : 'No',
|
51
|
-
autocorrect,
|
52
|
-
config.fetch('VersionAdded', '-'),
|
53
|
-
config.fetch('VersionChanged', '-')
|
54
|
-
]]
|
55
|
-
to_table(header, content) + "\n"
|
56
|
-
end
|
57
|
-
# rubocop:enable Metrics/MethodLength
|
58
|
-
|
59
|
-
def h2(title)
|
60
|
-
content = +"\n"
|
61
|
-
content << "## #{title}\n"
|
62
|
-
content << "\n"
|
63
|
-
content
|
64
|
-
end
|
65
|
-
|
66
|
-
def h3(title)
|
67
|
-
content = +"\n"
|
68
|
-
content << "### #{title}\n"
|
69
|
-
content << "\n"
|
70
|
-
content
|
71
|
-
end
|
72
|
-
|
73
|
-
def h4(title)
|
74
|
-
content = +"#### #{title}\n"
|
75
|
-
content << "\n"
|
76
|
-
content
|
77
|
-
end
|
78
|
-
|
79
|
-
def code_example(ruby_code)
|
80
|
-
content = +"```ruby\n"
|
81
|
-
content << ruby_code.text
|
82
|
-
.gsub('@good', '# good').gsub('@bad', '# bad').strip
|
83
|
-
content << "\n```\n"
|
84
|
-
content
|
85
|
-
end
|
86
|
-
|
87
|
-
def configurations(pars)
|
88
|
-
return '' if pars.empty?
|
89
|
-
|
90
|
-
header = ['Name', 'Default value', 'Configurable values']
|
91
|
-
configs = pars.each_key.reject { |key| key.start_with?('Supported') }
|
92
|
-
content = configs.map do |name|
|
93
|
-
configurable = configurable_values(pars, name)
|
94
|
-
default = format_table_value(pars[name])
|
95
|
-
[name, default, configurable]
|
96
|
-
end
|
97
|
-
|
98
|
-
h3('Configurable attributes') + to_table(header, content)
|
99
|
-
end
|
100
|
-
|
101
|
-
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
102
|
-
def configurable_values(pars, name)
|
103
|
-
case name
|
104
|
-
when /^Enforced/
|
105
|
-
supported_style_name = RuboCop::Cop::Util.to_supported_styles(name)
|
106
|
-
format_table_value(pars[supported_style_name])
|
107
|
-
when 'IndentationWidth'
|
108
|
-
'Integer'
|
109
|
-
when 'Database'
|
110
|
-
format_table_value(pars['SupportedDatabases'])
|
111
|
-
else
|
112
|
-
case pars[name]
|
113
|
-
when String
|
114
|
-
'String'
|
115
|
-
when Integer
|
116
|
-
'Integer'
|
117
|
-
when Float
|
118
|
-
'Float'
|
119
|
-
when true, false
|
120
|
-
'Boolean'
|
121
|
-
when Array
|
122
|
-
'Array'
|
123
|
-
else
|
124
|
-
''
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
129
|
-
|
130
|
-
def to_table(header, content)
|
131
|
-
table = [
|
132
|
-
header.join(' | '),
|
133
|
-
Array.new(header.size, '---').join(' | ')
|
134
|
-
]
|
135
|
-
table.concat(content.map { |c| c.join(' | ') })
|
136
|
-
table.join("\n") + "\n"
|
137
|
-
end
|
138
|
-
|
139
|
-
def format_table_value(val)
|
140
|
-
value =
|
141
|
-
case val
|
142
|
-
when Array
|
143
|
-
if val.empty?
|
144
|
-
'`[]`'
|
145
|
-
else
|
146
|
-
val.map { |config| format_table_value(config) }.join(', ')
|
147
|
-
end
|
148
|
-
else
|
149
|
-
"`#{val.nil? ? '<none>' : val}`"
|
150
|
-
end
|
151
|
-
value.gsub("#{Dir.pwd}/", '').rstrip
|
152
|
-
end
|
153
|
-
|
154
|
-
def references(config, cop)
|
155
|
-
cop_config = config.for_cop(cop)
|
156
|
-
urls = RuboCop::Cop::MessageAnnotator.new(
|
157
|
-
config, cop.name, cop_config, {}
|
158
|
-
).urls
|
159
|
-
return '' if urls.empty?
|
160
|
-
|
161
|
-
content = h3('References')
|
162
|
-
content << urls.map { |url| "* [#{url}](#{url})" }.join("\n")
|
163
|
-
content << "\n"
|
164
|
-
content
|
165
|
-
end
|
166
|
-
|
167
|
-
def print_cops_of_department(cops, department, config)
|
168
|
-
selected_cops = cops_of_department(cops, department).select do |cop|
|
169
|
-
cop.to_s.start_with?('RuboCop::Cop::Minitest')
|
170
|
-
end
|
171
|
-
return if selected_cops.empty?
|
172
|
-
|
173
|
-
content = +"# #{department}\n"
|
174
|
-
selected_cops.each do |cop|
|
175
|
-
content << print_cop_with_doc(cop, config)
|
176
|
-
end
|
177
|
-
file_name = "#{Dir.pwd}/manual/cops_#{department.downcase}.md"
|
178
|
-
File.open(file_name, 'w') do |file|
|
179
|
-
puts "* generated #{file_name}"
|
180
|
-
file.write(content.strip + "\n")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def print_cop_with_doc(cop, config)
|
185
|
-
t = config.for_cop(cop)
|
186
|
-
non_display_keys = %w[
|
187
|
-
Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded
|
188
|
-
VersionChanged
|
189
|
-
]
|
190
|
-
pars = t.reject { |k| non_display_keys.include? k }
|
191
|
-
description = 'No documentation'
|
192
|
-
examples_object = []
|
193
|
-
YARD::Registry.all(:class).detect do |code_object|
|
194
|
-
next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
|
195
|
-
|
196
|
-
description = code_object.docstring unless code_object.docstring.blank?
|
197
|
-
examples_object = code_object.tags('example')
|
198
|
-
end
|
199
|
-
cops_body(config, cop, description, examples_object, pars)
|
200
|
-
end
|
201
|
-
|
202
|
-
# rubocop:disable Metrics/AbcSize
|
203
|
-
def table_of_content_for_department(cops, department)
|
204
|
-
selected_cops = cops_of_department(cops, department.to_sym).select do |cop|
|
205
|
-
cop.to_s.start_with?('RuboCop::Cop::Minitest')
|
206
|
-
end
|
207
|
-
return if selected_cops.empty?
|
208
|
-
|
209
|
-
type_title = department[0].upcase + department[1..-1]
|
210
|
-
filename = "cops_#{department.downcase}.md"
|
211
|
-
content = +"#### Department [#{type_title}](#{filename})\n\n"
|
212
|
-
selected_cops.each do |cop|
|
213
|
-
anchor = cop.cop_name.sub('/', '').downcase
|
214
|
-
content << "* [#{cop.cop_name}](#{filename}##{anchor})\n"
|
215
|
-
end
|
216
|
-
|
217
|
-
content
|
218
|
-
end
|
219
|
-
# rubocop:enable Metrics/AbcSize
|
220
|
-
|
221
|
-
def print_table_of_contents(cops)
|
222
|
-
path = "#{Dir.pwd}/manual/cops.md"
|
223
|
-
original = File.read(path)
|
224
|
-
content = +"<!-- START_COP_LIST -->\n"
|
225
|
-
|
226
|
-
content << table_contents(cops)
|
227
|
-
|
228
|
-
content << "\n<!-- END_COP_LIST -->"
|
229
|
-
|
230
|
-
content = if original.empty?
|
231
|
-
content
|
232
|
-
else
|
233
|
-
original.sub(
|
234
|
-
/<!-- START_COP_LIST -->.+<!-- END_COP_LIST -->/m, content
|
235
|
-
)
|
236
|
-
end
|
237
|
-
File.write(path, content)
|
238
|
-
end
|
239
|
-
|
240
|
-
def table_contents(cops)
|
241
|
-
cops
|
242
|
-
.departments
|
243
|
-
.map(&:to_s)
|
244
|
-
.sort
|
245
|
-
.map { |department| table_of_content_for_department(cops, department) }
|
246
|
-
.reject(&:nil?)
|
247
|
-
.join("\n")
|
248
|
-
end
|
249
|
-
|
250
|
-
def assert_manual_synchronized
|
251
|
-
# Do not print diff and yield whether exit code was zero
|
252
|
-
sh('git diff --quiet manual') do |outcome, _|
|
253
|
-
return if outcome
|
254
|
-
|
255
|
-
# Output diff before raising error
|
256
|
-
sh('GIT_PAGER=cat git diff manual')
|
257
|
-
|
258
|
-
warn 'The manual directory is out of sync. ' \
|
259
|
-
'Run `rake generate_cops_documentation` and commit the results.'
|
260
|
-
exit!
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
def main
|
265
|
-
cops = RuboCop::Cop::Cop.registry
|
266
|
-
config = RuboCop::ConfigLoader.load_file('config/default.yml')
|
15
|
+
deps = ['Minitest']
|
16
|
+
CopsDocumentationGenerator.new(departments: deps).call
|
17
|
+
end
|
267
18
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
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
|
272
24
|
|
273
|
-
|
25
|
+
# Output diff before raising error
|
26
|
+
sh('GIT_PAGER=cat git diff docs')
|
274
27
|
|
275
|
-
|
276
|
-
|
277
|
-
|
28
|
+
warn 'The docs directory is out of sync. ' \
|
29
|
+
'Run `rake generate_cops_documentation` and commit the results.'
|
30
|
+
exit!
|
278
31
|
end
|
279
|
-
|
280
|
-
main
|
281
32
|
end
|
282
33
|
|
283
34
|
desc 'Syntax check for the documentation comments'
|
@@ -286,7 +37,7 @@ task documentation_syntax_check: :yard_for_generate_documentation do
|
|
286
37
|
|
287
38
|
ok = true
|
288
39
|
YARD::Registry.load!
|
289
|
-
cops = RuboCop::Cop::
|
40
|
+
cops = RuboCop::Cop::Registry.global
|
290
41
|
cops.each do |cop|
|
291
42
|
examples = YARD::Registry.all(:class).find do |code_object|
|
292
43
|
next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
|