Fix Style/SlicingWithRange cop (#25923)

This commit is contained in:
Matt Jankowski 2023-07-12 04:03:06 -04:00 committed by GitHub
parent 658742b3cd
commit b8b2470cf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 13 additions and 28 deletions

View file

@ -908,21 +908,6 @@ Style/SingleArgumentDig:
Exclude:
- 'lib/webpacker/manifest_extensions.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- 'app/lib/emoji_formatter.rb'
- 'app/lib/text_formatter.rb'
- 'app/models/account_alias.rb'
- 'app/models/domain_block.rb'
- 'app/models/email_domain_block.rb'
- 'app/models/preview_card_provider.rb'
- 'app/validators/status_length_validator.rb'
- 'db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb'
- 'lib/active_record/batches.rb'
- 'lib/mastodon/premailer_webpack_strategy.rb'
- 'lib/tasks/repo.rake'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: require_parentheses, require_no_parentheses

View file

@ -53,7 +53,7 @@ class EmojiFormatter
end
end
result << Nokogiri::XML::Text.new(text[last_index..-1], tree.document)
result << Nokogiri::XML::Text.new(text[last_index..], tree.document)
node.replace(result)
end

View file

@ -57,8 +57,8 @@ class TextFormatter
prefix = url.match(URL_PREFIX_REGEX).to_s
display_url = url[prefix.length, 30]
suffix = url[prefix.length + 30..-1]
cutoff = url[prefix.length..-1].length > 30
suffix = url[prefix.length + 30..]
cutoff = url[prefix.length..].length > 30
<<~HTML.squish.html_safe # rubocop:disable Rails/OutputSafety
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}" translate="no"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>
@ -84,7 +84,7 @@ class TextFormatter
indices.last
end
result << h(text[last_index..-1])
result << h(text[last_index..])
result
end

View file

@ -25,7 +25,7 @@ class AccountAlias < ApplicationRecord
def acct=(val)
val = val.to_s.strip
super(val.start_with?('@') ? val[1..-1] : val)
super(val.start_with?('@') ? val[1..] : val)
end
def pretty_acct

View file

@ -69,7 +69,7 @@ class DomainBlock < ApplicationRecord
uri = Addressable::URI.new.tap { |u| u.host = domain.strip.delete('/') }
segments = uri.normalized_host.split('.')
variants = segments.map.with_index { |_, i| segments[i..-1].join('.') }
variants = segments.map.with_index { |_, i| segments[i..].join('.') }
where(domain: variants).order(Arel.sql('char_length(domain) desc')).first
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError

View file

@ -64,7 +64,7 @@ class EmailDomainBlock < ApplicationRecord
segments = uri.normalized_host.split('.')
segments.map.with_index { |_, i| segments[i..-1].join('.') }
segments.map.with_index { |_, i| segments[i..].join('.') }
end
end

View file

@ -54,6 +54,6 @@ class PreviewCardProvider < ApplicationRecord
def self.matching_domain(domain)
segments = domain.split('.')
where(domain: segments.map.with_index { |_, i| segments[i..-1].join('.') }).order(Arel.sql('char_length(domain) desc')).first
where(domain: segments.map.with_index { |_, i| segments[i..].join('.') }).order(Arel.sql('char_length(domain) desc')).first
end
end

View file

@ -53,7 +53,7 @@ class StatusLengthValidator < ActiveModel::Validator
entity[:indices].last
end
result << str[last_index..-1]
result << str[last_index..]
result
end
end

View file

@ -6,7 +6,7 @@ class AddCaseInsensitiveIndexToTags < ActiveRecord::Migration[5.2]
def up
Tag.connection.select_all('SELECT string_agg(id::text, \',\') AS ids FROM tags GROUP BY lower(name) HAVING count(*) > 1').to_ary.each do |row|
canonical_tag_id = row['ids'].split(',').first
redundant_tag_ids = row['ids'].split(',')[1..-1]
redundant_tag_ids = row['ids'].split(',')[1..]
safety_assured do
execute "UPDATE accounts_tags AS t0 SET tag_id = #{canonical_tag_id} WHERE tag_id IN (#{redundant_tag_ids.join(', ')}) AND NOT EXISTS (SELECT t1.tag_id FROM accounts_tags AS t1 WHERE t1.tag_id = #{canonical_tag_id} AND t1.account_id = t0.account_id)"

View file

@ -29,7 +29,7 @@ module ActiveRecord
if flatten
yield record[1]
else
yield record[1..-1]
yield record[1..]
end
end

View file

@ -12,7 +12,7 @@ module PremailerWebpackStrategy
css = if url.start_with?('http')
HTTP.get(url).to_s
else
url = url[1..-1] if url.start_with?('/')
url = url[1..] if url.start_with?('/')
Rails.public_path.join(url).read
end

View file

@ -50,7 +50,7 @@ namespace :repo do
file.each_line do |line|
if line.start_with?('-')
new_line = line.gsub(/#([[:digit:]]+)*/) do |pull_request_reference|
pull_request_number = pull_request_reference[1..-1]
pull_request_number = pull_request_reference[1..]
response = nil
loop do