From d7d85cd85f8f0dee246db549facf2f32a3ca4046 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Tue, 15 Oct 2019 17:25:19 +0000 Subject: [PATCH] code cleanup: rubocop: fix Layout/SpaceInsideStringInterpolation in lib/redmine/wiki_formatting/textile/redcloth3.rb git-svn-id: http://svn.redmine.org/redmine/trunk@18684 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .rubocop_todo.yml | 1 - .../wiki_formatting/textile/redcloth3.rb | 130 +++++++++--------- 2 files changed, 65 insertions(+), 66 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9688ab113..28f2213e3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -404,7 +404,6 @@ Layout/SpaceInsideStringInterpolation: - 'app/models/issue_query.rb' - 'app/models/mail_handler.rb' - 'lib/redmine/core_ext/string/inflections.rb' - - 'lib/redmine/wiki_formatting/textile/redcloth3.rb' - 'test/integration/admin_test.rb' Lint/AmbiguousBlockAssociation: diff --git a/lib/redmine/wiki_formatting/textile/redcloth3.rb b/lib/redmine/wiki_formatting/textile/redcloth3.rb index d68c3a264..52ade2290 100644 --- a/lib/redmine/wiki_formatting/textile/redcloth3.rb +++ b/lib/redmine/wiki_formatting/textile/redcloth3.rb @@ -255,7 +255,7 @@ class RedCloth3 < String # #=>"

A <b>bold</b> man

" # def initialize( string, restrictions = [] ) - restrictions.each { |r| method( "#{ r }=" ).call( true ) } + restrictions.each { |r| method( "#{r}=" ).call( true ) } super( string ) end @@ -333,7 +333,7 @@ class RedCloth3 < String [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732], [153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]]. collect! do |a, b| - [a.chr, ( b.zero? and "" or "&#{ b };" )] + [a.chr, ( b.zero? and "" or "&#{b};" )] end # # Regular expressions to convert to HTML. @@ -471,12 +471,12 @@ class RedCloth3 < String if element == 'td' colspan = $1 if text =~ /\\(\d+)/ rowspan = $1 if text =~ /\/(\d+)/ - style << "vertical-align:#{ v_align( $& ) };" if text =~ A_VLGN + style << "vertical-align:#{v_align($&)};" if text =~ A_VLGN end if text.sub!( /\{([^"}]*)\}/, '' ) && !filter_styles sanitized = sanitize_styles($1) - style << "#{ sanitized };" unless sanitized.blank? + style << "#{sanitized};" unless sanitized.blank? end lang = $1 if @@ -485,12 +485,12 @@ class RedCloth3 < String cls = $1 if text.sub!( /\(([^()]+?)\)/, '' ) - style << "padding-left:#{ $1.length }em;" if + style << "padding-left:#{$1.length}em;" if text.sub!( /([(]+)/, '' ) - style << "padding-right:#{ $1.length }em;" if text.sub!( /([)]+)/, '' ) + style << "padding-right:#{$1.length}em;" if text.sub!( /([)]+)/, '' ) - style << "text-align:#{ h_align( $& ) };" if text =~ A_HLGN + style << "text-align:#{h_align($&)};" if text =~ A_HLGN cls, id = $1, $2 if cls =~ /^(.*?)#(.*)$/ @@ -503,12 +503,12 @@ class RedCloth3 < String id = id.starts_with?('wiki-id-') ? id : "wiki-id-#{id}" if id atts = +'' - atts << " style=\"#{ style.join }\"" unless style.empty? - atts << " class=\"#{ cls }\"" unless cls.to_s.empty? - atts << " lang=\"#{ lang }\"" if lang - atts << " id=\"#{ id }\"" if id - atts << " colspan=\"#{ colspan }\"" if colspan - atts << " rowspan=\"#{ rowspan }\"" if rowspan + atts << " style=\"#{style.join}\"" unless style.empty? + atts << " class=\"#{cls}\"" unless cls.to_s.empty? + atts << " lang=\"#{lang}\"" if lang + atts << " id=\"#{id}\"" if id + atts << " colspan=\"#{colspan}\"" if colspan + atts << " rowspan=\"#{rowspan}\"" if rowspan atts end @@ -545,12 +545,12 @@ class RedCloth3 < String catts = pba( modifiers, 'td' ) if modifiers catts = shelve( catts ) if catts - cells << "\t\t\t#{ cell }" + cells << "\t\t\t#{cell}" end ratts = shelve( ratts ) if ratts - rows << "\t\t\n#{ cells.join( "\n" ) }\n\t\t" + rows << "\t\t\n#{cells.join("\n")}\n\t\t" end - "\t\n#{ rows.join( "\n" ) }\n\t\n\n" + "\t\n#{rows.join("\n")}\n\t\n\n" end end @@ -570,7 +570,7 @@ class RedCloth3 < String if depth.last.length > tl.length (depth.length - 1).downto(0) do |i| break if depth[i].length == tl.length - lines[line_id - 1] << "\n\t\n\t" + lines[line_id - 1] << "\n\t\n\t" depth.pop end end @@ -582,9 +582,9 @@ class RedCloth3 < String depth << tl atts = pba( atts ) atts = shelve( atts ) if atts - lines[line_id] = +"\t<#{ lT(tl) }l#{ atts }>\n\t
  • #{ content }" + lines[line_id] = +"\t<#{lT(tl)}l#{atts}>\n\t
  • #{content}" else - lines[line_id] = +"\t\t
  • #{ content }" + lines[line_id] = +"\t\t
  • #{content}" end last_line = line_id @@ -593,7 +593,7 @@ class RedCloth3 < String end if line_id - last_line > 1 or line_id == lines.length - 1 while v = depth.pop - lines[last_line] << "
  • \n\t" + lines[last_line] << "\n\t" end end end @@ -634,8 +634,8 @@ class RedCloth3 < String def inline_textile_code( text ) text.gsub!( CODE_RE ) do |m| before,lang,code,after = $~[1..4] - lang = " lang=\"#{ lang }\"" if lang - rip_offtags( +"#{ before }#{ code }#{ after }", false ) + lang = " lang=\"#{lang}\"" if lang + rip_offtags( +"#{before}#{code}#{after}", false ) end end @@ -680,13 +680,13 @@ class RedCloth3 < String end if block_applied.zero? if deep_code - blk = "\t
    #{ blk }
    " + blk = "\t
    #{blk}
    " else - blk = "\t

    #{ blk }

    " + blk = "\t

    #{blk}

    " end end # hard_break blk - blk + "\n#{ code_blk }" + blk + "\n#{code_blk}" end end end.join( "\n\n" ) ) @@ -694,14 +694,14 @@ class RedCloth3 < String def textile_bq( tag, atts, cite, content ) cite, cite_title = check_refs( cite ) - cite = " cite=\"#{ cite }\"" if cite + cite = " cite=\"#{cite}\"" if cite atts = shelve( atts ) if atts - "\t\n\t\t#{ content }

    \n\t" + "\t\n\t\t#{content}

    \n\t" end def textile_p( tag, atts, cite, content ) atts = shelve( atts ) if atts - "\t<#{ tag }#{ atts }>#{ content }" + "\t<#{tag}#{atts}>#{content}" end alias textile_h1 textile_p @@ -712,10 +712,10 @@ class RedCloth3 < String alias textile_h6 textile_p def textile_fn_( tag, num, atts, cite, content ) - atts << " id=\"fn#{ num }\" class=\"footnote\"" - content = "#{ num } #{ content }" + atts << " id=\"fn#{num}\" class=\"footnote\"" + content = "#{num} #{content}" atts = shelve( atts ) if atts - "\t#{ content }

    " + "\t#{content}

    " end BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m @@ -727,10 +727,10 @@ class RedCloth3 < String # pass to prefix handler replacement = nil - if respond_to? "textile_#{ tag }", true - replacement = method( "textile_#{ tag }" ).call( tag, atts, cite, content ) - elsif respond_to? "textile_#{ tagpre }_", true - replacement = method( "textile_#{ tagpre }_" ).call( tagpre, num, atts, cite, content ) + if respond_to? "textile_#{tag}", true + replacement = method( "textile_#{tag}" ).call( tag, atts, cite, content ) + elsif respond_to? "textile_#{tagpre}_", true + replacement = method( "textile_#{tagpre}_" ).call( tagpre, num, atts, cite, content ) end text.gsub!( $& ) { replacement } if replacement end @@ -740,7 +740,7 @@ class RedCloth3 < String def block_markdown_setext( text ) if text =~ SETEXT_RE tag = ($2 == "=" ? "h1" : "h2") - blk, cont = "<#{ tag }>#{ $1 }", $' + blk, cont = "<#{tag}>#{$1}", $' blocks cont text.replace( blk + cont ) end @@ -754,8 +754,8 @@ class RedCloth3 < String $/x def block_markdown_atx( text ) if text =~ ATX_RE - tag = "h#{ $1.length }" - blk, cont = "<#{ tag }>#{ $2 }\n\n", $' + tag = "h#{$1.length}" + blk, cont = "<#{tag}>#{$2}\n\n", $' blocks cont text.replace( blk + cont ) end @@ -769,7 +769,7 @@ class RedCloth3 < String flush_left blk blocks blk blk.gsub!( /^(\S)/, "\t\\1" ) - "
    \n#{ blk }\n
    \n\n" + "
    \n#{blk}\n
    \n\n" end end @@ -804,7 +804,7 @@ class RedCloth3 < String atts = pba( atts ) atts = shelve( atts ) if atts - "#{ sta }#{ oqs }<#{ ht }#{ atts }>#{ content }#{ oqa }" + "#{sta}#{oqs}<#{ht}#{atts}>#{content}#{oqa}" end end end @@ -844,13 +844,13 @@ class RedCloth3 < String post = ")"+post # add closing parenth to post end atts = pba( atts ) - atts = +" href=\"#{ htmlesc url }#{ slash }\"#{ atts }" - atts << " title=\"#{ htmlesc title }\"" if title + atts = +" href=\"#{htmlesc url}#{slash}\"#{atts}" + atts << " title=\"#{htmlesc title}\"" if title atts = shelve( atts ) if atts external = (url =~ /^https?:\/\//) ? ' class="external"' : '' - "#{ pre }#{ text }#{ post }" + "#{pre}#{text}#{post}" end end end @@ -872,11 +872,11 @@ class RedCloth3 < String url, title = check_refs( id ) end - atts = " href=\"#{ url }\"" - atts << " title=\"#{ title }\"" if title + atts = " href=\"#{url}\"" + atts << " title=\"#{title}\"" if title atts = shelve( atts ) - "#{ text }" + "#{text}" end end @@ -898,11 +898,11 @@ class RedCloth3 < String text.gsub!( MARKDOWN_LINK_RE ) do |m| text, url, quote, title = $~[1..4] - atts = " href=\"#{ url }\"" - atts << " title=\"#{ title }\"" if title + atts = " href=\"#{url}\"" + atts << " title=\"#{title}\"" if title atts = shelve( atts ) - "#{ text }" + "#{text}" end end @@ -947,7 +947,7 @@ class RedCloth3 < String \s? # optional space (?:\(((?:[^\(\)]|\([^\)]+\))+?)\))? # optional title \! # closing - (?::#{ HYPERLINK })? # optional href + (?::#{HYPERLINK})? # optional href /x def inline_textile_image( text ) @@ -955,9 +955,9 @@ class RedCloth3 < String stln,algn,atts,url,title,href,href_a1,href_a2 = $~[1..8] htmlesc title atts = pba( atts ) - atts = +" src=\"#{ htmlesc url.dup }\"#{ atts }" - atts << " title=\"#{ title }\"" if title - atts << " alt=\"#{ title }\"" + atts = +" src=\"#{htmlesc url.dup}\"#{atts}" + atts << " title=\"#{title}\"" if title + atts << " alt=\"#{title}\"" # size = @getimagesize($url); # if($size) $atts.= " $size[3]"; @@ -967,16 +967,16 @@ class RedCloth3 < String next m unless uri_with_safe_scheme?(url) out = +'' - out << "" if href - out << "" - out << "#{ href_a1 }#{ href_a2 }" if href + out << "" if href + out << "" + out << "#{href_a1}#{href_a2}" if href if algn algn = h_align( algn ) if stln == "

    " - out = "

    #{ out }" + out = "

    #{out}" else - out = "#{ stln }#{ out }" + out = "#{stln}#{out}" end else out = stln + out @@ -988,7 +988,7 @@ class RedCloth3 < String def shelve( val ) @shelf << val - " :redsh##{ @shelf.length }:" + " :redsh##{@shelf.length}:" end def retrieve( text ) @@ -1044,9 +1044,9 @@ class RedCloth3 < String end OFFTAGS = /(code|pre|kbd|notextile)/ - OFFTAG_MATCH = /(?:(<\/#{ OFFTAGS }\b>)|(<#{ OFFTAGS }\b[^>]*>))(.*?)(?=<\/?#{ OFFTAGS }\b\W|\Z)/mi - OFFTAG_OPEN = /<#{ OFFTAGS }/ - OFFTAG_CLOSE = /<\/?#{ OFFTAGS }/ + OFFTAG_MATCH = /(?:(<\/#{OFFTAGS}\b>)|(<#{OFFTAGS}\b[^>]*>))(.*?)(?=<\/?#{OFFTAGS}\b\W|\Z)/mi + OFFTAG_OPEN = /<#{OFFTAGS}/ + OFFTAG_CLOSE = /<\/?#{OFFTAGS}/ HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m @@ -1096,12 +1096,12 @@ class RedCloth3 < String ### NB: some changes were made not to use $N variables, because we use "match" ### and it breaks following lines htmlesc( aftertag, :NoQuotes ) if aftertag && escape_aftertag && !first.match(//) - line = +"" - first.match(/<#{ OFFTAGS }([^>]*)>/) + line = +"" + first.match(/<#{OFFTAGS}([^>]*)>/) tag = $1 $2.to_s.match(/(class\=("[^"]+"|'[^']+'))/i) tag << " #{$1}" if $1 && tag == 'code' - @pre_list << +"<#{ tag }>#{ aftertag }" + @pre_list << +"<#{tag}>#{aftertag}" end elsif $1 and codepre > 0 if codepre - used_offtags.length > 0 -- 2.39.5