From bc06f8cea26daca30a917ce87db0a17b37bd18e9 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Sun, 25 Feb 2024 16:41:35 +0100 Subject: [PATCH] [Misc] Fix all remaining (hopefully) issues with frozen string literals +"" is a bit of a copout, that could be done better but very easy to do in these more complicated cases --- app/helpers/comments_helper.rb | 7 +++---- app/helpers/note_versions_helper.rb | 24 ++++++++---------------- app/helpers/posts_helper.rb | 4 ++-- app/logical/apng_inspector.rb | 2 +- app/presenters/tag_set_presenter.rb | 4 ++-- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index d22ee06bc..f656acee9 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -4,7 +4,7 @@ module CommentsHelper voted = !vote.nil? vote_score = voted ? vote.score : 0 - comment_score = comment.score + score_tag = tag.li(comment.score, class: "comment-score #{score_class(comment.score)}", id: "comment-score-#{comment.id}") if CurrentUser.is_member? up_tag = tag.li( @@ -17,10 +17,9 @@ module CommentsHelper class: confirm_score_class(vote_score, -1, false), id: "comment-vote-down-#{comment.id}", ) + up_tag + score_tag + down_tag else - up_tag = down_tag = "".html_safe + score_tag end - score_tag = tag.li(comment.score, class: "comment-score #{score_class(comment_score)}", id: "comment-score-#{comment.id}") - up_tag + score_tag + down_tag end end diff --git a/app/helpers/note_versions_helper.rb b/app/helpers/note_versions_helper.rb index e007faba1..d8ef595e4 100644 --- a/app/helpers/note_versions_helper.rb +++ b/app/helpers/note_versions_helper.rb @@ -1,30 +1,22 @@ module NoteVersionsHelper def note_version_body_diff_info(note_version) previous = note_version.previous - if previous.nil? - return "" + if note_version.body == previous&.body + tag.span("(body not changed)", class: "inactive") + else + "" end - - html = "" - if note_version.body == previous.body - html += '(body not changed)' - end - - html.html_safe end def note_version_position_diff(note_version) previous = note_version.previous + html = "#{note_version.width}x#{note_version.height} #{note_version.x},#{note_version.y}" + return html if previous.nil? - html = "#{note_version.width}x#{note_version.height}" - html += " #{note_version.x},#{note_version.y}" - if previous.nil? - html - elsif note_version.x == previous.x && note_version.y == previous.y && note_version.width == previous.width && note_version.height == previous.height + if note_version.x == previous.x && note_version.y == previous.y && note_version.width == previous.width && note_version.height == previous.height html else - html = '' + html + '' - html.html_safe + tag.span(html, style: "text-decoration: underline;") end end end diff --git a/app/helpers/posts_helper.rb b/app/helpers/posts_helper.rb index 9fcafe6ac..1810c5df5 100644 --- a/app/helpers/posts_helper.rb +++ b/app/helpers/posts_helper.rb @@ -35,7 +35,7 @@ module PostsHelper end def has_parent_message(post, parent_post_set) - html = "" + html = +"" html << "Parent: " html << link_to("post ##{post.parent_id}", post_path(id: post.parent_id)) @@ -56,7 +56,7 @@ module PostsHelper end def has_children_message(post, children_post_set) - html = "" + html = +"" html << "Children: " text = children_post_set.children.count == 1 ? "1 child" : "#{children_post_set.children.count} children" diff --git a/app/logical/apng_inspector.rb b/app/logical/apng_inspector.rb index d61d7fa0e..30b97b87b 100644 --- a/app/logical/apng_inspector.rb +++ b/app/logical/apng_inspector.rb @@ -35,7 +35,7 @@ class ApngInspector #We could be dealing with large number of chunks, #so the code should be optimized to create as few objects as possible. #All literal strings are frozen and read() function uses string buffer. - chunkheader = '' + chunkheader = +"" while file.read(8, chunkheader) #ensure that first 8 bytes from chunk were read properly if chunkheader == nil || chunkheader.length < 8 diff --git a/app/presenters/tag_set_presenter.rb b/app/presenters/tag_set_presenter.rb index 94ff47e41..391df9653 100644 --- a/app/presenters/tag_set_presenter.rb +++ b/app/presenters/tag_set_presenter.rb @@ -16,7 +16,7 @@ class TagSetPresenter < Presenter end def post_index_sidebar_tag_list_html(current_query: "") - html = "" + html = +"" if ordered_tags.present? html << '