Skip to content

Commit 12b818a

Browse files
committed
Fix more 'Lint/ShadowingOuterLocalVar' warnings reported by ameba
1 parent 1c91110 commit 12b818a

File tree

10 files changed

+22
-18
lines changed

10 files changed

+22
-18
lines changed

src/invidious/channels/about.cr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get_about_info(ucid, locale) : AboutChannel
9696
total_views = channel_about_meta["viewCountText"]?.try &.["simpleText"]?.try &.as_s.gsub(/\D/, "").to_i64? || 0_i64
9797

9898
# The joined text is split to several sub strings. The reduce joins those strings before parsing the date.
99-
joined = channel_about_meta["joinedDateText"]?.try &.["runs"]?.try &.as_a.reduce("") { |acc, node| acc + node["text"].as_s }
99+
joined = channel_about_meta["joinedDateText"]?.try &.["runs"]?.try &.as_a.reduce("") { |acc, nd| acc + nd["text"].as_s }
100100
.try { |text| Time.parse(text, "Joined %b %-d, %Y", Time::Location.local) } || Time.unix(0)
101101

102102
# Normal Auto-generated channels
@@ -136,7 +136,8 @@ def fetch_related_channels(about_channel : AboutChannel) : Array(AboutRelatedCha
136136
channels = YoutubeAPI.browse(browse_id: about_channel.ucid, params: "EghjaGFubmVscw%3D%3D")
137137

138138
tabs = channels.dig?("contents", "twoColumnBrowseResultsRenderer", "tabs").try(&.as_a?) || [] of JSON::Any
139-
tab = tabs.find { |tab| tab.dig?("tabRenderer", "title").try(&.as_s?) == "Channels" }
139+
tab = tabs.find(&.dig?("tabRenderer", "title").try(&.as_s?).try(&.== "Channels"))
140+
140141
return [] of AboutRelatedChannel if tab.nil?
141142

142143
items = tab.dig?("tabRenderer", "content", "sectionListRenderer", "contents", 0, "itemSectionRenderer", "contents", 0, "gridRenderer", "items").try(&.as_a?) || [] of JSON::Any

src/invidious/helpers/i18n.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def translate(locale : String?, key : String, text : String | Nil = nil) : Strin
9494
translation = ""
9595
match_length = 0
9696

97-
raw_data.as_h.each do |key, value|
98-
if md = text.try &.match(/#{key}/)
97+
raw_data.as_h.each do |hash_key, value|
98+
if md = text.try &.match(/#{hash_key}/)
9999
if md[0].size >= match_length
100100
translation = value.as_s
101101
match_length = md[0].size

src/invidious/helpers/json_filter.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ module JSONFilter
9898
end
9999
end
100100

101-
group_name.split('/').each do |group_name|
101+
group_name.split('/').each do |name|
102102
nest_stack.push({
103-
group_name: group_name,
103+
group_name: name,
104104
closing_bracket_index: closing_bracket_index,
105105
})
106106
end

src/invidious/helpers/static_file_handler.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ module Kemal
175175

176176
if @cached_files.sum(&.[1][:data].bytesize) + (size = File.size(file_path)) < CACHE_LIMIT
177177
data = Bytes.new(size)
178-
File.open(file_path) do |file|
179-
file.read(data)
180-
end
178+
179+
File.open(file_path) { |f| f.read(data) }
180+
181181
filestat = File.info(file_path)
182182

183183
@cached_files[file_path] = {data: data, filestat: filestat}

src/invidious/helpers/tokens.cr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ end
4242
def sign_token(key, hash)
4343
string_to_sign = [] of String
4444

45+
# TODO: figure out which "key" variable is used
46+
# Ameba reports a warning for "Lint/ShadowingOuterLocalVar" on this
47+
# variable, but its preferrable to not touch that (works fine atm).
4548
hash.each do |key, value|
4649
next if key == "signature"
4750

src/invidious/helpers/utils.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ def parse_range(range)
292292
end
293293

294294
ranges = range.lchop("bytes=").split(',')
295-
ranges.each do |range|
296-
start_range, end_range = range.split('-')
295+
ranges.each do |r|
296+
start_range, end_range = r.split('-')
297297

298298
start_range = start_range.to_i64? || 0_i64
299299
end_range = end_range.to_i64?

src/invidious/playlists.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ struct InvidiousPlaylist
202202
end
203203

204204
videos = get_playlist_videos(self, offset: offset, video_id: video_id)
205-
videos.each_with_index do |video, index|
206-
video.to_json(json, offset + index)
205+
videos.each_with_index do |video, idx|
206+
video.to_json(json, offset + idx)
207207
end
208208
end
209209
end

src/invidious/routes/api/manifest.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ module Invidious::Routes::API::Manifest
9898
height = fmt["height"].as_i
9999

100100
# Resolutions reported by YouTube player (may not accurately reflect source)
101-
height = potential_heights.min_by { |i| (height - i).abs }
101+
height = potential_heights.min_by { |x| (height - x).abs }
102102
next if unique_res && heights.includes? height
103103
heights << height
104104

src/invidious/routes/login.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ module Invidious::Routes::Login
425425

426426
found_valid_captcha = false
427427
error_exception = Exception.new
428-
tokens.each do |token|
428+
tokens.each do |tok|
429429
begin
430-
validate_request(token, answer, env.request, HMAC_KEY, locale)
430+
validate_request(tok, answer, env.request, HMAC_KEY, locale)
431431
found_valid_captcha = true
432432
rescue ex
433433
error_exception = ex

src/invidious/videos.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,8 @@ struct Video
661661
url = URI.parse(storyboards.shift)
662662
params = HTTP::Params.parse(url.query || "")
663663

664-
storyboards.each_with_index do |storyboard, i|
665-
width, height, count, storyboard_width, storyboard_height, interval, _, sigh = storyboard.split("#")
664+
storyboards.each_with_index do |sb, i|
665+
width, height, count, storyboard_width, storyboard_height, interval, _, sigh = sb.split("#")
666666
params["sigh"] = sigh
667667
url.query = params.to_s
668668

0 commit comments

Comments
 (0)