~cytrogen/masto-fe

b8b2470cf8e2aa77df2ebdcbf9106aeeb7dd6f68 — Matt Jankowski 2 years ago 658742b
Fix `Style/SlicingWithRange` cop (#25923)

M .rubocop_todo.yml => .rubocop_todo.yml +0 -15
@@ 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

M app/lib/emoji_formatter.rb => app/lib/emoji_formatter.rb +1 -1
@@ 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


M app/lib/text_formatter.rb => app/lib/text_formatter.rb +3 -3
@@ 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

M app/models/account_alias.rb => app/models/account_alias.rb +1 -1
@@ 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

M app/models/domain_block.rb => app/models/domain_block.rb +1 -1
@@ 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

M app/models/email_domain_block.rb => app/models/email_domain_block.rb +1 -1
@@ 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


M app/models/preview_card_provider.rb => app/models/preview_card_provider.rb +1 -1
@@ 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

M app/validators/status_length_validator.rb => app/validators/status_length_validator.rb +1 -1
@@ 53,7 53,7 @@ class StatusLengthValidator < ActiveModel::Validator
      entity[:indices].last
    end

    result << str[last_index..-1]
    result << str[last_index..]
    result
  end
end

M db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb => db/migrate/20190726175042_add_case_insensitive_index_to_tags.rb +1 -1
@@ 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)"

M lib/active_record/batches.rb => lib/active_record/batches.rb +1 -1
@@ 29,7 29,7 @@ module ActiveRecord
          if flatten
            yield record[1]
          else
            yield record[1..-1]
            yield record[1..]
          end
        end


M lib/mastodon/premailer_webpack_strategy.rb => lib/mastodon/premailer_webpack_strategy.rb +1 -1
@@ 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


M lib/tasks/repo.rake => lib/tasks/repo.rake +1 -1
@@ 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