Fix new linter errors

This commit is contained in:
Alex Ling 2021-03-12 15:03:12 +00:00
parent daec2bdac6
commit ee52c52f46
16 changed files with 46 additions and 54 deletions

View File

@ -8,9 +8,7 @@ describe Storage do
end
it "deletes user" do
with_storage do |storage|
storage.delete_user "admin"
end
with_storage &.delete_user "admin"
end
it "creates new user" do

View File

@ -21,7 +21,7 @@ describe "compare_numerically" do
it "sorts like the stack exchange post" do
ary = ["2", "12", "200000", "1000000", "a", "a12", "b2", "text2",
"text2a", "text2a2", "text2a12", "text2ab", "text12", "text12a"]
ary.reverse.sort { |a, b|
ary.reverse.sort! { |a, b|
compare_numerically a, b
}.should eq ary
end
@ -29,7 +29,7 @@ describe "compare_numerically" do
# https://github.com/hkalexling/Mango/issues/22
it "handles numbers larger than Int32" do
ary = ["14410155591588.jpg", "21410155591588.png", "104410155591588.jpg"]
ary.reverse.sort { |a, b|
ary.reverse.sort! { |a, b|
compare_numerically a, b
}.should eq ary
end
@ -56,7 +56,7 @@ describe "chapter_sort" do
it "sorts correctly" do
ary = ["Vol.1 Ch.01", "Vol.1 Ch.02", "Vol.2 Ch. 2.5", "Ch. 3", "Ch.04"]
sorter = ChapterSorter.new ary
ary.reverse.sort do |a, b|
ary.reverse.sort! do |a, b|
sorter.compare a, b
end.should eq ary
end

View File

@ -86,7 +86,7 @@ class Entry
SUPPORTED_IMG_TYPES.includes? \
MIME.from_filename? e.filename
}
.sort { |a, b|
.sort! { |a, b|
compare_numerically a.filename, b.filename
}
yield file, entries

View File

@ -63,7 +63,7 @@ class Library
end
def deep_titles
titles + titles.map { |t| t.deep_titles }.flatten
titles + titles.flat_map &.deep_titles
end
def to_json(json : JSON::Builder)
@ -98,7 +98,7 @@ class Library
.select { |path| File.directory? path }
.map { |path| Title.new path, "" }
.select { |title| !(title.entries.empty? && title.titles.empty?) }
.sort { |a, b| a.title <=> b.title }
.sort! { |a, b| a.title <=> b.title }
.tap { |_| @title_ids.clear }
.each do |title|
@title_hash[title.id] = title
@ -114,7 +114,7 @@ class Library
def get_continue_reading_entries(username)
cr_entries = deep_titles
.map { |t| t.get_last_read_entry username }
.map(&.get_last_read_entry username)
# Select elements with type `Entry` from the array and ignore all `Nil`s
.select(Entry)[0...ENTRIES_IN_HOME_SECTIONS]
.map { |e|
@ -150,9 +150,9 @@ class Library
recently_added = [] of RA
last_date_added = nil
titles.map { |t| t.deep_entries_with_date_added }.flatten
.select { |e| e[:date_added] > 1.month.ago }
.sort { |a, b| b[:date_added] <=> a[:date_added] }
titles.flat_map(&.deep_entries_with_date_added)
.select(&.[:date_added].> 1.month.ago)
.sort! { |a, b| b[:date_added] <=> a[:date_added] }
.each do |e|
break if recently_added.size > 12
last = recently_added.last?
@ -188,9 +188,9 @@ class Library
# If we use `deep_titles`, the start reading section might include `Vol. 2`
# when the user hasn't started `Vol. 1` yet
titles
.select { |t| t.load_percentage(username) == 0 }
.select(&.load_percentage(username).== 0)
.sample(ENTRIES_IN_HOME_SECTIONS)
.shuffle
.shuffle!
end
def thumbnail_generation_progress
@ -205,7 +205,7 @@ class Library
end
Logger.info "Starting thumbnail generation"
entries = deep_titles.map(&.deep_entries).flatten.reject &.err_msg
entries = deep_titles.flat_map(&.deep_entries).reject &.err_msg
@entries_count = entries.size
@thumbnails_count = 0

View File

@ -44,14 +44,14 @@ class Title
mtimes = [@mtime]
mtimes += @title_ids.map { |e| Library.default.title_hash[e].mtime }
mtimes += @entries.map { |e| e.mtime }
mtimes += @entries.map &.mtime
@mtime = mtimes.max
@title_ids.sort! do |a, b|
compare_numerically Library.default.title_hash[a].title,
Library.default.title_hash[b].title
end
sorter = ChapterSorter.new @entries.map { |e| e.title }
sorter = ChapterSorter.new @entries.map &.title
@entries.sort! do |a, b|
sorter.compare a.title, b.title
end
@ -92,12 +92,12 @@ class Title
# Get all entries, including entries in nested titles
def deep_entries
return @entries if title_ids.empty?
@entries + titles.map { |t| t.deep_entries }.flatten
@entries + titles.flat_map &.deep_entries
end
def deep_titles
return [] of Title if titles.empty?
titles + titles.map { |t| t.deep_titles }.flatten
titles + titles.flat_map &.deep_titles
end
def parents
@ -138,7 +138,7 @@ class Title
end
def get_entry(eid)
@entries.find { |e| e.id == eid }
@entries.find &.id.== eid
end
def display_name
@ -217,29 +217,23 @@ class Title
@entries.each do |e|
e.save_progress username, e.pages
end
titles.each do |t|
t.read_all username
end
titles.each &.read_all username
end
# Set the reading progress of all entries and nested libraries to 0%
def unread_all(username)
@entries.each do |e|
e.save_progress username, 0
end
titles.each do |t|
t.unread_all username
end
@entries.each &.save_progress(username, 0)
titles.each &.unread_all username
end
def deep_read_page_count(username) : Int32
load_progress_for_all_entries(username).sum +
titles.map { |t| t.deep_read_page_count username }.flatten.sum
titles.flat_map(&.deep_read_page_count username).sum
end
def deep_total_page_count : Int32
entries.map { |e| e.pages }.sum +
titles.map { |t| t.deep_total_page_count }.flatten.sum
entries.sum(&.pages) +
titles.flat_map(&.deep_total_page_count).sum
end
def load_percentage(username)
@ -311,13 +305,13 @@ class Title
ary = @entries.zip(percentage_ary)
.sort { |a_tp, b_tp| (a_tp[1] <=> b_tp[1]).or \
compare_numerically a_tp[0].title, b_tp[0].title }
.map { |tp| tp[0] }
.map &.[0]
else
unless opt.method.auto?
Logger.warn "Unknown sorting method #{opt.not_nil!.method}. Using " \
"Auto instead"
end
sorter = ChapterSorter.new @entries.map { |e| e.title }
sorter = ChapterSorter.new @entries.map &.title
ary = @entries.sort do |a, b|
sorter.compare(a.title, b.title).or \
compare_numerically a.title, b.title
@ -383,13 +377,13 @@ class Title
{entry: e, date_added: da_ary[i]}
end
return zip if title_ids.empty?
zip + titles.map { |t| t.deep_entries_with_date_added }.flatten
zip + titles.flat_map &.deep_entries_with_date_added
end
def bulk_progress(action, ids : Array(String), username)
selected_entries = ids
.map { |id|
@entries.find { |e| e.id == id }
@entries.find &.id.==(id)
}
.select(Entry)

View File

@ -35,7 +35,7 @@ module MangaDex
struct Chapter
def rename(rule : Rename::Rule)
hash = properties_to_hash %w(id title volume chapter lang_code language)
hash["groups"] = groups.map(&.name).join ","
hash["groups"] = groups.join(",", &.name)
rule.render hash
end

View File

@ -117,7 +117,7 @@ class Plugin
def initialize(id : String)
Plugin.build_info_ary
@info = @@info_ary.find { |i| i.id == id }
@info = @@info_ary.find &.id.== id
if @info.nil?
raise Error.new "Plugin with ID #{id} not found"
end

View File

@ -303,12 +303,12 @@ class Queue
end
def pause
@downloaders.each { |d| d.stopped = true }
@downloaders.each &.stopped=(true)
@paused = true
end
def resume
@downloaders.each { |d| d.stopped = false }
@downloaders.each &.stopped=(false)
@paused = false
end

View File

@ -35,15 +35,15 @@ module Rename
class Group < Base(Pattern | String)
def render(hash : VHash)
return "" if @ary.select(&.is_a? Pattern)
return "" if @ary.select(Pattern)
.any? &.as(Pattern).render(hash).empty?
@ary.map do |e|
@ary.join do |e|
if e.is_a? Pattern
e.render hash
else
e
end
end.join
end
end
end
@ -129,13 +129,13 @@ module Rename
end
def render(hash : VHash)
str = @ary.map do |e|
str = @ary.join do |e|
if e.is_a? String
e
else
e.render hash
end
end.join.strip
end.strip
post_process str
end

View File

@ -339,7 +339,7 @@ struct APIRouter
}
post "/api/admin/mangadex/download" do |env|
begin
chapters = env.params.json["chapters"].as(Array).map { |c| c.as_h }
chapters = env.params.json["chapters"].as(Array).map &.as_h
jobs = chapters.map { |chapter|
Queue::Job.new(
chapter["id"].as_i64.to_s,

View File

@ -103,7 +103,7 @@ struct MainRouter
recently_added = Library.default.get_recently_added_entries username
start_reading = Library.default.get_start_reading_titles username
titles = Library.default.titles
new_user = !titles.any? { |t| t.load_percentage(username) > 0 }
new_user = !titles.any? &.load_percentage(username).> 0
empty_library = titles.size == 0
layout "home"
rescue e

View File

@ -445,7 +445,7 @@ class Storage
Logger.debug "Marking #{trash_ids.size} entries as unavailable"
end
db.exec "update ids set unavailable = 1 where id in " \
"(#{trash_ids.map { |i| "'#{i}'" }.join ","})"
"(#{trash_ids.join "," { |i| "'#{i}'" }})"
# Detect dangling title IDs
trash_titles = [] of String
@ -461,7 +461,7 @@ class Storage
Logger.debug "Marking #{trash_titles.size} titles as unavailable"
end
db.exec "update titles set unavailable = 1 where id in " \
"(#{trash_titles.map { |i| "'#{i}'" }.join ","})"
"(#{trash_titles.join "," { |i| "'#{i}'" }})"
end
end
end

View File

@ -73,7 +73,7 @@ class ChapterSorter
.select do |key|
keys[key].count >= str_ary.size / 2
end
.sort do |a_key, b_key|
.sort! do |a_key, b_key|
a = keys[a_key]
b = keys[b_key]
# Sort keys by the number of times they appear

View File

@ -11,7 +11,7 @@ end
def split_by_alphanumeric(str)
arr = [] of String
str.scan(/([^\d\n\r]*)(\d*)([^\d\n\r]*)/) do |match|
arr += match.captures.select { |s| s != "" }
arr += match.captures.select &.!= ""
end
arr
end

View File

@ -114,7 +114,7 @@ class String
def components_similarity(other : String) : Float64
s, l = [self, other]
.map { |str| Path.new(str).parts }
.sort_by &.size
.sort_by! &.size
match = s.reverse.zip(l.reverse).count { |a, b| a == b }
match / s.size

View File

@ -72,7 +72,7 @@ def redirect(env, path)
end
def hash_to_query(hash)
hash.map { |k, v| "#{k}=#{v}" }.join("&")
hash.join "&" { |k, v| "#{k}=#{v}" }
end
def request_path_startswith(env, ary)