Fix various rubocop issues.

This commit is contained in:
evazion
2020-01-11 19:01:40 -06:00
parent bab656a873
commit aff3d3b18f
15 changed files with 24 additions and 32 deletions

View File

@@ -121,7 +121,7 @@ module ApplicationHelper
link_to text, wiki_page_path(title), class: "wiki-link", **options
end
def link_to_wikis(*wiki_titles, last_word_connector: ", or", **options)
def link_to_wikis(*wiki_titles, **options)
links = wiki_titles.map do |title|
link_to_wiki title.tr("_", " "), title
end
@@ -245,7 +245,7 @@ module ApplicationHelper
def data_attributes_for(record, prefix, attributes)
attributes.map do |attr|
if attr.kind_of?(Array)
if attr.is_a?(Array)
name = attr.map {|sym| sym.to_s.dasherize.delete("?")}.join('-')
value = record
attr.each do |sym|
@@ -261,7 +261,7 @@ module ApplicationHelper
if value.nil?
value = "null"
end
if prefix.length == 0
if prefix.blank?
[:"#{name}", value]
else
[:"#{prefix}-#{name}", value]

View File

@@ -2,5 +2,4 @@ module ArtistCommentaryVersionsHelper
def artist_commentary_versions_listing_type
params.dig(:search, :post_id).present? ? :revert : :standard
end
end

View File

@@ -1,6 +1,6 @@
module NoteVersionsHelper
def note_versions_listing_type
(params.dig(:search, :post_id).present? || params.dig(:search, :note_id).present?) && CurrentUser.is_member? ? :revert : :standard
((params.dig(:search, :post_id).present? || params.dig(:search, :note_id).present?) && CurrentUser.is_member?) ? :revert : :standard
end
def note_version_body_diff_info(note_version)

View File

@@ -23,4 +23,4 @@ module PoolVersionsHelper
pattern = Regexp.new('(?:<.+?>)|(?:\w+)|(?:[ \t]+)|(?:\r?\n)|(?:.+?)')
DiffBuilder.new(other_version.description, pool_version.description, pattern).build
end
end
end

View File

@@ -1,6 +1,6 @@
module Danbooru
class Http
attr_accessor :cache, :http
attr_writer :cache, :http
class << self
delegate :get, :post, :delete, :cache, :auth, :basic_auth, :headers, to: :new

View File

@@ -40,9 +40,7 @@ class PostQueryBuilder
end
def escape_string_for_tsquery(array)
array.map do |token|
token.to_escaped_for_tsquery
end
array.map(&:to_escaped_for_tsquery)
end
def add_tag_string_search_relation(tags, relation)
@@ -314,7 +312,7 @@ class PostQueryBuilder
elsif flagger_id == "none"
relation = relation.where('NOT EXISTS (' + PostFlag.unscoped.search(:category => "normal").where('post_id = posts.id').reorder('').select('1').to_sql + ')')
elsif CurrentUser.can_view_flagger?(flagger_id)
post_ids = PostFlag.unscoped.search(:creator_id => flagger_id, :category => "normal").reorder("").select {|flag| flag.not_uploaded_by?(CurrentUser.id)}.map {|flag| flag.post_id}.uniq
post_ids = PostFlag.unscoped.search(creator_id: flagger_id, category: "normal").reorder("").select {|flag| flag.not_uploaded_by?(CurrentUser.id)}.map(&:post_id).uniq
relation = relation.where("posts.id": post_ids)
end
end

View File

@@ -78,11 +78,11 @@ module PostSets
end
def hidden_posts
posts.reject { |p| p.visible? }
posts.reject(&:visible?)
end
def banned_posts
posts.select { |p| p.banblocked? }
posts.select(&:banblocked?)
end
def censored_posts

View File

@@ -11,8 +11,8 @@ class PostVoteSimilarity
@score = score
end
def <=>(rhs)
score <=> rhs.score
def <=>(other)
score <=> other.score
end
end

View File

@@ -240,11 +240,6 @@ module Sources
self.class.to_dtext(artist_commentary_desc)
end
# A strategy may return extra data unrelated to the file
def data
return {}
end
# A search query that should return any posts that were previously
# uploaded from the same source. These may be duplicates, or they may be
# other posts from the same gallery.

View File

@@ -139,7 +139,7 @@ module Sources::Strategies
def normalize_tag(tag)
COMMON_TAG_REGEXES.each do |rg|
norm_tag = tag.gsub(rg,"")
norm_tag = tag.gsub(rg, "")
if norm_tag != tag
return norm_tag
end

View File

@@ -9,7 +9,7 @@ class TableBuilder
@block = block
@name = name || attribute
@name = @name.to_s.titleize unless @name.kind_of?(String)
@name = @name.to_s.titleize unless @name.is_a?(String)
if @name.present?
column_class = "#{@name.parameterize.dasherize}-column"
@@ -22,7 +22,7 @@ class TableBuilder
if block.present?
block.call(item, i, j, self)
nil
elsif attribute.kind_of?(Symbol)
elsif attribute.is_a?(Symbol)
item.send(attribute)
else
""

View File

@@ -1,5 +1,6 @@
module TagRelationshipRetirementService
module_function
THRESHOLD = 2.years
def forum_topic_title

View File

@@ -1,6 +1,7 @@
class UploadService
module Utils
module_function
class CorruptFileError < RuntimeError; end
def file_header_to_file_ext(file)

View File

@@ -371,7 +371,7 @@ class Artist < ApplicationRecord
elsif wiki_page.nil?
# if there are any notes, we need to create a new wiki page
if @notes.present?
wp = create_wiki_page(body: @notes, title: name)
create_wiki_page(body: @notes, title: name)
end
elsif (!@notes.nil? && (wiki_page.body != @notes)) || wiki_page.title != name
# if anything changed, we need to update the wiki page
@@ -402,10 +402,10 @@ class Artist < ApplicationRecord
def unban!
Post.transaction do
CurrentUser.without_safe_mode do
ti = TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").first
ti = TagImplication.find_by(antecedent_name: name, consequent_name: "banned_artist")
ti&.destroy
Post.tag_match(name).where("true /* Artist.unban */").each do |post|
Post.tag_match(name).find_each do |post|
post.unban!
fixed_tags = post.tag_string.sub(/(?:\A| )banned_artist(?:\Z| )/, " ").strip
post.update(tag_string: fixed_tags)
@@ -420,9 +420,7 @@ class Artist < ApplicationRecord
def ban!
Post.transaction do
CurrentUser.without_safe_mode do
Post.tag_match(name).where("true /* Artist.ban */").each do |post|
post.ban!
end
Post.tag_match(name).each(&:ban!)
# potential race condition but unlikely
unless TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").exists?

View File

@@ -636,7 +636,7 @@ class Post < ApplicationRecord
def normalize_tags
normalized_tags = Tag.scan_tags(tag_string)
normalized_tags = apply_casesensitive_metatags(normalized_tags)
normalized_tags = normalized_tags.map {|tag| tag.downcase}
normalized_tags = normalized_tags.map(&:downcase)
normalized_tags = filter_metatags(normalized_tags)
normalized_tags = remove_negated_tags(normalized_tags)
normalized_tags = TagAlias.to_aliased(normalized_tags)
@@ -1256,7 +1256,7 @@ class Post < ApplicationRecord
def children_ids
if has_children?
children.map {|p| p.id}.join(' ')
children.map(&:id).join(' ')
end
end
end
@@ -1335,7 +1335,7 @@ class Post < ApplicationRecord
self.is_deleted = false
self.approver_id = CurrentUser.id
flags.each {|x| x.resolve!}
flags.each(&:resolve!)
save
ModAction.log("undeleted post ##{id}", :post_undelete)
end