Project

General

Profile

Patch #38146 » 0004-Fix-RuboCop-offense-Performance-ConstantRegexp.patch

Go MAEDA, 2023-01-04 07:28

View differences:

.rubocop_todo.yml
486 486
    - 'test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb'
487 487
    - 'test/unit/project_test.rb'
488 488

  
489
# This cop supports safe autocorrection (--autocorrect).
490
Performance/ConstantRegexp:
491
  Exclude:
492
    - 'app/models/changeset.rb'
493
    - 'lib/redmine/scm/adapters/cvs_adapter.rb'
494
    - 'lib/redmine/wiki_formatting/textile/formatter.rb'
495
    - 'lib/redmine/wiki_formatting/textile/redcloth3.rb'
496

  
497 489
Performance/FixedSize:
498 490
  Exclude:
499 491
    - 'test/integration/api_test/issues_test.rb'
app/models/changeset.rb
144 144
      refs   = match[3]
145 145
      next unless action.present? || ref_keywords_any
146 146

  
147
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
147
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/o).each do |m|
148 148
        issue = find_referenced_issue_by_id(m[0].to_i)
149 149
        hours = m[2]
150 150
        if issue && !issue_linked_to_same_commit?(issue)
lib/redmine/scm/adapters/cvs_adapter.rb
179 179
            file_state = nil
180 180
            branch_map = nil
181 181
            io.each_line() do |line|
182
              if state != "revision" && /^#{ENDLOG}/.match?(line)
182
              if state != "revision" && /^#{ENDLOG}/o.match?(line)
183 183
                commit_log = ""
184 184
                revision   = nil
185 185
                state      = "entry_start"
......
194 194
                  entry_headRev = $1
195 195
                elsif /^symbolic names:/.match?(line)
196 196
                  state = "symbolic"
197
                elsif /^#{STARTLOG}/.match?(line)
197
                elsif /^#{STARTLOG}/o.match?(line)
198 198
                  commit_log = ""
199 199
                  state      = "revision"
200 200
                end
......
207 207
                  next
208 208
                end
209 209
              elsif state == "tags"
210
                if /^#{STARTLOG}/.match?(line)
210
                if /^#{STARTLOG}/o.match?(line)
211 211
                  commit_log = ""
212 212
                  state = "revision"
213
                elsif /^#{ENDLOG}/.match?(line)
213
                elsif /^#{ENDLOG}/o.match?(line)
214 214
                  state = "head"
215 215
                end
216 216
                next
217 217
              elsif state == "revision"
218
                if /^#{ENDLOG}/ =~ line || /^#{STARTLOG}/ =~ line
218
                if /^#{ENDLOG}/o =~ line || /^#{STARTLOG}/o =~ line
219 219
                  if revision
220 220
                    revHelper = CvsRevisionHelper.new(revision)
221 221
                    revBranch = "HEAD"
......
245 245
                  end
246 246
                  commit_log = ""
247 247
                  revision   = nil
248
                  if /^#{ENDLOG}/.match?(line)
248
                  if /^#{ENDLOG}/o.match?(line)
249 249
                    state = "entry_start"
250 250
                  end
251 251
                  next
lib/redmine/wiki_formatting/textile/formatter.rb
57 57
          l = 1
58 58
          started = false
59 59
          ended = false
60
          text.scan(/(((?:.*?)(\A|\r?\n\s*\r?\n))(h(\d+)(#{A}#{C})\.(?::(\S+))?[ \t](.*?)$)|.*)/m).each do |all, content, lf, heading, level|
60
          text.scan(/(((?:.*?)(\A|\r?\n\s*\r?\n))(h(\d+)(#{A}#{C})\.(?::(\S+))?[ \t](.*?)$)|.*)/mo).each do |all, content, lf, heading, level|
61 61
            if heading.nil?
62 62
              if ended
63 63
                after << all
lib/redmine/wiki_formatting/textile/redcloth3.rb
532 532
            rows = []
533 533
            fullrow.gsub!(/([^|\s])\s*\n/, "\\1<br />")
534 534
            fullrow.each_line do |row|
535
                ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/m
535
                ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/mo
536 536
                cells = []
537 537
                # the regexp prevents wiki links with a | from being cut as cells
538
                row.scan(/\|(_?#{S}#{A}#{C}\. ?)?((\[\[[^|\]]*\|[^|\]]*\]\]|[^|])*?)(?=\|)/) do |modifiers, cell|
538
                row.scan(/\|(_?#{S}#{A}#{C}\. ?)?((\[\[[^|\]]*\|[^|\]]*\]\]|[^|])*?)(?=\|)/o) do |modifiers, cell|
539 539
                    ctyp = 'd'
540 540
                    ctyp = 'h' if modifiers && modifiers =~ /^_/
541 541

  
......
791 791
                when :limit
792 792
                    sta,oqs,qtag,content,oqa = $~[1..6]
793 793
                    atts = nil
794
                    if content =~ /^(#{C})(.+)$/
794
                    if content =~ /^(#{C})(.+)$/o
795 795
                      atts, content = $~[1..2]
796 796
                    end
797 797
                else
......
1100 1100
                        ###   and it breaks following lines
1101 1101
                        htmlesc( aftertag, :NoQuotes ) if aftertag && escape_aftertag && !first.match(/<code\s+class="(\w+)">/)
1102 1102
                        line = +"<redpre##{@pre_list.length}>"
1103
                        first.match(/<#{OFFTAGS}([^>]*)>/)
1103
                        first.match(/<#{OFFTAGS}([^>]*)>/o)
1104 1104
                        tag = $1
1105 1105
                        $2.to_s.match(/(class\=("[^"]+"|'[^']+'))/i)
1106 1106
                        tag << " #{$1}" if $1 && tag == 'code'
(4-4/9)