diff options
author | Marcel Amirault <mamirault@gitlab.com> | 2022-06-06 04:32:44 +0300 |
---|---|---|
committer | Marcel Amirault <mamirault@gitlab.com> | 2022-06-06 04:32:44 +0300 |
commit | b3111528d56dca12cf1396b2e2ba3cb7a4bb560c (patch) | |
tree | 49b4029d3b8eac4f38983589451b160ce1b49b34 | |
parent | bfc025769b2fd089cab354c69cf5595f095e0d1e (diff) | |
parent | 9934176180cc95510de52ce509a656fabf06b92e (diff) |
Merge branch 'eread/fix-regexp-literal-rubocop-offenses' into 'main'
Fix Style/RegexpLiteral RuboCop offenses
See merge request gitlab-org/gitlab-docs!2755
-rw-r--r-- | .rubocop.yml | 6 | ||||
-rw-r--r-- | Rakefile | 6 | ||||
-rw-r--r-- | lib/filters/admonition.rb | 2 | ||||
-rw-r--r-- | lib/filters/gitlab_kramdown.rb | 2 | ||||
-rw-r--r-- | lib/filters/icons.rb | 4 | ||||
-rw-r--r-- | lib/filters/introduced_in.rb | 6 | ||||
-rw-r--r-- | lib/filters/markdown_to_html_ext.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/navigation.rb | 2 | ||||
-rw-r--r-- | lib/helpers/versions.rb | 2 | ||||
-rw-r--r-- | lib/task_helpers.rb | 2 |
10 files changed, 22 insertions, 16 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 23504765..58222779 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,3 +20,9 @@ RSpec/MultipleMemoizedHelpers: Style/FrozenStringLiteralComment: Enabled: false + +# See https://gitlab.com/gitlab-org/gitlab/-/issues/327495 +# Prefer percent_r instead of mix of styles +Style/RegexpLiteral: + Enabled: true + EnforcedStyle: percent_r @@ -79,7 +79,7 @@ namespace :release do version = args.version.to_s source_dir = File.expand_path(__dir__) - raise 'You need to specify a version, like 10.1' unless version.match?(/\A\d+\.\d+\z/) + raise 'You need to specify a version, like 10.1' unless version.match?(%r{\A\d+\.\d+\z}) # Check if local branch exists abort("\n#{COLOR_CODE_RED}ERROR: Rake aborted! The branch already exists. Delete it with `git branch -D #{version}` and rerun the task.#{COLOR_CODE_RESET}") \ @@ -267,7 +267,7 @@ namespace :docs do # def new_path(redirect, filename, content_dir, slug) if !redirect.start_with?('http') - Pathname.new(filename).dirname.join(redirect).to_s.gsub(/\.md/, '.html').gsub(content_dir, "/#{slug}") + Pathname.new(filename).dirname.join(redirect).to_s.gsub(%r{\.md}, '.html').gsub(content_dir, "/#{slug}") elsif redirect.start_with?('https://docs.gitlab.com') redirect.gsub('https://docs.gitlab.com', '') else @@ -311,7 +311,7 @@ namespace :docs do next unless frontmatter.has_key?('remove_date') remove_date = Date.parse(frontmatter['remove_date']) - old_path = filename.gsub(/\.md/, '.html').gsub(content_dir, "/#{slug}") + old_path = filename.gsub(%r{\.md}, '.html').gsub(content_dir, "/#{slug}") # # Check if the removal date is before today, and delete the file and diff --git a/lib/filters/admonition.rb b/lib/filters/admonition.rb index 41c6de40..e88267bd 100644 --- a/lib/filters/admonition.rb +++ b/lib/filters/admonition.rb @@ -26,7 +26,7 @@ class AdmonitionFilter < Nanoc::Filter doc = Nokogiri::HTML.fragment(content.dup) doc.css('p').each do |para| content = para.inner_html - match = content.match(/\A(?<type>NOTE|WARNING|FLAG|INFO|DISCLAIMER):\s?(?<content>.*)\Z/m) + match = content.match(%r{\A(?<type>NOTE|WARNING|FLAG|INFO|DISCLAIMER):\s?(?<content>.*)\Z}m) next unless match new_content = generate(match[:type].downcase, match[:content]) diff --git a/lib/filters/gitlab_kramdown.rb b/lib/filters/gitlab_kramdown.rb index 281adfcf..64a1d17a 100644 --- a/lib/filters/gitlab_kramdown.rb +++ b/lib/filters/gitlab_kramdown.rb @@ -15,7 +15,7 @@ module Nanoc::Filters PRODUCT_TIERS = %w[core starter premium ultimate free bronze silver gold].freeze PRODUCT_TYPES = %w[only saas self].freeze - PRODUCT_SUFFIX = /-(#{PRODUCT_TIERS.join('|')})(?:-(#{PRODUCT_TYPES.join('|')}))?\z/.freeze + PRODUCT_SUFFIX = %r{-(#{PRODUCT_TIERS.join('|')})(?:-(#{PRODUCT_TYPES.join('|')}))?\z}.freeze # Runs the content through [GitLab Kramdown](https://gitlab.com/brodock/gitlab_kramdown). # Parameters passed to this filter will be passed on to Kramdown. diff --git a/lib/filters/icons.rb b/lib/filters/icons.rb index 39daadcc..815faa51 100644 --- a/lib/filters/icons.rb +++ b/lib/filters/icons.rb @@ -16,9 +16,9 @@ class IconsFilter < Nanoc::Filter identifier :icons - ICON_PATTERN = /\{\s*([\w-]+)\s*(?:,\s*(\d+))?\s*(?:,\s*([\w-]+))?\s*\}/.freeze + ICON_PATTERN = %r{\{\s*([\w-]+)\s*(?:,\s*(\d+))?\s*(?:,\s*([\w-]+))?\s*\}}.freeze ICON_HTML_PATTERN = %r{<strong>#{ICON_PATTERN}</strong>}.freeze - ICON_MARKDOWN_PATTERN = /\*\*#{ICON_PATTERN}\*\*/.freeze + ICON_MARKDOWN_PATTERN = %r{\*\*#{ICON_PATTERN}\*\*}.freeze def run(content, params = {}) content.gsub(ICON_HTML_PATTERN) { generate(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)) } diff --git a/lib/filters/introduced_in.rb b/lib/filters/introduced_in.rb index 3aec9b1e..8bcdfb50 100644 --- a/lib/filters/introduced_in.rb +++ b/lib/filters/introduced_in.rb @@ -21,7 +21,7 @@ class IntroducedInFilter < Nanoc::Filter # - "changed <optional text> in" # - "enabled <optional text> in" # ...followed by "GitLab" - next if content !~ /(<a href="[^"]+">)?( + next if content !~ %r{(<a href="[^"]+">)?( introduced| enabled| (re)?moved| @@ -29,7 +29,7 @@ class IntroducedInFilter < Nanoc::Filter deprecated| renamed| recommended - )(<\/a>)?(.*)? (in|to).*GitLab/xmi + )(</a>)?(.*)? (in|to).*GitLab}xmi new_content = generate(content) blockquote.replace(new_content) @@ -40,7 +40,7 @@ class IntroducedInFilter < Nanoc::Filter def generate(content) @incremental_id += 1 # If the content is a list of items, collapse the content. - if content =~ /<ul>/i + if content =~ %r{<ul>}i %(<div class="introduced-in mb-3">Version history) + %(<button class="text-expander" type="button" data-toggle="collapse" data-target="#release_version_notes_#{@incremental_id}" aria-expanded="false" aria-controls="release_version_notes_#{@incremental_id}" aria-label="Version history">) + %(</button>) + diff --git a/lib/filters/markdown_to_html_ext.rb b/lib/filters/markdown_to_html_ext.rb index 9ab372ba..14ef06e0 100644 --- a/lib/filters/markdown_to_html_ext.rb +++ b/lib/filters/markdown_to_html_ext.rb @@ -7,9 +7,9 @@ module Nanoc::Filters # Convert internal URLs that link to `.md` files to instead link to # { }`.html` files since that's what Nanoc actually serves. def run(content, params = {}) - content.gsub(/href="(\S*.md\S*)"/) do |result| # Fetch all links in the HTML Document - if /^href="http/.match(result).nil? # Check if link is internal - result.gsub!(/\.md/, '.html') # Replace the extension if link is internal + content.gsub(%r{href="(\S*.md\S*)"}) do |result| # Fetch all links in the HTML Document + if %r{^href="http}.match(result).nil? # Check if link is internal + result.gsub!(%r{\.md}, '.html') # Replace the extension if link is internal end result diff --git a/lib/gitlab/navigation.rb b/lib/gitlab/navigation.rb index 014f567f..886a6487 100644 --- a/lib/gitlab/navigation.rb +++ b/lib/gitlab/navigation.rb @@ -29,7 +29,7 @@ module Gitlab end def id_for(element) - element.title.gsub(/[\s\/()]/, '') + element.title.gsub(%r{[\s/()]}, '') end def children diff --git a/lib/helpers/versions.rb b/lib/helpers/versions.rb index e467c43f..2dfa2d14 100644 --- a/lib/helpers/versions.rb +++ b/lib/helpers/versions.rb @@ -2,7 +2,7 @@ module Nanoc::Helpers module VersionsDropdown - STABLE_VERSIONS_REGEX = /^\d{1,2}\.\d{1,2}$/.freeze + STABLE_VERSIONS_REGEX = %r{^\d{1,2}\.\d{1,2}$}.freeze # # Set the active class based on CI_COMMIT_REF_NAME and exclude if on diff --git a/lib/task_helpers.rb b/lib/task_helpers.rb index fc7eb5d5..c4045655 100644 --- a/lib/task_helpers.rb +++ b/lib/task_helpers.rb @@ -3,7 +3,7 @@ require 'yaml' PRODUCTS = %w[ee omnibus runner charts operator].freeze -VERSION_FORMAT = /^(?<major>\d{1,2})\.(?<minor>\d{1,2})$/.freeze +VERSION_FORMAT = %r{^(?<major>\d{1,2})\.(?<minor>\d{1,2})$}.freeze def config # Parse the config file and create a hash. |