Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Enable Rubocop Style/StringConcatenation defaults (mastodon#23792)
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni authored Feb 22, 2023
1 parent 7ecf783 commit 0cfdd1a
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 44 deletions.
19 changes: 0 additions & 19 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2263,25 +2263,6 @@ Style/SlicingWithRange:
- 'lib/mastodon/premailer_webpack_strategy.rb'
- 'lib/tasks/repo.rake'

# Offense count: 25
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'app/lib/activitypub/case_transform.rb'
- 'app/lib/validation_error_formatter.rb'
- 'app/services/backup_service.rb'
- 'app/services/fetch_link_card_service.rb'
- 'lib/mastodon/emoji_cli.rb'
- 'lib/mastodon/redis_config.rb'
- 'lib/mastodon/snowflake.rb'
- 'lib/paperclip/gif_transcoder.rb'
- 'lib/paperclip/type_corrector.rb'
- 'spec/controllers/api/v1/apps_controller_spec.rb'
- 'spec/controllers/api/v1/streaming_controller_spec.rb'
- 'spec/validators/disallowed_hashtags_validator_spec.rb'
- 'spec/workers/web/push_notification_worker_spec.rb'

# Offense count: 272
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, MinSize.
Expand Down
2 changes: 1 addition & 1 deletion app/lib/activitypub/case_transform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def camel_lower(value)
when Symbol then camel_lower(value.to_s).to_sym
when String
camel_lower_cache[value] ||= if value.start_with?('_:')
'_:' + value.gsub(/\A_:/, '').underscore.camelize(:lower)
"_:#{value.gsub(/\A_:/, '').underscore.camelize(:lower)}"
else
value.underscore.camelize(:lower)
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/validation_error_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def details
messages = errors.messages[attribute_name]

h[@aliases[attribute_name] || attribute_name] = attribute_errors.map.with_index do |error, index|
{ error: 'ERR_' + error[:error].to_s.upcase, description: messages[index] }
{ error: "ERR_#{error[:error].to_s.upcase}", description: messages[index] }
end
end

Expand Down
10 changes: 5 additions & 5 deletions app/services/backup_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def build_archive!
end
end

archive_filename = ['archive', Time.now.utc.strftime('%Y%m%d%H%M%S'), SecureRandom.hex(16)].join('-') + '.tar.gz'
archive_filename = "#{['archive', Time.now.utc.strftime('%Y%m%d%H%M%S'), SecureRandom.hex(16)].join('-')}.tar.gz"

@backup.dump = ActionDispatch::Http::UploadedFile.new(tempfile: tmp_file, filename: archive_filename)
@backup.processed = true
Expand Down Expand Up @@ -86,14 +86,14 @@ def dump_outbox!(tar)
def dump_actor!(tar)
actor = serialize(account, ActivityPub::ActorSerializer)

actor[:icon][:url] = 'avatar' + File.extname(actor[:icon][:url]) if actor[:icon]
actor[:image][:url] = 'header' + File.extname(actor[:image][:url]) if actor[:image]
actor[:icon][:url] = "avatar#{File.extname(actor[:icon][:url])}" if actor[:icon]
actor[:image][:url] = "header#{File.extname(actor[:image][:url])}" if actor[:image]
actor[:outbox] = 'outbox.json'
actor[:likes] = 'likes.json'
actor[:bookmarks] = 'bookmarks.json'

download_to_tar(tar, account.avatar, 'avatar' + File.extname(account.avatar.path)) if account.avatar.exists?
download_to_tar(tar, account.header, 'header' + File.extname(account.header.path)) if account.header.exists?
download_to_tar(tar, account.avatar, "avatar#{File.extname(account.avatar.path)}") if account.avatar.exists?
download_to_tar(tar, account.header, "header#{File.extname(account.header.path)}") if account.header.exists?

json = Oj.dump(actor)

Expand Down
2 changes: 1 addition & 1 deletion app/services/fetch_link_card_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def process_url
def html
return @html if defined?(@html)

Request.new(:get, @url).add_headers('Accept' => 'text/html', 'User-Agent' => Mastodon::Version.user_agent + ' Bot').perform do |res|
Request.new(:get, @url).add_headers('Accept' => 'text/html', 'User-Agent' => "#{Mastodon::Version.user_agent} Bot").perform do |res|
# We follow redirects, and ideally we want to save the preview card for
# the destination URL and not any link shortener in-between, so here
# we set the URL to the one of the last response in the redirect chain
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/emoji_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def import(path)
failed += 1
say('Failure/Error: ', :red)
say(entry.full_name)
say(' ' + custom_emoji.errors[:image].join(', '), :red)
say(" #{custom_emoji.errors[:image].join(', ')}", :red)
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/mastodon/redis_config.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

def setup_redis_env_url(prefix = nil, defaults = true)
prefix = prefix.to_s.upcase + '_' unless prefix.nil?
prefix = "#{prefix.to_s.upcase}_" unless prefix.nil?
prefix = '' if prefix.nil?

return if ENV[prefix + 'REDIS_URL'].present?
return if ENV["#{prefix}REDIS_URL"].present?

password = ENV.fetch(prefix + 'REDIS_PASSWORD') { '' if defaults }
host = ENV.fetch(prefix + 'REDIS_HOST') { 'localhost' if defaults }
port = ENV.fetch(prefix + 'REDIS_PORT') { 6379 if defaults }
db = ENV.fetch(prefix + 'REDIS_DB') { 0 if defaults }
password = ENV.fetch("#{prefix}REDIS_PASSWORD") { '' if defaults }
host = ENV.fetch("#{prefix}REDIS_HOST") { 'localhost' if defaults }
port = ENV.fetch("#{prefix}REDIS_PORT") { 6379 if defaults }
db = ENV.fetch("#{prefix}REDIS_DB") { 0 if defaults }

ENV[prefix + 'REDIS_URL'] = begin
ENV["#{prefix}REDIS_URL"] = begin
if [password, host, port, db].all?(&:nil?)
ENV['REDIS_URL']
else
Expand All @@ -27,7 +27,7 @@ def setup_redis_env_url(prefix = nil, defaults = true)
setup_redis_env_url(:sidekiq, false)

namespace = ENV.fetch('REDIS_NAMESPACE', nil)
cache_namespace = namespace ? namespace + '_cache' : 'cache'
cache_namespace = namespace ? "#{namespace}_cache" : 'cache'
sidekiq_namespace = namespace

REDIS_CACHE_PARAMS = {
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/snowflake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def ensure_id_sequences_exist
# And only those that are using timestamp_id.
next unless (data = DEFAULT_REGEX.match(id_col.default_function))

seq_name = data[:seq_prefix] + '_id_seq'
seq_name = "#{data[:seq_prefix]}_id_seq"

# If we were on Postgres 9.5+, we could do CREATE SEQUENCE IF
# NOT EXISTS, but we can't depend on that. Instead, catch the
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/gif_transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def make
final_file = Paperclip::Transcoder.make(file, options, attachment)

if options[:style] == :original
attachment.instance.file_file_name = File.basename(attachment.instance.file_file_name, '.*') + '.mp4'
attachment.instance.file_file_name = "#{File.basename(attachment.instance.file_file_name, '.*')}.mp4"
attachment.instance.file_content_type = 'video/mp4'
attachment.instance.type = MediaAttachment.types[:gifv]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/type_corrector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TypeCorrector < Paperclip::Processor
def make
return @file unless options[:format]

target_extension = '.' + options[:format]
target_extension = ".#{options[:format]}"
extension = File.extname(attachment.instance_read(:file_name))

return @file unless options[:style] == :original && target_extension && extension != target_extension
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/api/v1/apps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@
end

context 'with a too-long website' do
let(:website) { 'https://foo.bar/' + ('hoge' * 2_000) }
let(:website) { "https://foo.bar/#{'hoge' * 2_000}" }

it 'returns http unprocessable entity' do
expect(response).to have_http_status(422)
end
end

context 'with a too-long redirect_uris' do
let(:redirect_uris) { 'https://foo.bar/' + ('hoge' * 2_000) }
let(:redirect_uris) { "https://foo.bar/#{'hoge' * 2_000}" }

it 'returns http unprocessable entity' do
expect(response).to have_http_status(422)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/api/v1/streaming_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

context 'with streaming api on different host' do
before(:each) do
Rails.configuration.x.streaming_api_base_url = 'wss://streaming-' + Rails.configuration.x.web_domain
Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}"
@streaming_host = URI.parse(Rails.configuration.x.streaming_api_base_url).host
end

Expand Down
2 changes: 1 addition & 1 deletion spec/validators/disallowed_hashtags_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
described_class.new.validate(status)
end

let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: disallowed_tags.map { |x| '#' + x }.join(' ')) }
let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: disallowed_tags.map { |x| "##{x}" }.join(' ')) }
let(:errors) { double(add: nil) }

context 'for a remote reblog' do
Expand Down
2 changes: 1 addition & 1 deletion spec/workers/web/push_notification_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
expect(a_request(:post, endpoint).with(headers: {
'Content-Encoding' => 'aesgcm',
'Content-Type' => 'application/octet-stream',
'Crypto-Key' => 'dh=BAgtUks5d90kFmxGevk9tH7GEmvz9DB0qcEMUsOBgKwMf-TMjsKIIG6LQvGcFAf6jcmAod15VVwmYwGIIxE4VWE;p256ecdsa=' + vapid_public_key.delete('='),
'Crypto-Key' => "dh=BAgtUks5d90kFmxGevk9tH7GEmvz9DB0qcEMUsOBgKwMf-TMjsKIIG6LQvGcFAf6jcmAod15VVwmYwGIIxE4VWE;p256ecdsa=#{vapid_public_key.delete('=')}",
'Encryption' => 'salt=WJeVM-RY-F9351SVxTFx_g',
'Ttl' => '172800',
'Urgency' => 'normal',
Expand Down

0 comments on commit 0cfdd1a

Please sign in to comment.