From 4adda6d5020d9299c06c8f360c14da7db390ab72 Mon Sep 17 00:00:00 2001 From: Evan Read Date: Thu, 19 May 2022 13:40:15 +1000 Subject: Fix Style/IfUnlessModifier Rubocop offenses --- Rakefile | 17 ++++++++++++----- lib/filters/gitlab_kramdown.rb | 4 +--- lib/filters/introduced_in.rb | 10 +++++++++- lib/helpers/child_parent_better.rb | 8 ++------ lib/helpers/reading_time.rb | 4 +--- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Rakefile b/Rakefile index cdb5820a..76a7a35d 100644 --- a/Rakefile +++ b/Rakefile @@ -24,7 +24,9 @@ task :clone_repositories do # check if the pipeline was triggered via the API (multi-project pipeline) # to exclude the case where we create a branch right off the gitlab-docs # project. - next if ENV["CI_COMMIT_REF_NAME"] != ENV['CI_DEFAULT_BRANCH'] && branch == ENV['CI_DEFAULT_BRANCH'] && ENV["CI_PIPELINE_SOURCE"] == 'pipeline' + next if ENV["CI_COMMIT_REF_NAME"] != ENV['CI_DEFAULT_BRANCH'] \ + && branch == ENV['CI_DEFAULT_BRANCH'] \ + && ENV["CI_PIPELINE_SOURCE"] == 'pipeline' puts "\n=> Cloning #{product['repo']} into #{product['project_dir']}\n" @@ -76,7 +78,8 @@ namespace :release do raise 'You need to specify a version, like 10.1' unless version.match?(/\A\d+\.\d+\z/) # Check if local branch exists - abort("Rake aborted! The branch already exists. Delete it with `git branch -D #{version}` and rerun the task.") if local_branch_exist?(version) + abort("Rake aborted! The branch already exists. Delete it with `git branch -D #{version}` and rerun the task.") \ + if local_branch_exist?(version) # Stash modified and untracked files so we have "clean" environment # without accidentally deleting data @@ -224,7 +227,9 @@ task :symlink_readmes do # check if the pipeline was triggered via the API (multi-project pipeline) # to exclude the case where we create a branch right off the gitlab-docs # project. - next if ENV["CI_COMMIT_REF_NAME"] != ENV['CI_DEFAULT_BRANCH'] && branch == ENV['CI_DEFAULT_BRANCH'] && ENV["CI_PIPELINE_SOURCE"] == 'pipeline' + next if ENV["CI_COMMIT_REF_NAME"] != ENV['CI_DEFAULT_BRANCH'] \ + && branch == ENV['CI_DEFAULT_BRANCH'] \ + && ENV["CI_PIPELINE_SOURCE"] == 'pipeline' next if readmes.key?(product['slug']) == false @@ -398,7 +403,8 @@ namespace :docs do puts "=> (#{slug}): Committing and pushing to create a merge request" system("git add .") system("git commit --quiet -m 'Update docs redirects #{today}'") - `git push --set-upstream origin #{redirects_branch} -o merge_request.create -o merge_request.remove_source_branch -o merge_request.title="#{mr_title}" -o merge_request.description="#{mr_description}" -o merge_request.label="Technical Writing" -o merge_request.label="documentation" -o merge_request.label="docs::improvement"` if ENV['SKIP_MR'].nil? + `git push --set-upstream origin #{redirects_branch} -o merge_request.create -o merge_request.remove_source_branch -o merge_request.title="#{mr_title}" -o merge_request.description="#{mr_description}" -o merge_request.label="Technical Writing" -o merge_request.label="documentation" -o merge_request.label="docs::improvement"` \ + if ENV['SKIP_MR'].nil? Dir.chdir(source_dir) puts end @@ -415,6 +421,7 @@ namespace :docs do puts "=> (gitlab-docs): Committing and pushing to create a merge request" system("git add #{redirects_yaml}") system("git commit --quiet -m 'Update docs redirects #{today}'") - `git push --set-upstream origin #{redirects_branch} -o merge_request.create -o merge_request.remove_source_branch -o merge_request.title="#{mr_title}" -o merge_request.description="#{mr_description}" -o merge_request.label="Technical Writing" -o merge_request.label="redirects" -o merge_request.label="Category:Docs Site"` if ENV['SKIP_MR'].nil? + `git push --set-upstream origin #{redirects_branch} -o merge_request.create -o merge_request.remove_source_branch -o merge_request.title="#{mr_title}" -o merge_request.description="#{mr_description}" -o merge_request.label="Technical Writing" -o merge_request.label="redirects" -o merge_request.label="Category:Docs Site"` \ + if ENV['SKIP_MR'].nil? end end diff --git a/lib/filters/gitlab_kramdown.rb b/lib/filters/gitlab_kramdown.rb index a849f70e..281adfcf 100644 --- a/lib/filters/gitlab_kramdown.rb +++ b/lib/filters/gitlab_kramdown.rb @@ -76,9 +76,7 @@ module Nanoc::Filters elements.each do |e| results.push(e) if type == e.type - unless e.children.empty? - results.concat(find_type_elements(type, e.children)) - end + e.children.empty? unless results.concat(find_type_elements(type, e.children)) end results diff --git a/lib/filters/introduced_in.rb b/lib/filters/introduced_in.rb index 57fca380..3aec9b1e 100644 --- a/lib/filters/introduced_in.rb +++ b/lib/filters/introduced_in.rb @@ -21,7 +21,15 @@ class IntroducedInFilter < Nanoc::Filter # - "changed in" # - "enabled in" # ...followed by "GitLab" - next if content !~ /()?(introduced|enabled|(re)?moved|changed|deprecated|renamed|recommended)(<\/a>)?(.*)? (in|to).*GitLab/mi + next if content !~ /()?( + introduced| + enabled| + (re)?moved| + changed| + deprecated| + renamed| + recommended + )(<\/a>)?(.*)? (in|to).*GitLab/xmi new_content = generate(content) blockquote.replace(new_content) diff --git a/lib/helpers/child_parent_better.rb b/lib/helpers/child_parent_better.rb index ec34e65d..c8427e40 100644 --- a/lib/helpers/child_parent_better.rb +++ b/lib/helpers/child_parent_better.rb @@ -4,9 +4,7 @@ module Nanoc::Helpers module ChildParentBetter # Returns an array of ancestor pages for the given page. def ancestor_path_array(item) - if @config[:debug] - puts item - end + puts item if @config[:debug] parent_array = [] current_item = item @@ -27,9 +25,7 @@ module Nanoc::Helpers # A recursive function which returns the nearest parent item for the # given path. def get_nearest_parent(item_identifier) - if @config[:debug] - puts item_identifier - end + puts item_identifier if @config[:debug] if (item_identifier.nil? || (item_identifier.to_s.end_with?('README.md', 'index.md') && item_identifier.to_s.split('/').length == 3)) return diff --git a/lib/helpers/reading_time.rb b/lib/helpers/reading_time.rb index c336dec7..424b4dac 100644 --- a/lib/helpers/reading_time.rb +++ b/lib/helpers/reading_time.rb @@ -24,9 +24,7 @@ module Nanoc::Helpers minutes = (words / WPM).ceil seconds = (words % WPM / (WPM / 60)).floor - if seconds.positive? - minutes += 1 - end + minutes += 1 if seconds.positive? (minutes <= 1 ? 'about a minute' : "~#{minutes} minutes") end -- cgit v1.2.3