diff options
| author | Geremia Taglialatela <[email protected]> | 2023-05-25 14:17:12 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-25 14:17:12 +0200 |
| commit | 2a70161abe24ae130041aaca3eec79e63d08a5f5 (patch) | |
| tree | 5dd5cbdfda525eaaaf857513dafc322096eeaf47 | |
| parent | 14b7da239879d5299775c48666b43f3016add8ec (diff) | |
| download | caxlsx-2a70161abe24ae130041aaca3eec79e63d08a5f5.tar.gz caxlsx-2a70161abe24ae130041aaca3eec79e63d08a5f5.zip | |
Fix StringConcatenation offenses (non-production)
Prefer interpolation over concatenation
```
Comparison ("String#{'String'}" vs 'String' + 'String'):
interpolation: 11821321.0 i/s
concatenation: 8849491.7 i/s - 1.34x (± 0.00) slower
```
| -rw-r--r-- | .rubocop_todo.yml | 9 | ||||
| -rw-r--r-- | Rakefile | 4 | ||||
| -rw-r--r-- | test/doc_props/tc_app.rb | 2 | ||||
| -rw-r--r-- | test/doc_props/tc_core.rb | 2 | ||||
| -rw-r--r-- | test/drawing/tc_drawing.rb | 4 | ||||
| -rw-r--r-- | test/drawing/tc_hyperlink.rb | 2 | ||||
| -rw-r--r-- | test/drawing/tc_one_cell_anchor.rb | 2 | ||||
| -rw-r--r-- | test/drawing/tc_pic.rb | 8 | ||||
| -rw-r--r-- | test/util/tc_mime_type_utils.rb | 2 | ||||
| -rw-r--r-- | test/workbook/tc_shared_strings_table.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_rich_text_run.rb | 2 |
11 files changed, 23 insertions, 16 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a0260f2e..82fc6a22 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -423,7 +423,14 @@ Style/StringChars: # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: Mode. Style/StringConcatenation: - Enabled: false + Exclude: + - 'lib/axlsx/drawing/area_series.rb' + - 'lib/axlsx/drawing/line_series.rb' + - 'lib/axlsx/drawing/pie_series.rb' + - 'lib/axlsx/drawing/scatter_series.rb' + - 'lib/axlsx/stylesheet/color.rb' + - 'lib/axlsx/util/constants.rb' + - 'lib/axlsx/workbook/worksheet/worksheet.rb' # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. @@ -1,13 +1,13 @@ # frozen_string_literal: true -require File.expand_path(File.dirname(__FILE__) + '/lib/axlsx/version.rb') +require File.expand_path("#{File.dirname(__FILE__)}/lib/axlsx/version.rb") task build: :gendoc do system "gem build axlsx.gemspec" end task :benchmark do - require File.expand_path(File.dirname(__FILE__) + '/test/benchmark.rb') + require File.expand_path("#{File.dirname(__FILE__)}/test/benchmark.rb") end task :gendoc do diff --git a/test/doc_props/tc_app.rb b/test/doc_props/tc_app.rb index 82e33f12..c066373c 100644 --- a/test/doc_props/tc_app.rb +++ b/test/doc_props/tc_app.rb @@ -41,6 +41,6 @@ class TestApp < Test::Unit::TestCase errors << error end - assert_equal(0, errors.size, "app.xml invalid" + errors.map(&:message).to_s) + assert_equal(0, errors.size, "app.xml invalid#{errors.map(&:message)}") end end diff --git a/test/doc_props/tc_core.rb b/test/doc_props/tc_core.rb index bfacab45..5a04a615 100644 --- a/test/doc_props/tc_core.rb +++ b/test/doc_props/tc_core.rb @@ -18,7 +18,7 @@ class TestCore < Test::Unit::TestCase errors << error end - assert_equal(0, errors.size, "core.xml Invalid" + errors.map(&:message).to_s) + assert_equal(0, errors.size, "core.xml Invalid#{errors.map(&:message)}") end def test_populates_created diff --git a/test/drawing/tc_drawing.rb b/test/drawing/tc_drawing.rb index d7e3e8df..d48ae604 100644 --- a/test/drawing/tc_drawing.rb +++ b/test/drawing/tc_drawing.rb @@ -26,7 +26,7 @@ class TestDrawing < Test::Unit::TestCase end def test_add_image - src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + src = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg" image = @ws.add_image(image_src: src, start_at: [0, 0], width: 600, height: 400) assert(@ws.drawing.anchors.last.is_a?(Axlsx::OneCellAnchor)) @@ -36,7 +36,7 @@ class TestDrawing < Test::Unit::TestCase end def test_add_two_cell_anchor_image - src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + src = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg" image = @ws.add_image(image_src: src, start_at: [0, 0], end_at: [15, 0]) assert(@ws.drawing.anchors.last.is_a?(Axlsx::TwoCellAnchor)) diff --git a/test/drawing/tc_hyperlink.rb b/test/drawing/tc_hyperlink.rb index c3cffb1c..5a1f5d48 100644 --- a/test/drawing/tc_hyperlink.rb +++ b/test/drawing/tc_hyperlink.rb @@ -6,7 +6,7 @@ class TestHyperlink < Test::Unit::TestCase def setup @p = Axlsx::Package.new ws = @p.workbook.add_worksheet - @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + @test_img = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg" @image = ws.add_image image_src: @test_img, hyperlink: "http://axlsx.blogspot.com" @hyperlink = @image.hyperlink end diff --git a/test/drawing/tc_one_cell_anchor.rb b/test/drawing/tc_one_cell_anchor.rb index e3eb8d90..5015d123 100644 --- a/test/drawing/tc_one_cell_anchor.rb +++ b/test/drawing/tc_one_cell_anchor.rb @@ -6,7 +6,7 @@ class TestOneCellAnchor < Test::Unit::TestCase def setup @p = Axlsx::Package.new @ws = @p.workbook.add_worksheet - @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + @test_img = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg" @image = @ws.add_image image_src: @test_img @anchor = @image.anchor end diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb index dc0f32da..f4961d4c 100644 --- a/test/drawing/tc_pic.rb +++ b/test/drawing/tc_pic.rb @@ -9,10 +9,10 @@ class TestPic < Test::Unit::TestCase @p = Axlsx::Package.new ws = @p.workbook.add_worksheet - @test_img = @test_img_jpg = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" - @test_img_png = File.dirname(__FILE__) + "/../fixtures/image1.png" - @test_img_gif = File.dirname(__FILE__) + "/../fixtures/image1.gif" - @test_img_fake = File.dirname(__FILE__) + "/../fixtures/image1_fake.jpg" + @test_img = @test_img_jpg = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg" + @test_img_png = "#{File.dirname(__FILE__)}/../fixtures/image1.png" + @test_img_gif = "#{File.dirname(__FILE__)}/../fixtures/image1.gif" + @test_img_fake = "#{File.dirname(__FILE__)}/../fixtures/image1_fake.jpg" @test_img_remote_png = "https://example.com/sample-image.png" @test_img_remote_fake = "invalid_URI" @image = ws.add_image image_src: @test_img, hyperlink: 'https://github.com/randym', tooltip: "What's up doc?", opacity: 5 diff --git a/test/util/tc_mime_type_utils.rb b/test/util/tc_mime_type_utils.rb index fc7d9d79..16ba45cd 100644 --- a/test/util/tc_mime_type_utils.rb +++ b/test/util/tc_mime_type_utils.rb @@ -7,7 +7,7 @@ class TestMimeTypeUtils < Test::Unit::TestCase stub_request(:get, 'https://example.com/sample-image.png') .to_return(body: File.new('examples/sample.png'), status: 200) - @test_img = File.dirname(__FILE__) + "/../fixtures/image1.jpeg" + @test_img = "#{File.dirname(__FILE__)}/../fixtures/image1.jpeg" @test_img_url = "https://example.com/sample-image.png" end diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb index 2edf5f4a..4ac8b112 100644 --- a/test/workbook/tc_shared_strings_table.rb +++ b/test/workbook/tc_shared_strings_table.rb @@ -45,7 +45,7 @@ class TestSharedStringsTable < Test::Unit::TestCase errors << error end - assert_equal(0, errors.size, "sharedStirngs.xml Invalid" + errors.map(&:message).to_s) + assert_equal(0, errors.size, "sharedStirngs.xml Invalid#{errors.map(&:message)}") end def test_remove_control_characters_in_xml_serialization diff --git a/test/workbook/worksheet/tc_rich_text_run.rb b/test/workbook/worksheet/tc_rich_text_run.rb index 6274dda8..be05d818 100644 --- a/test/workbook/worksheet/tc_rich_text_run.rb +++ b/test/workbook/worksheet/tc_rich_text_run.rb @@ -151,7 +151,7 @@ class RichTextRun < Test::Unit::TestCase def test_multiline_autowidth wrap = @p.workbook.styles.add_style({ alignment: { wrap_text: true } }) - awtr = Axlsx::RichTextRun.new('I\'m bold' + "\n", b: true) + awtr = Axlsx::RichTextRun.new("I'm bold\n", b: true) rt = Axlsx::RichText.new rt.runs << awtr @ws.add_row [rt], style: wrap |
