Commit 1a9d624a authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'perl-backref-cop' into 'master'

Fix Style/PerlBackrefs cop

See merge request gitlab-org/gitlab!41246
parents ba8e93fd eab8766b
......@@ -631,22 +631,6 @@ Style/ParallelAssignment:
Style/PercentLiteralDelimiters:
Enabled: false
# Offense count: 15
# Cop supports --auto-correct.
Style/PerlBackrefs:
Exclude:
- 'app/controllers/projects/application_controller.rb'
- 'app/helpers/submodule_helper.rb'
- 'lib/backup/manager.rb'
- 'lib/banzai/filter/abstract_reference_filter.rb'
- 'lib/banzai/filter/autolink_filter.rb'
- 'lib/banzai/filter/emoji_filter.rb'
- 'lib/banzai/filter/gollum_tags_filter.rb'
- 'lib/expand_variables.rb'
- 'lib/gitlab/diff/highlight.rb'
- 'lib/gitlab/search_results.rb'
- 'lib/gitlab/sherlock/query.rb'
# Offense count: 200
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
......
......@@ -58,9 +58,9 @@ class Projects::ApplicationController < ApplicationController
def method_missing(method_sym, *arguments, &block)
case method_sym.to_s
when /\Aauthorize_(.*)!\z/
authorize_action!($1.to_sym)
authorize_action!(Regexp.last_match(1).to_sym)
when /\Acheck_(.*)_available!\z/
check_project_feature_available!($1.to_sym)
check_project_feature_available!(Regexp.last_match(1).to_sym)
else
super
end
......
......@@ -18,7 +18,7 @@ module SubmoduleHelper
end
if url =~ %r{([^/:]+)/([^/]+(?:\.git)?)\Z}
namespace, project = $1, $2
namespace, project = Regexp.last_match(1), Regexp.last_match(2)
gitlab_hosts = [Gitlab.config.gitlab.url,
Gitlab.config.gitlab_shell.ssh_path_prefix]
......
---
title: Fix Style/PerlBackrefs cop
merge_request: 41246
author: Rajendra Kadam
type: fixed
......@@ -88,7 +88,7 @@ module Backup
# - 1495527097_2017_05_23_9.3.0-pre_gitlab_backup.tar
next unless file =~ /^(\d{10})(?:_\d{4}_\d{2}_\d{2}(_\d+\.\d+\.\d+((-|\.)(pre|rc\d))?(-ee)?)?)?_gitlab_backup\.tar$/
timestamp = $1.to_i
timestamp = Regexp.last_match(1).to_i
if Time.at(timestamp) < (Time.now - keep_time)
begin
......
......@@ -265,7 +265,7 @@ module Banzai
extras = []
if matches.names.include?("anchor") && matches[:anchor] && matches[:anchor] =~ /\A\#note_(\d+)\z/
extras << "comment #{$1}"
extras << "comment #{Regexp.last_match(1)}"
end
extension = matches[:extension] if matches.names.include?("extension")
......@@ -436,7 +436,7 @@ module Banzai
escaped = escape_html_entities(text)
escaped.gsub(REFERENCE_PLACEHOLDER_PATTERN) do |match|
placeholder_data[$1.to_i]
placeholder_data[Regexp.last_match(1).to_i]
end
end
end
......
......@@ -86,7 +86,7 @@ module Banzai
# outside the link element. The entity must be marked HTML safe in
# order to be output literally rather than escaped.
match.gsub!(/((?:&[\w#]+;)+)\z/, '')
dropped = ($1 || '').html_safe
dropped = (Regexp.last_match(1) || '').html_safe
# To match the behaviour of Rinku, if the matched link ends with a
# closing part of a matched pair of punctuation, we remove that trailing
......
......@@ -33,7 +33,7 @@ module Banzai
# Returns a String with :emoji: replaced with gl-emoji unicode.
def emoji_name_element_unicode_filter(text)
text.gsub(emoji_pattern) do |match|
name = $1
name = Regexp.last_match(1)
Gitlab::Emoji.gl_emoji_tag(name)
end
end
......
......@@ -64,7 +64,7 @@ module Banzai
next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS)
next unless node.content =~ TAGS_PATTERN
html = process_tag($1)
html = process_tag(Regexp.last_match(1))
node.replace(html) if html && html != node.content
end
......
......@@ -7,7 +7,7 @@ module ExpandVariables
value.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
variables_hash ||= transform_variables(variables)
variables_hash[$1 || $2]
variables_hash[Regexp.last_match(1) || Regexp.last_match(2)]
end
end
......
......@@ -60,7 +60,7 @@ module Gitlab
# Only update text if line is found. This will prevent
# issues with submodules given the line only exists in diff content.
if rich_line
line_prefix = diff_line.text =~ /\A(.)/ ? $1 : ' '
line_prefix = diff_line.text =~ /\A(.)/ ? Regexp.last_match(1) : ' '
"#{line_prefix}#{rich_line}".html_safe
end
end
......
......@@ -186,7 +186,7 @@ module Gitlab
params[:sort] = 'updated_desc'
if query =~ /#(\d+)\z/
params[:iids] = $1
params[:iids] = Regexp.last_match(1)
else
params[:search] = query
end
......
......@@ -105,7 +105,7 @@ module Gitlab
query.each_line
.map { |line| line.strip }
.join("\n")
.gsub(PREFIX_NEWLINE) { "\n#{$1} " }
.gsub(PREFIX_NEWLINE) { "\n#{Regexp.last_match(1)} " }
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment