From 15d33f68277b250c977e90b3e05b6856509b6b92 Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 11 Apr 2025 08:37:27 +0000 Subject: Fix RuboCop Style/RedundantFormat by renaming custom `format` method to `to_html` to avoid name conflict with `Kernel#format` (#41884). git-svn-id: https://svn.redmine.org/redmine/trunk@23624 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .rubocop_todo.yml | 5 -- .../wiki_formatting/common_mark/formatter_test.rb | 64 +++++++++++----------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0811d53c2..b27123b26 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1135,11 +1135,6 @@ Style/RedundantConditional: - 'app/models/enumeration.rb' - 'lib/redmine/field_format.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/RedundantFormat: - Exclude: - - 'test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Style/RedundantInterpolation: Exclude: diff --git a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb index 5214a1e00..11d5913ce 100644 --- a/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/common_mark/formatter_test.rb @@ -26,71 +26,71 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase @formatter = Redmine::WikiFormatting::CommonMark::Formatter end - def format(text) + def to_html(text) @formatter.new(text).to_html end def test_should_render_hard_breaks html ="

foo
\nbar

" - assert_equal html, format("foo\\\nbar") - assert_equal html, format("foo \nbar") + assert_equal html, to_html("foo\\\nbar") + assert_equal html, to_html("foo \nbar") end def test_should_render_soft_breaks - assert_equal "

foo
\nbar

", format("foo\nbar") + assert_equal "

foo
\nbar

", to_html("foo\nbar") end def test_syntax_error_in_image_reference_should_not_raise_exception - assert format("!>[](foo.png)") + assert to_html("!>[](foo.png)") end def test_empty_image_should_not_raise_exception - assert format("![]()") + assert to_html("![]()") end def test_inline_style - assert_equal "

foo

", format("**foo**") + assert_equal "

foo

", to_html("**foo**") end def test_not_set_intra_emphasis - assert_equal "

foo_bar_baz

", format("foo_bar_baz") + assert_equal "

foo_bar_baz

", to_html("foo_bar_baz") end def test_wiki_links_should_be_preserved text = 'This is a wiki link: [[Foo]]' - assert_include '[[Foo]]', format(text) + assert_include '[[Foo]]', to_html(text) end def test_redmine_links_with_double_quotes_should_be_preserved text = 'This is a redmine link: version:"1.0"' - assert_include 'version:"1.0"', format(text) + assert_include 'version:"1.0"', to_html(text) end def test_links_by_id_should_be_preserved text = "[project#3]" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) end def test_links_to_users_should_be_preserved text = "[@login]" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) text = "[user:login]" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) text = "user:user@example.org" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) text = "[user:user@example.org]" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) text = "@user@example.org" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) text = "[@user@example.org]" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) end def test_files_with_at_should_not_end_up_as_mailto_links text = "printscreen@2x.png" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) text = "[printscreen@2x.png]" - assert_equal "

#{text}

", format(text) + assert_equal "

#{text}

", to_html(text) end def test_should_support_syntax_highlight @@ -100,7 +100,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase end ~~~ STR - assert_select_in format(text), 'pre code.ruby.syntaxhl' do + assert_select_in to_html(text), 'pre code.ruby.syntaxhl' do assert_select 'span.k', :text => 'def' assert_select "[data-language='ruby']" end @@ -114,7 +114,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase ~~~ STR - assert_select_in format(text), 'pre' do + assert_select_in to_html(text), 'pre' do assert_select 'code[class=?]', "c++ syntaxhl" assert_select 'span.kt', :text => 'int' assert_select "[data-language=?]", "c++" @@ -123,12 +123,12 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase def test_external_links_should_have_external_css_class text = 'This is a [link](http://example.net/)' - assert_equal '

This is a link

', format(text) + assert_equal '

This is a link

', to_html(text) end def test_locals_links_should_not_have_external_css_class text = 'This is a [link](/issues)' - assert_equal '

This is a link

', format(text) + assert_equal '

This is a link

', to_html(text) end def test_markdown_should_not_require_surrounded_empty_line @@ -137,7 +137,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase * One * Two STR - assert_equal "

This is a list:

\n", format(text) + assert_equal "

This is a list:

\n", to_html(text) end def test_footnotes @@ -156,7 +156,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase EXPECTED - assert_equal expected.gsub(%r{[\r\n\t]}, ''), format(text).gsub(%r{[\r\n\t]}, '').rstrip + assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '').rstrip end STR_WITH_PRE = [ @@ -232,12 +232,12 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase def test_should_emphasize_text text = 'This _text_ should be emphasized' - assert_equal '

This text should be emphasized

', format(text) + assert_equal '

This text should be emphasized

', to_html(text) end def test_should_strike_through_text text = 'This ~~text~~ should be striked through' - assert_equal '

This text should be striked through

', format(text) + assert_equal '

This text should be striked through

', to_html(text) end def test_should_autolink_urls_and_emails @@ -249,13 +249,13 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase ["www.example.org", '

www.example.org

'], ["user@example.org", '

'] ].each do |text, html| - assert_equal html, format(text) + assert_equal html, to_html(text) end end def test_should_support_html_tables text = '
Cell
' - assert_equal '
Cell
', format(text) + assert_equal '
Cell
', to_html(text) end def test_should_remove_unsafe_uris @@ -263,7 +263,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase ['', ''], ['click me', '

click me

'], ].each do |text, html| - assert_equal html, format(text) + assert_equal html, to_html(text) end end @@ -274,7 +274,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase %[sit
amet ] ] ].each do |expected, input| - assert_equal expected, format(input) + assert_equal expected, to_html(input) end end @@ -296,7 +296,7 @@ class Redmine::WikiFormatting::CommonMark::FormatterTest < ActionView::TestCase EXPECTED - assert_equal expected.gsub(%r{[\r\n\t]}, ''), format(text).gsub(%r{[\r\n\t]}, '').rstrip + assert_equal expected.gsub(%r{[\r\n\t]}, ''), to_html(text).gsub(%r{[\r\n\t]}, '').rstrip end private -- cgit v1.2.3