Skip to content
Snippets Groups Projects
Commit 2b6307f6 authored by Takuya Noguchi's avatar Takuya Noguchi
Browse files

Enable RuboCop Style/RegexpLiteral

parent 08e01343
No related branches found
No related tags found
No related merge requests found
Showing
with 39 additions and 32 deletions
Loading
Loading
@@ -704,7 +704,9 @@ Style/RedundantSelf:
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Enabled: false
Enabled: true
EnforcedStyle: mixed
AllowInnerSlashes: false
 
# Offense count: 36
# Cop supports --auto-correct.
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ class HelpController < ApplicationController
 
# Taken from Jekyll
# https://github.com/jekyll/jekyll/blob/3.5-stable/lib/jekyll/document.rb#L13
YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m
YAML_FRONT_MATTER_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
 
def index
# Remove YAML frontmatter so that it doesn't look weird
Loading
Loading
Loading
Loading
@@ -403,6 +403,6 @@ class ProjectsController < Projects::ApplicationController
# to
# localhost/group/project
#
redirect_to request.original_url.sub(/\.git\/?\Z/, '') if params[:format] == 'git'
redirect_to request.original_url.sub(%r{\.git/?\Z}, '') if params[:format] == 'git'
end
end
module SidekiqHelper
SIDEKIQ_PS_REGEXP = /\A
SIDEKIQ_PS_REGEXP = %r{\A
(?<pid>\d+)\s+
(?<cpu>[\d\.,]+)\s+
(?<mem>[\d\.,]+)\s+
(?<state>[DIEKNRSTVWXZNLpsl\+<>\/\d]+)\s+
(?<state>[DIEKNRSTVWXZNLpsl\+<>/\d]+)\s+
(?<start>.+?)\s+
(?<command>(?:ruby\d+:\s+)?sidekiq.*\].*)
\z/x
\z}x
 
def parse_sidekiq_ps(line)
match = line.strip.match(SIDEKIQ_PS_REGEXP)
Loading
Loading
Loading
Loading
@@ -11,7 +11,7 @@ module SubmoduleHelper
url = File.join(Gitlab.config.gitlab.url, @project.full_path)
end
 
if url =~ /([^\/:]+)\/([^\/]+(?:\.git)?)\Z/
if url =~ %r{([^/:]+)/([^/]+(?:\.git)?)\Z}
namespace, project = $1, $2
gitlab_hosts = [Gitlab.config.gitlab.url,
Gitlab.config.gitlab_shell.ssh_path_prefix]
Loading
Loading
@@ -23,7 +23,7 @@ module SubmoduleHelper
end
end
 
namespace.sub!(/\A\//, '')
namespace.sub!(%r{\A/}, '')
project.rstrip!
project.sub!(/\.git\z/, '')
 
Loading
Loading
@@ -47,11 +47,11 @@ module SubmoduleHelper
protected
 
def github_dot_com_url?(url)
url =~ /github\.com[\/:][^\/]+\/[^\/]+\Z/
url =~ %r{github\.com[/:][^/]+/[^/]+\Z}
end
 
def gitlab_dot_com_url?(url)
url =~ /gitlab\.com[\/:][^\/]+\/[^\/]+\Z/
url =~ %r{gitlab\.com[/:][^/]+/[^/]+\Z}
end
 
def self_url?(url, namespace, project)
Loading
Loading
@@ -65,7 +65,7 @@ module SubmoduleHelper
 
def relative_self_url?(url)
# (./)?(../repo.git) || (./)?(../../project/repo.git) )
url =~ /\A((\.\/)?(\.\.\/))(?!(\.\.)|(.*\/)).*(\.git)?\z/ || url =~ /\A((\.\/)?(\.\.\/){2})(?!(\.\.))([^\/]*)\/(?!(\.\.)|(.*\/)).*(\.git)?\z/
url =~ %r{\A((\./)?(\.\./))(?!(\.\.)|(.*/)).*(\.git)?\z} || url =~ %r{\A((\./)?(\.\./){2})(?!(\.\.))([^/]*)/(?!(\.\.)|(.*/)).*(\.git)?\z}
end
 
def standard_links(host, namespace, project, commit)
Loading
Loading
Loading
Loading
@@ -110,7 +110,7 @@ module TreeHelper
 
# returns the relative path of the first subdir that doesn't have only one directory descendant
def flatten_tree(root_path, tree)
return tree.flat_path.sub(/\A#{root_path}\//, '') if tree.flat_path.present?
return tree.flat_path.sub(%r{\A#{root_path}/}, '') if tree.flat_path.present?
 
subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path)
if subtree.count == 1 && subtree.first.dir?
Loading
Loading
Loading
Loading
@@ -292,7 +292,7 @@ module Ci
 
def repo_url
auth = "gitlab-ci-token:#{ensure_token!}@"
project.http_url_to_repo.sub(/^https?:\/\//) do |prefix|
project.http_url_to_repo.sub(%r{^https?://}) do |prefix|
prefix + auth
end
end
Loading
Loading
Loading
Loading
@@ -141,7 +141,7 @@ class CommitStatus < ActiveRecord::Base
end
 
def group_name
name.to_s.gsub(/\d+[\s:\/\\]+\d+\s*/, '').strip
name.to_s.gsub(%r{\d+[\s:/\\]+\d+\s*}, '').strip
end
 
def failed_but_allowed?
Loading
Loading
Loading
Loading
@@ -9,13 +9,13 @@ require 'task_list/filter'
module Taskable
COMPLETED = 'completed'.freeze
INCOMPLETE = 'incomplete'.freeze
ITEM_PATTERN = /
ITEM_PATTERN = %r{
^
\s*(?:[-+*]|(?:\d+\.)) # list prefix required - task item has to be always in a list
\s+ # whitespace prefix has to be always presented for a list item
(\[\s\]|\[[xX]\]) # checkbox
(\s.+) # followed by whitespace and some text.
/x
}x
 
def self.get_tasks(content)
content.to_s.scan(ITEM_PATTERN).map do |checkbox, label|
Loading
Loading
Loading
Loading
@@ -115,7 +115,7 @@ class Environment < ActiveRecord::Base
def formatted_external_url
return nil unless external_url
 
external_url.gsub(/\A.*?:\/\//, '')
external_url.gsub(%r{\A.*?://}, '')
end
 
def stop_action?
Loading
Loading
Loading
Loading
@@ -234,7 +234,7 @@ class Project < ActiveRecord::Base
validates :creator, presence: true, on: :create
validates :description, length: { maximum: 2000 }, allow_blank: true
validates :ci_config_path,
format: { without: /(\.{2}|\A\/)/,
format: { without: %r{(\.{2}|\A/)},
message: 'cannot include leading slash or directory traversal.' },
length: { maximum: 255 },
allow_blank: true
Loading
Loading
@@ -1338,7 +1338,7 @@ class Project < ActiveRecord::Base
host = "#{subdomain}.#{Settings.pages.host}".downcase
 
# The host in URL always needs to be downcased
url = Gitlab.config.pages.url.sub(/^https?:\/\//) do |prefix|
url = Gitlab.config.pages.url.sub(%r{^https?://}) do |prefix|
"#{prefix}#{subdomain}."
end.downcase
 
Loading
Loading
Loading
Loading
@@ -84,7 +84,7 @@ http://app.asana.com/-/account_api'
# - fix/ed/es/ing
# - close/s/d
# - closing
issue_finder = /(fix\w*|clos[ei]\w*+)?\W*(?:https:\/\/app\.asana\.com\/\d+\/\d+\/(\d+)|#(\d+))/i
issue_finder = %r{(fix\w*|clos[ei]\w*+)?\W*(?:https://app\.asana\.com/\d+/\d+/(\d+)|#(\d+))}i
 
message.scan(issue_finder).each do |tuple|
# tuple will be
Loading
Loading
Loading
Loading
@@ -10,9 +10,9 @@ class IssueTrackerService < Service
# overriden patterns. See ReferenceRegexes::EXTERNAL_PATTERN
def self.reference_pattern(only_long: false)
if only_long
%r{(\b[A-Z][A-Z0-9_]+-)(?<issue>\d+)}
/(\b[A-Z][A-Z0-9_]+-)(?<issue>\d+)/
else
%r{(\b[A-Z][A-Z0-9_]+-|#{Issue.reference_prefix})(?<issue>\d+)}
/(\b[A-Z][A-Z0-9_]+-|#{Issue.reference_prefix})(?<issue>\d+)/
end
end
 
Loading
Loading
Loading
Loading
@@ -19,7 +19,7 @@ class JiraService < IssueTrackerService
 
# {PROJECT-KEY}-{NUMBER} Examples: JIRA-1, PROJECT-1
def self.reference_pattern(only_long: true)
@reference_pattern ||= %r{(?<issue>\b([A-Z][A-Z0-9_]+-)\d+)}
@reference_pattern ||= /(?<issue>\b([A-Z][A-Z0-9_]+-)\d+)/
end
 
def initialize_properties
Loading
Loading
Loading
Loading
@@ -842,13 +842,13 @@ class User < ActiveRecord::Base
end
 
def full_website_url
return "http://#{website_url}" if website_url !~ /\Ahttps?:\/\//
return "http://#{website_url}" if website_url !~ %r{\Ahttps?://}
 
website_url
end
 
def short_website_url
website_url.sub(/\Ahttps?:\/\//, '')
website_url.sub(%r{\Ahttps?://}, '')
end
 
def all_ssh_keys
Loading
Loading
---
title: Enable RuboCop Style/RegexpLiteral
merge_request: 16752
author: Takuya Noguchi
type: other
Loading
Loading
@@ -110,7 +110,7 @@ class Settings < Settingslogic
url = "http://#{url}" unless url.start_with?('http')
 
# Get rid of the path so that we don't even have to encode it
url_without_path = url.sub(%r{(https?://[^\/]+)/?.*}, '\1')
url_without_path = url.sub(%r{(https?://[^/]+)/?.*}, '\1')
 
URI.parse(url_without_path).host
end
Loading
Loading
@@ -469,10 +469,10 @@ end
# repository_downloads_path value.
#
repositories_storages = Settings.repositories.storages.values
repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(/\/$/, '')
repository_downloads_path = Settings.gitlab['repository_downloads_path'].to_s.gsub(%r{/$}, '')
repository_downloads_full_path = File.expand_path(repository_downloads_path, Settings.gitlab['user_home'])
 
if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs['path'].gsub(/\/$/, '')) }
if repository_downloads_path.blank? || repositories_storages.any? { |rs| [repository_downloads_path, repository_downloads_full_path].include?(rs['path'].gsub(%r{/$}, '')) }
Settings.gitlab['repository_downloads_path'] = File.join(Settings.shared['path'], 'cache/archive')
end
 
Loading
Loading
Loading
Loading
@@ -54,7 +54,7 @@ elsif Gitlab::Database.mysql?
def initialize_type_map(mapping)
super mapping
 
mapping.register_type(%r(timestamp)i) do |sql_type|
mapping.register_type(/timestamp/i) do |sql_type|
precision = extract_precision(sql_type)
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlDateTimeWithTimeZone.new(precision: precision)
end
Loading
Loading
namespace :admin do
resources :users, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
resources :users, constraints: { id: %r{[a-zA-Z./0-9_\-]+} } do
resources :keys, only: [:show, :destroy]
resources :identities, except: [:show]
resources :impersonation_tokens, only: [:index, :create] do
Loading
Loading
Loading
Loading
@@ -35,7 +35,7 @@ constraints(GroupUrlConstrainer.new) do
post :toggle_subscription, on: :member
end
 
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :edit, :update, :new, :create] do
resources :milestones, constraints: { id: %r{[^/]+} }, only: [:index, :show, :edit, :update, :new, :create] do
member do
get :merge_requests
get :participants
Loading
Loading
@@ -52,7 +52,7 @@ constraints(GroupUrlConstrainer.new) do
 
resources :uploads, only: [:create] do
collection do
get ":secret/:filename", action: :show, as: :show, constraints: { filename: /[^\/]+/ }
get ":secret/:filename", action: :show, as: :show, constraints: { filename: %r{[^/]+} }
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment