Skip to content

Commit

Permalink
Fix Performance/DeletePrefix cop (mastodon#24796)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored and Michael Mitchell committed May 3, 2023
1 parent 4002c3d commit 0c7336e
Show file tree
Hide file tree
Showing 10 changed files with 9 additions and 24 deletions.
15 changes: 0 additions & 15 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,6 @@ Performance/CollectionLiteralInLoop:
- 'config/deploy.rb'
- 'lib/mastodon/media_cli.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeMultiline.
Performance/DeletePrefix:
Exclude:
- 'app/controllers/authorize_interactions_controller.rb'
- 'app/controllers/concerns/signature_verification.rb'
- 'app/controllers/intents_controller.rb'
- 'app/lib/activitypub/case_transform.rb'
- 'app/lib/permalink_redirector.rb'
- 'app/lib/webfinger_resource.rb'
- 'app/services/activitypub/fetch_remote_actor_service.rb'
- 'app/services/backup_service.rb'
- 'app/services/resolve_account_service.rb'
- 'app/services/tag_search_service.rb'

# This cop supports unsafe autocorrection (--autocorrect-all).
Performance/MapCompact:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/authorize_interactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def parsed_uri
end

def uri_param
params[:uri] || params.fetch(:acct, '').gsub(/\Aacct:/, '')
params[:uri] || params.fetch(:acct, '').delete_prefix('acct:')
end

def set_body_classes
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/signature_verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def actor_from_key_id(key_id)
end

if key_id.start_with?('acct:')
stoplight_wrap_request { ResolveAccountService.new.call(key_id.gsub(/\Aacct:/, ''), suppress_errors: false) }
stoplight_wrap_request { ResolveAccountService.new.call(key_id.delete_prefix('acct:'), suppress_errors: false) }
elsif !ActivityPub::TagManager.instance.local_uri?(key_id)
account = ActivityPub::TagManager.instance.uri_to_actor(key_id)
account ||= stoplight_wrap_request { ActivityPub::FetchRemoteKeyService.new.call(key_id, id: false, suppress_errors: false) }
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/intents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def show
if uri.scheme == 'web+mastodon'
case uri.host
when 'follow'
return redirect_to authorize_interaction_path(uri: uri.query_values['uri'].gsub(/\Aacct:/, ''))
return redirect_to authorize_interaction_path(uri: uri.query_values['uri'].delete_prefix('acct:'))
when 'share'
return redirect_to share_path(text: uri.query_values['text'])
end
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.delete_prefix('_:').underscore.camelize(:lower)}"
else
value.underscore.camelize(:lower)
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/permalink_redirector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def second_segment
end

def path_segments
@path_segments ||= @path.gsub(/\A\//, '').split('/')
@path_segments ||= @path.delete_prefix('/').split('/')
end

def find_status_url_by_id(id)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/webfinger_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def split_acct
end

def resource_without_acct_string
resource.gsub(/\Aacct:/, '')
resource.delete_prefix('acct:')
end

def local_username
Expand Down
2 changes: 1 addition & 1 deletion app/services/activitypub/fetch_remote_actor_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def check_webfinger!
end

def split_acct(acct)
acct.gsub(/\Aacct:/, '').split('@')
acct.delete_prefix('acct:').split('@')
end

def supported_context?
Expand Down
2 changes: 1 addition & 1 deletion app/services/resolve_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def process_webfinger!(uri)
end

def split_acct(acct)
acct.gsub(/\Aacct:/, '').split('@')
acct.delete_prefix('acct:').split('@')
end

def fetch_account!
Expand Down
2 changes: 1 addition & 1 deletion app/services/tag_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class TagSearchService < BaseService
def call(query, options = {})
@query = query.strip.gsub(/\A#/, '')
@query = query.strip.delete_prefix('#')
@offset = options.delete(:offset).to_i
@limit = options.delete(:limit).to_i
@options = options
Expand Down

0 comments on commit 0c7336e

Please sign in to comment.