Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
06087d01205f
Commit
06087d01
authored
Jan 27, 2018
by
Takuya Noguchi
Browse files
Enable RuboCop Style/RegexpLiteral
parent
08892b08cb1e
Changes
84
Hide whitespace changes
Inline
Side-by-side
.rubocop_todo.yml
View file @
06087d01
...
...
@@ -704,7 +704,9 @@
# 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.
...
...
app/controllers/help_controller.rb
View file @
06087d01
...
...
@@ -5,7 +5,7 @@
# 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
...
...
app/controllers/projects_controller.rb
View file @
06087d01
...
...
@@ -403,6 +403,6 @@
# 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
app/helpers/sidekiq_helper.rb
View file @
06087d01
module
SidekiqHelper
SIDEKIQ_PS_REGEXP
=
/
\A
SIDEKIQ_PS_REGEXP
=
%r{
\A
(?<pid>
\d
+)
\s
+
(?<cpu>[
\d\.
,]+)
\s
+
(?<mem>[
\d\.
,]+)
\s
+
...
...
@@ -3,6 +3,6 @@
(?<pid>
\d
+)
\s
+
(?<cpu>[
\d\.
,]+)
\s
+
(?<mem>[
\d\.
,]+)
\s
+
(?<state>[DIEKNRSTVWXZNLpsl\+<>
\
/\d]+)\s+
(?<state>[DIEKNRSTVWXZNLpsl
\+
<>/
\d
]+)
\s
+
(?<start>.+?)
\s
+
(?<command>(?:ruby
\d
+:
\s
+)?sidekiq.*
\]
.*)
...
...
@@ -7,6 +7,6 @@
(?<start>.+?)
\s
+
(?<command>(?:ruby
\d
+:
\s
+)?sidekiq.*
\]
.*)
\z
/
x
\z
}
x
def
parse_sidekiq_ps
(
line
)
match
=
line
.
strip
.
match
(
SIDEKIQ_PS_REGEXP
)
...
...
app/helpers/submodule_helper.rb
View file @
06087d01
...
...
@@ -11,7 +11,7 @@
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
]
...
...
@@ -23,7 +23,7 @@
end
end
namespace
.
sub!
(
/\A\//
,
''
)
namespace
.
sub!
(
%r{
\A
/}
,
''
)
project
.
rstrip!
project
.
sub!
(
/\.git\z/
,
''
)
...
...
@@ -47,7 +47,7 @@
protected
def
github_dot_com_url?
(
url
)
url
=~
/
github\.com[
\
/:][^
\
/]+
\
/[^
\
/]+\Z
/
url
=~
%r{
github
\.
com[/:][^/]+/[^/]+
\Z
}
end
def
gitlab_dot_com_url?
(
url
)
...
...
@@ -51,7 +51,7 @@
end
def
gitlab_dot_com_url?
(
url
)
url
=~
/
gitlab\.com[
\
/:][^
\
/]+
\
/[^
\
/]+\Z
/
url
=~
%r{
gitlab
\.
com[/:][^/]+/[^/]+
\Z
}
end
def
self_url?
(
url
,
namespace
,
project
)
...
...
@@ -65,7 +65,7 @@
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
)
...
...
app/helpers/tree_helper.rb
View file @
06087d01
...
...
@@ -110,7 +110,7 @@
# 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?
...
...
app/models/ci/build.rb
View file @
06087d01
...
...
@@ -292,7 +292,7 @@
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
...
...
app/models/commit_status.rb
View file @
06087d01
...
...
@@ -141,7 +141,7 @@
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?
...
...
app/models/concerns/taskable.rb
View file @
06087d01
...
...
@@ -9,9 +9,9 @@
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.
...
...
@@ -13,9 +13,9 @@
^
\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
|
...
...
app/models/environment.rb
View file @
06087d01
...
...
@@ -115,7 +115,7 @@
def
formatted_external_url
return
nil
unless
external_url
external_url
.
gsub
(
/
\A.*?:
\/\
//
,
''
)
external_url
.
gsub
(
%r{
\A
.*?://
}
,
''
)
end
def
stop_action?
...
...
app/models/project.rb
View file @
06087d01
...
...
@@ -234,7 +234,7 @@
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
...
...
@@ -1338,7 +1338,7 @@
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
...
...
app/models/project_services/asana_service.rb
View file @
06087d01
...
...
@@ -84,7 +84,7 @@
# - 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
...
...
app/models/project_services/issue_tracker_service.rb
View file @
06087d01
...
...
@@ -10,5 +10,5 @@
# 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
...
...
@@ -14,5 +14,5 @@
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
...
...
app/models/project_services/jira_service.rb
View file @
06087d01
...
...
@@ -19,7 +19,7 @@
# {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
...
...
app/models/user.rb
View file @
06087d01
...
...
@@ -842,9 +842,9 @@
end
def
full_website_url
return
"http://
#{
website_url
}
"
if
website_url
!~
/
\Ahttps?:
\/\
//
return
"http://
#{
website_url
}
"
if
website_url
!~
%r{
\A
https?://
}
website_url
end
def
short_website_url
...
...
@@ -846,9 +846,9 @@
website_url
end
def
short_website_url
website_url
.
sub
(
/
\Ahttps?:
\/\
//
,
''
)
website_url
.
sub
(
%r{
\A
https?://
}
,
''
)
end
def
all_ssh_keys
...
...
changelogs/unreleased/42497-rubocop-style-regexpliteral.yml
0 → 100644
View file @
06087d01
---
title
:
Enable RuboCop Style/RegexpLiteral
merge_request
:
16752
author
:
Takuya Noguchi
type
:
other
config/initializers/1_settings.rb
View file @
06087d01
...
...
@@ -110,7 +110,7 @@
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
...
...
@@ -469,6 +469,6 @@
# 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'
])
...
...
@@ -473,6 +473,6 @@
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
...
...
config/initializers/active_record_data_types.rb
View file @
06087d01
...
...
@@ -54,7 +54,7 @@
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
...
...
config/routes/admin.rb
View file @
06087d01
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
...
...
config/routes/group.rb
View file @
06087d01
...
...
@@ -35,7 +35,7 @@
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
...
...
@@ -52,7 +52,7 @@
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
...
...
Prev
1
2
3
4
5
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment