From 62a930cc65472133123f674c4bbdfcbd822cc731 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Wed, 11 Jan 2023 13:31:57 +0000 Subject: [PATCH] Fix RuboCop offense Performance/RedundantMatch (#38146). git-svn-id: https://svn.redmine.org/redmine/trunk@22032 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .rubocop_todo.yml | 7 ------- app/models/issue_relation.rb | 2 +- lib/redmine/wiki_formatting/textile/formatter.rb | 2 +- lib/redmine/wiki_formatting/textile/redcloth3.rb | 4 ++-- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 87e78d17d..b794a7124 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -486,13 +486,6 @@ Naming/VariableNumber: - 'test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb' - 'test/unit/project_test.rb' -# This cop supports safe autocorrection (--autocorrect). -Performance/RedundantMatch: - Exclude: - - 'app/models/issue_relation.rb' - - 'lib/redmine/wiki_formatting/textile/formatter.rb' - - 'lib/redmine/wiki_formatting/textile/redcloth3.rb' - # This cop supports safe autocorrection (--autocorrect). Performance/RedundantSplitRegexpArgument: Exclude: diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb index f2821340f..639c88e5e 100644 --- a/app/models/issue_relation.rb +++ b/app/models/issue_relation.rb @@ -91,7 +91,7 @@ class IssueRelation < ActiveRecord::Base attrs = attrs.deep_dup if issue_id = attrs.delete('issue_to_id') - if issue_id.to_s.strip.match(/\A#?(\d+)\z/) + if issue_id.to_s.strip =~ /\A#?(\d+)\z/ issue_id = $1.to_i self.issue_to = Issue.visible(user).find_by_id(issue_id) end diff --git a/lib/redmine/wiki_formatting/textile/formatter.rb b/lib/redmine/wiki_formatting/textile/formatter.rb index 04464763e..53c04341d 100644 --- a/lib/redmine/wiki_formatting/textile/formatter.rb +++ b/lib/redmine/wiki_formatting/textile/formatter.rb @@ -109,7 +109,7 @@ module Redmine text.gsub!(//) do content = @pre_list[$1.to_i] # This regex must match any data produced by RedCloth3#rip_offtags - if content.match(/\s?(.*)/m) + if content =~ /\s?(.*)/m language = $1 || $2 text = $3 # original language for extension development diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb index 637f2883e..77bfa0ab6 100644 --- a/lib/redmine/wiki_formatting/textile/redcloth3.rb +++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb @@ -1100,9 +1100,9 @@ class RedCloth3 < String ### and it breaks following lines htmlesc( aftertag, :NoQuotes ) if aftertag && escape_aftertag && !first.match(//) line = +"" - first.match(/<#{OFFTAGS}([^>]*)>/o) + first =~ /<#{OFFTAGS}([^>]*)>/o tag = $1 - $2.to_s.match(/(class\=("[^"]+"|'[^']+'))/i) + $2.to_s =~ /(class\=("[^"]+"|'[^']+'))/i tag << " #{$1}" if $1 && tag == 'code' @pre_list << +"<#{tag}>#{aftertag}" end