Fix various rubocop warnings.

This commit is contained in:
evazion
2021-09-27 00:44:41 -05:00
parent a2a4ab887d
commit 79fdfa86ae
39 changed files with 149 additions and 154 deletions

View File

@@ -29,9 +29,9 @@ module ApplicationHelper
return type == "previous" ? "New" : ""
end
changed_fields = record.class.status_fields.select do |field, status|
changed_fields = record.class.status_fields.select do |field, _status|
(record.has_attribute?(field) && record[field] != other[field]) ||
(!record.has_attribute?(field) && record.send(field, type))
(!record.has_attribute?(field) && record.send(field, type))
end
statuses = changed_fields.map { |field, status| status }
@@ -52,7 +52,7 @@ module ApplicationHelper
html = []
%w[previous subsequent current].each do |type|
if type == params[:type]
html << %(<span>#{type}</span>)
html << %{<span>#{type}</span>}
else
html << tag.li(link_to(type, params.except(:controller, :action).merge(type: type).permit!))
end
@@ -106,7 +106,7 @@ module ApplicationHelper
if number >= 10_000
"#{number / 1_000}k"
elsif number >= 1_000
"%.1fk" % (number / 1_000.0)
format("%.1fk", number / 1_000.0)
else
number.to_s
end
@@ -142,11 +142,11 @@ module ApplicationHelper
end
def external_link_to(url, text = url, truncate: nil, strip: false, **link_options)
text = text.gsub(%r!\Ahttps?://!i, "") if strip == :scheme
text = text.gsub(%r!\Ahttps?://(?:www\.)?!i, "") if strip == :subdomain
text = text.gsub(%r{\Ahttps?://}i, "") if strip == :scheme
text = text.gsub(%r{\Ahttps?://(?:www\.)?}i, "") if strip == :subdomain
text = text.truncate(truncate) if truncate
if url =~ %r!\Ahttps?://!i
if url =~ %r{\Ahttps?://}i
link_to text, url, rel: "external noreferrer nofollow", **link_options
else
url
@@ -369,37 +369,37 @@ module ApplicationHelper
def nav_link_match(controller, url)
url =~ case controller
when "sessions", "users", "admin/users"
/^\/(session|users)/
%r{^/(session|users)}
when "comments"
/^\/comments/
%r{^/comments}
when "notes", "note_versions"
/^\/notes/
%r{^/notes}
when "posts", "uploads", "post_versions", "explore/posts", "moderator/post/dashboards", "favorites"
/^\/post/
%r{^/post}
when "artists", "artist_versions"
/^\/artist/
%r{^/artist}
when "tags", "tag_aliases", "tag_implications"
/^\/tags/
%r{^/tags}
when "pools", "pool_versions"
/^\/pools/
%r{^/pools}
when "moderator/dashboards"
/^\/moderator/
%r{^/moderator}
when "wiki_pages", "wiki_page_versions"
/^\/wiki_pages/
%r{^/wiki_pages}
when "forum_topics", "forum_posts"
/^\/forum_topics/
%r{^/forum_topics}
else
/^\/static/
%r{^/static}
end
end
end

View File

@@ -43,7 +43,7 @@ module ArtistVersionsHelper
else
name_diff = diff_name_html(other.name, artist_version.name)
end
%(<br><br><b>Rename:</b><br>&ensp;#{name_diff}</p>).html_safe
%{<br><br><b>Rename:</b><br>&ensp;#{name_diff}</p>}.html_safe
else
""
end
@@ -58,7 +58,7 @@ module ArtistVersionsHelper
else
group_name_diff = diff_name_html(other_group_name, artist_version.group_name)
end
%(<b>Group:</b><br>&ensp;#{group_name_diff}<br><br>).html_safe
%{<b>Group:</b><br>&ensp;#{group_name_diff}<br><br>}.html_safe
else
""
end

View File

@@ -8,7 +8,7 @@ module ForumTopicsHelper
end
def new_forum_topic?(topic, read_forum_topics)
!read_forum_topics.map(&:id).include?(topic.id)
read_forum_topics.map(&:id).exclude?(topic.id)
end
def forum_topic_status(topic)
@@ -24,9 +24,10 @@ module ForumTopicsHelper
end
def forum_post_vote_icon(vote)
if vote.score == 1
case vote.score
when 1
upvote_icon
elsif vote.score == -1
when -1
downvote_icon
else
meh_icon

View File

@@ -25,12 +25,12 @@ module PostVersionsHelper
html = '<span class="diff-list">'
added_tags.each do |tag|
obsolete_class = (obsolete_added_tags.include?(tag) ? "diff-obsolete" : "");
html << %(<ins class="#{obsolete_class}">#{link_to(wordbreakify(tag), posts_path(:tags => tag))}</ins> )
obsolete_class = (obsolete_added_tags.include?(tag) ? "diff-obsolete" : "")
html << %{<ins class="#{obsolete_class}">#{link_to(wordbreakify(tag), posts_path(:tags => tag))}</ins> }
end
removed_tags.each do |tag|
obsolete_class = (obsolete_removed_tags.include?(tag) ? "diff-obsolete" : "");
html << %(<del class="#{obsolete_class}">#{link_to(wordbreakify(tag), posts_path(:tags => tag))}</del> )
obsolete_class = (obsolete_removed_tags.include?(tag) ? "diff-obsolete" : "")
html << %{<del class="#{obsolete_class}">#{link_to(wordbreakify(tag), posts_path(:tags => tag))}</del> }
end
html << "</span>"
@@ -42,7 +42,7 @@ module PostVersionsHelper
prefix = (field == :parent_id ? "parent" : field.to_s)
search = "#{prefix}:#{value}"
display = (field == :rating ? post_version.pretty_rating : value)
%(<b>#{field.to_s.titleize}:</b> #{link_to(display, posts_path(:tags => search))}).html_safe
%{<b>#{field.to_s.titleize}:</b> #{link_to(display, posts_path(:tags => search))}}.html_safe
end
def post_version_value(value)

View File

@@ -35,7 +35,7 @@ module PostsHelper
def post_source_tag(source, normalized_source = source)
# Only allow http:// and https:// links. Disallow javascript: links.
if source =~ %r!\Ahttps?://!i
if source =~ %r{\Ahttps?://}i
external_link_to(normalized_source, strip: :subdomain) + "&nbsp;".html_safe + link_to("»", source, rel: "external noreferrer nofollow")
else
source

View File

@@ -17,11 +17,11 @@ module SeoHelper
json_ld_tag({
"@context": "https://schema.org",
"@type": "VideoObject",
"name": page_title,
"description": meta_description,
"uploadDate": post.created_at.iso8601,
"thumbnailUrl": post.preview_file_url,
"contentUrl": post.file_url,
name: page_title,
description: meta_description,
uploadDate: post.created_at.iso8601,
thumbnailUrl: post.preview_file_url,
contentUrl: post.file_url,
})
end
@@ -30,7 +30,7 @@ module SeoHelper
Danbooru.config.twitter_url,
Danbooru.config.discord_server_url,
Danbooru.config.source_code_url,
"https://en.wikipedia.org/wiki/Danbooru"
"https://en.wikipedia.org/wiki/Danbooru",
].compact
json_ld_tag({
@@ -41,18 +41,18 @@ module SeoHelper
url: root_url(host: Danbooru.config.hostname),
name: Danbooru.config.app_name,
logo: "#{root_url(host: Danbooru.config.hostname)}images/danbooru-logo-500x500.png",
sameAs: urls
sameAs: urls,
},
{
"@type": "WebSite",
"@id": root_url(anchor: "website", host: Danbooru.config.hostname),
"url": root_url(host: Danbooru.config.hostname),
"name": Danbooru.config.app_name,
"description": site_description,
"potentialAction": [{
url: root_url(host: Danbooru.config.hostname),
name: Danbooru.config.app_name,
description: site_description,
potentialAction: [{
"@type": "SearchAction",
"target": "#{posts_url(host: Danbooru.config.hostname)}?tags={search_term_string}",
"query-input": "required name=search_term_string"
target: "#{posts_url(host: Danbooru.config.hostname)}?tags={search_term_string}",
"query-input": "required name=search_term_string",
}]
}
]

View File

@@ -23,7 +23,7 @@ module WikiPageVersionsHelper
else
name_diff = diff_name_html(other.title, wiki_page_version.title)
end
%((<b>Rename:</b>&ensp;#{name_diff})).html_safe
%{(<b>Rename:</b>&ensp;#{name_diff})}.html_safe
else
""
end