DEV: Enable unless cops

We discussed the use of `unless` internally and decided to enforce
available rules from rubocop to restrict its most problematic uses.
This commit is contained in:
Loïc Guitaut
2023-02-16 10:40:11 +01:00
committed by Loïc Guitaut
parent 87de3c2319
commit f7c57fbc19
56 changed files with 137 additions and 142 deletions

View File

@ -145,12 +145,12 @@ module Onebox
!!AllowlistedGenericOnebox.allowed_twitter_labels.find { |l|
d[:label2] =~ /#{l}/i
}
unless Onebox::Helpers.blank?(d[:label_1])
d[:label_2] = Onebox::Helpers.truncate(d[:label2])
d[:data_2] = Onebox::Helpers.truncate(d[:data2])
else
if Onebox::Helpers.blank?(d[:label_1])
d[:label_1] = Onebox::Helpers.truncate(d[:label2])
d[:data_1] = Onebox::Helpers.truncate(d[:data2])
else
d[:label_2] = Onebox::Helpers.truncate(d[:label2])
d[:data_2] = Onebox::Helpers.truncate(d[:data2])
end
end

View File

@ -23,7 +23,9 @@ module Onebox
m_url_hash_name = m_url_hash[1]
end
unless m_url_hash.nil?
if m_url_hash.nil? # no hash found in url
paras = raw.search("p") # default get all the paras
else
section_header_title = raw.xpath("//span[@id='#{CGI.unescape(m_url_hash_name)}']")
if section_header_title.empty?
@ -49,8 +51,6 @@ module Onebox
end
end
end
else # no hash found in url
paras = raw.search("p") # default get all the paras
end
unless paras.empty?

View File

@ -40,8 +40,8 @@ module Onebox
should_ignore_canonical =
IGNORE_CANONICAL_DOMAINS.map { |hostname| uri.hostname.match?(hostname) }.any?
unless (ignore_canonical_tag && ignore_canonical_tag["content"].to_s == "true") ||
should_ignore_canonical
if !(ignore_canonical_tag && ignore_canonical_tag["content"].to_s == "true") &&
!should_ignore_canonical
# prefer canonical link
canonical_link = doc.at('//link[@rel="canonical"]/@href')
canonical_uri = Addressable::URI.parse(canonical_link)

View File

@ -120,15 +120,15 @@ module Onebox
a_lines.each do |l|
l = l.chomp("\n") # remove new line
m = l.match(/\A[ ]*/) # find leading spaces 0 or more
unless m.nil? || l.size == m[0].size || l.size == 0 # no match | only spaces in line | empty line
if m.nil? || l.size == m[0].size || l.size == 0
next # SKIP no match or line is only spaces
else # no match | only spaces in line | empty line
m_str_length = m[0].size
if m_str_length <= 1 # minimum space is 1 or nothing we can break we found our minimum
min_space = m_str_length
break #stop iteration
end
min_space = m_str_length if m_str_length < min_space
else
next # SKIP no match or line is only spaces
end
end
a_lines.each do |l|