rubocop: fix various Rubocop warnings.

This commit is contained in:
evazion
2021-06-16 18:24:42 -05:00
parent cfe471e0b5
commit 07e23204b6
99 changed files with 412 additions and 374 deletions

View File

@@ -1,7 +1,6 @@
class ApplicationComponent < ViewComponent::Base
delegate :link_to_user, :time_ago_in_words_tagged, :format_text, :external_link_to, :tag_class, to: :helpers
delegate :edit_icon, :delete_icon, :undelete_icon, :flag_icon, :upvote_icon,
:downvote_icon, :link_icon, :sticky_icon, :unsticky_icon, to: :helpers
delegate :edit_icon, :delete_icon, :undelete_icon, :flag_icon, :upvote_icon, :downvote_icon, :link_icon, :sticky_icon, :unsticky_icon, to: :helpers
def policy(subject)
Pundit.policy!(current_user, subject)

View File

@@ -4,6 +4,7 @@ class CommentComponent < ApplicationComponent
attr_reader :comment, :context, :dtext_data, :current_user
def initialize(comment:, current_user:, context: nil, dtext_data: nil)
super
@comment = comment
@context = context
@dtext_data = dtext_data
@@ -11,7 +12,7 @@ class CommentComponent < ApplicationComponent
end
def dimmed?
comment.is_deleted? || (!comment.is_sticky? && comment.score <= current_user.comment_threshold/2.0)
comment.is_deleted? || (!comment.is_sticky? && comment.score <= current_user.comment_threshold / 2.0)
end
def thresholded?

View File

@@ -4,6 +4,7 @@ class CommentSectionComponent < ApplicationComponent
attr_reader :post, :comments, :current_user, :limit, :dtext_data
def initialize(post:, current_user:, limit: nil)
super
@post = post
@current_user = current_user
@limit = limit

View File

@@ -2,6 +2,7 @@
class ForumPostComponent < ApplicationComponent
attr_reader :forum_post, :original_forum_post_id, :dtext_data, :moderation_reports, :current_user
delegate :link_to_user, :time_ago_in_words_tagged, :format_text, :policy, to: :helpers
with_collection_parameter :forum_post
@@ -17,6 +18,7 @@ class ForumPostComponent < ApplicationComponent
end
def initialize(forum_post:, original_forum_post_id: nil, dtext_data: nil, current_user: User.anonymous)
super
@forum_post = forum_post
@original_forum_post_id = original_forum_post_id
@dtext_data = dtext_data

View File

@@ -23,6 +23,7 @@
<% if policy(forum_post).create? %>
<li><%= link_to "Reply", new_forum_post_path(post_id: forum_post.id), method: :get, remote: true %></li>
<% end %>
<% if policy(forum_post).destroy? && !forum_post.is_original_post?(original_forum_post_id) %>
<% if forum_post.is_deleted %>
<li><%= link_to "Undelete", undelete_forum_post_path(forum_post.id), method: :post, remote: true %></li>
@@ -30,6 +31,7 @@
<li><%= link_to "Delete", forum_post_path(forum_post.id), "data-confirm": "Are you sure you want to delete this forum post?", method: :delete, remote: true %></li>
<% end %>
<% end %>
<% if policy(forum_post).update? %>
<% if forum_post.is_original_post?(original_forum_post_id) %>
<li><%= link_to "Edit", edit_forum_topic_path(forum_post.topic), id: "edit_forum_topic_link_#{forum_post.topic.id}", class: "edit_forum_topic_link" %></li>
@@ -37,12 +39,15 @@
<li><%= link_to "Edit", edit_forum_post_path(forum_post.id), id: "edit_forum_post_link_#{forum_post.id}", class: "edit_forum_post_link" %></li>
<% end %>
<% end %>
<% if policy(forum_post).reportable? %>
<li><%= link_to "Report", new_moderation_report_path(moderation_report: { model_type: "ForumPost", model_id: forum_post.id }), remote: true, title: "Report this forum post to the moderators" %></li>
<% end %>
<% if has_moderation_reports? %>
<li class="moderation-report-notice">Reported (<%= link_to pluralize(forum_post.moderation_reports.length, "report"), moderation_reports_path(search: { model_type: "ForumPost", model_id: forum_post.id }) %>)</li>
<% end %>
<% if forum_post.bulk_update_request.present? %>
<menu class="votes" id="forum-post-votes-for-<%= forum_post.id %>">
<%= render "forum_post_votes/list", votes: forum_post.votes, forum_post: forum_post %>

View File

@@ -2,10 +2,12 @@
class PaginatorComponent < ApplicationComponent
attr_reader :records, :window, :params
delegate :current_page, :prev_page, :next_page, :total_pages, :paginator_mode, :paginator_page_limit, to: :records
delegate :ellipsis_icon, :chevron_left_icon, :chevron_right_icon, to: :helpers
def initialize(records:, params:, window: 4)
super
@records = records
@window = window
@params = params
@@ -25,7 +27,7 @@ class PaginatorComponent < ApplicationComponent
("..." unless left == 2),
(left..right).to_a,
("..." unless right == last_page - 1),
(last_page unless last_page == 1)
(last_page unless last_page == 1),
].flatten.compact
end

View File

@@ -4,6 +4,7 @@ class PostNavbarComponent < ApplicationComponent
attr_reader :post, :current_user, :search
def initialize(post:, current_user:, search: nil)
super
@post = post
@current_user = current_user
@search = search.presence || "status:any"

View File

@@ -4,9 +4,11 @@ class PostPreviewComponent < ApplicationComponent
with_collection_parameter :post
attr_reader :post, :tags, :show_deleted, :show_cropped, :link_target, :pool, :similarity, :recommended, :compact, :size, :current_user, :options
delegate :external_link_to, :time_ago_in_words_tagged, :empty_heart_icon, to: :helpers
def initialize(post:, tags: "", show_deleted: false, show_cropped: true, link_target: post, pool: nil, similarity: nil, recommended: nil, compact: nil, size: nil, current_user: CurrentUser.user, **options)
super
@post = post
@tags = tags.presence
@show_deleted = show_deleted
@@ -44,7 +46,7 @@ class PostPreviewComponent < ApplicationComponent
{
width: [(downscale_ratio * post.image_width).floor, post.image_width].min,
height: [(downscale_ratio * post.image_height).floor, post.image_height].min
height: [(downscale_ratio * post.image_height).floor, post.image_height].min,
}
else
{ width: 0, height: 0 }
@@ -70,7 +72,7 @@ class PostPreviewComponent < ApplicationComponent
def data_attributes
attributes = {
"data-id" => post.id,
"data-has-sound" => post.has_tag?('video_with_sound|flash_with_sound'),
"data-has-sound" => post.has_tag?("video_with_sound|flash_with_sound"),
"data-tags" => post.tag_string,
"data-pools" => post.pool_string,
"data-approver-id" => post.approver_id,

View File

@@ -5,6 +5,7 @@ class PostVotesComponent < ApplicationComponent
attr_reader :post, :current_user
def initialize(post:, current_user:)
super
@post = post
@current_user = current_user
end

View File

@@ -2,9 +2,11 @@
class SourceDataComponent < ApplicationComponent
attr_reader :source
delegate :spinner_icon, :external_site_icon, to: :helpers
def initialize(source:)
super
@source = source
end

View File

@@ -2,16 +2,18 @@
class TagListComponent < ApplicationComponent
attr_reader :tags, :current_query, :show_extra_links
delegate :humanized_number, to: :helpers
def initialize(tags: [], current_query: nil, show_extra_links: false)
super
@tags = tags
@current_query = current_query
@show_extra_links = show_extra_links
end
def self.tags_from_names(tag_names)
names_to_tags = Tag.where(name: tag_names).map { |tag| [tag.name, tag] }.to_h
names_to_tags = Tag.where(name: tag_names).index_by(&:name)
tag_names.map do |name|
names_to_tags.fetch(name) { Tag.new(name: name).freeze }