Skip to content

Commit 223ef05

Browse files
committed
(MAINT) Rubocop - (lib) fixes for tasks
1 parent 5af8db8 commit 223ef05

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

lib/puppet-strings/tasks/generate.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Implements the strings:generate task.
66
namespace :strings do
77
desc 'Generate Puppet documentation with YARD.'
8-
task :generate, [:patterns, :debug, :backtrace, :markup, :json, :markdown, :yard_args] do |t, args|
8+
task :generate, [:patterns, :debug, :backtrace, :markup, :json, :markdown, :yard_args] do |_t, args|
99
patterns = args[:patterns]
1010
patterns = patterns.split if patterns
1111
patterns ||= PuppetStrings::DEFAULT_SEARCH_PATTERNS
@@ -16,7 +16,7 @@
1616
markup: args[:markup] || 'markdown',
1717
}
1818

19-
raise("Error: Both JSON and Markdown output have been selected. Please select one.") if args[:json] == 'true' && args[:markdown] == 'true'
19+
raise('Error: Both JSON and Markdown output have been selected. Please select one.') if args[:json] == 'true' && args[:markdown] == 'true'
2020

2121
# rubocop:disable Style/PreferredHashMethods
2222
# Because of Ruby, true and false from the args are both strings and both true. Here,
@@ -28,16 +28,14 @@
2828
# @param [Symbol] possible format option
2929
# @return nil
3030
def parse_format_option(args, options, format)
31-
if args.has_key? format
32-
options[format] = args[format] == 'false' || args[format].empty? ? false : true
33-
if options[format]
34-
options[:path] = args[format] == 'true' ? nil : args[format]
35-
end
36-
end
31+
return unless args.has_key? format
32+
options[format] = args[format] == 'false' || args[format].empty? ? false : true
33+
return unless options[format]
34+
options[:path] = args[format] == 'true' ? nil : args[format]
3735
end
3836
# rubocop:enable Style/PreferredHashMethods
3937

40-
%i[json markdown].each { |format| parse_format_option(args, options, format) }
38+
[:json, :markdown].each { |format| parse_format_option(args, options, format) }
4139

4240
warn('yard_args behavior is a little dodgy, use at your own risk') if args[:yard_args]
4341
options[:yard_args] = args[:yard_args].split if args.key? :yard_args
@@ -47,7 +45,7 @@ def parse_format_option(args, options, format)
4745

4846
namespace :generate do
4947
desc 'Generate Puppet Reference documentation.'
50-
task :reference, [:patterns, :debug, :backtrace] do |t, args|
48+
task :reference, [:patterns, :debug, :backtrace] do |_t, args|
5149
Rake::Task['strings:generate'].invoke(args[:patterns], args[:debug], args[:backtrace], nil, 'false', 'true')
5250
end
5351
end

lib/puppet-strings/tasks/gh_pages.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# frozen_string_literal: true
22

3+
require 'English'
34
require 'puppet-strings/tasks'
45

56
namespace :strings do
67
namespace :gh_pages do
78
task :checkout do
89
if Dir.exist?('doc')
9-
fail "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git')
10+
raise "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git')
1011

1112
Dir.chdir('doc') do
1213
system 'git checkout gh-pages'
1314
system 'git pull --rebase origin gh-pages'
1415
end
1516
else
1617
git_uri = `git config --get remote.origin.url`.strip
17-
fail "Could not determine the remote URL for origin: ensure the current directory is a Git repro with a remote named 'origin'." unless $?.success?
18+
raise "Could not determine the remote URL for origin: ensure the current directory is a Git repro with a remote named 'origin'." unless $CHILD_STATUS.success?
1819

1920
Dir.mkdir('doc')
2021
Dir.chdir('doc') do
@@ -29,15 +30,15 @@
2930
task :configure do
3031
unless File.exist?(File.join('doc', '_config.yml'))
3132
Dir.chdir('doc') do
32-
File.open('_config.yml', 'w+') {|f| f.write("include: _index.html") }
33+
File.open('_config.yml', 'w+') { |f| f.write('include: _index.html') }
3334
end
3435
end
3536
end
3637

3738
task :push do
3839
output = `git describe --long 2>/dev/null`
3940
# If a project has never been tagged, fall back to latest SHA
40-
output.empty? ? git_sha = `git log --pretty=format:'%H' -n 1` : git_sha = output
41+
git_sha = output.empty? ? `git log --pretty=format:'%H' -n 1` : output
4142

4243
Dir.chdir('doc') do
4344
system 'git add .'
@@ -47,7 +48,7 @@
4748
end
4849

4950
desc 'Update docs on the gh-pages branch and push to GitHub.'
50-
task :update => [
51+
task update: [
5152
:checkout,
5253
:'strings:generate',
5354
:configure,

lib/puppet-strings/tasks/validate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace :strings do
77
namespace :validate do
88
desc 'Validate the reference is up to date'
9-
task :reference, [:patterns, :debug, :backtrace] do |t, args|
9+
task :reference, [:patterns, :debug, :backtrace] do |_t, args|
1010
filename = 'REFERENCE.md'
1111

1212
unless File.exist?(filename)

0 commit comments

Comments
 (0)