tasks/cops_documentation.rake in rubocop-faker-1.1.0 vs tasks/cops_documentation.rake in rubocop-faker-1.2.0
- old
+ new
@@ -38,11 +38,11 @@
'Enabled by default', 'Safe', 'Supports autocorrection', 'VersionAdded',
'VersionChanged'
]
config = config.for_cop(cop)
safe_auto_correct = config.fetch('SafeAutoCorrect', true)
- autocorrect = if cop.new.support_autocorrect?
+ autocorrect = if cop.support_autocorrect?
"Yes #{'(Unsafe)' unless safe_auto_correct}"
else
'No'
end
content = [[
@@ -50,11 +50,11 @@
config.fetch('Safe', true) ? 'Yes' : 'No',
autocorrect,
config.fetch('VersionAdded', '-'),
config.fetch('VersionChanged', '-')
]]
- to_table(header, content) + "\n"
+ "#{to_table(header, content)}\n"
end
# rubocop:enable Metrics/MethodLength
def h2(title)
content = +"\n"
@@ -129,11 +129,11 @@
table = [
header.join(' | '),
Array.new(header.size, '---').join(' | ')
]
table.concat(content.map { |c| c.join(' | ') })
- table.join("\n") + "\n"
+ "#{table.join("\n")}\n"
end
def format_table_value(val)
value =
case val
@@ -173,11 +173,11 @@
content << print_cop_with_doc(cop, config)
end
file_name = "#{Dir.pwd}/manual/cops_#{department.downcase}.md"
File.open(file_name, 'w') do |file|
puts "* generated #{file_name}"
- file.write(content.strip + "\n")
+ file.write("#{content.strip}\n")
end
end
def print_cop_with_doc(cop, config)
t = config.for_cop(cop)
@@ -201,11 +201,11 @@
selected_cops = cops_of_department(cops, department.to_sym).select do |cop|
cop.to_s.start_with?('RuboCop::Cop::Faker')
end
return if selected_cops.empty?
- type_title = department[0].upcase + department[1..-1]
+ type_title = department[0].upcase + department[1..]
filename = "cops_#{department.downcase}.md"
content = +"#### Department [#{type_title}](#{filename})\n\n"
selected_cops.each do |cop|
anchor = cop.cop_name.sub('/', '').downcase
content << "* [#{cop.cop_name}](#{filename}##{anchor})\n"
@@ -221,27 +221,24 @@
content << table_contents(cops)
content << "\n<!-- END_COP_LIST -->"
- content = if original.empty?
- content
- else
- original.sub(
- /<!-- START_COP_LIST -->.+<!-- END_COP_LIST -->/m, content
- )
- end
+ unless original.empty?
+ content = original.sub(
+ /<!-- START_COP_LIST -->.+<!-- END_COP_LIST -->/m, content
+ )
+ end
File.write(path, content)
end
def table_contents(cops)
cops
.departments
.map(&:to_s)
.sort
- .map { |department| table_of_content_for_department(cops, department) }
- .reject(&:nil?)
+ .filter_map { |department| table_of_content_for_department(cops, department) }
.join("\n")
end
def assert_manual_synchronized
# Do not print diff and yield whether exit code was zero
@@ -250,17 +247,17 @@
# Output diff before raising error
sh('GIT_PAGER=cat git diff manual')
warn 'The manual directory is out of sync. ' \
- 'Run `rake generate_cops_documentation` and commit the results.'
+ 'Run `rake generate_cops_documentation` and commit the results.'
exit!
end
end
def main
- cops = RuboCop::Cop::Cop.registry
+ cops = RuboCop::Cop::Registry.global
config = RuboCop::ConfigLoader.load_file('config/default.yml')
YARD::Registry.load!
cops.departments.sort!.each do |department|
print_cops_of_department(cops, department, config)
@@ -280,29 +277,27 @@
task documentation_syntax_check: :yard_for_generate_documentation do
require 'parser/ruby25'
ok = true
YARD::Registry.load!
- cops = RuboCop::Cop::Cop.registry
+ cops = RuboCop::Cop::Registry.global
cops.each do |cop|
examples = YARD::Registry.all(:class).find do |code_object|
next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge
break code_object.tags('example')
end
examples.to_a.each do |example|
- begin
- buffer = Parser::Source::Buffer.new('<code>', 1)
- buffer.source = example.text
- parser = Parser::Ruby25.new(RuboCop::AST::Builder.new)
- parser.diagnostics.all_errors_are_fatal = true
- parser.parse(buffer)
- rescue Parser::SyntaxError => e
- path = example.object.file
- puts "#{path}: Syntax Error in an example. #{e}"
- ok = false
- end
+ buffer = Parser::Source::Buffer.new('<code>', 1)
+ buffer.source = example.text
+ parser = Parser::Ruby25.new(RuboCop::AST::Builder.new)
+ parser.diagnostics.all_errors_are_fatal = true
+ parser.parse(buffer)
+ rescue Parser::SyntaxError => e
+ path = example.object.file
+ puts "#{path}: Syntax Error in an example. #{e}"
+ ok = false
end
end
abort unless ok
end