Skip to content

Commit fdc17be

Browse files
committed
Fix rubocop issues, introduce usage of frozen literal to improve performance
1 parent a91c3ef commit fdc17be

File tree

96 files changed

+329
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+329
-126
lines changed

.rubocop.yml

+32-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,29 @@ Metrics/MethodLength:
1818
CountComments: false
1919
Max: 10
2020

21-
Metrics/ModuleLength:
21+
Metrics/AbcSize:
2222
Max: 100
2323

24+
Metrics/BlockNesting:
25+
Max: 3
26+
27+
Metrics/ClassLength:
28+
CountComments: false
29+
Max: 200
30+
31+
Metrics/CyclomaticComplexity:
32+
Max: 15
33+
34+
Metrics/MethodLength:
35+
Max: 55
36+
37+
Metrics/ModuleLength:
38+
CountComments: false
39+
Max: 200
40+
41+
Metrics/PerceivedComplexity:
42+
Max: 10
43+
2444
Metrics/ParameterLists:
2545
Max: 4
2646
CountKeywordArgs: true
@@ -37,10 +57,10 @@ Style/Documentation:
3757
Enabled: false
3858

3959
Style/DoubleNegation:
40-
Enabled: false
60+
Enabled: true
4161

4262
Style/FrozenStringLiteralComment:
43-
Enabled: false
63+
Enabled: true
4464

4565
Style/SpaceInsideHashLiteralBraces:
4666
EnforcedStyle: space
@@ -51,10 +71,18 @@ Style/TrailingCommaInLiteral:
5171
Style/RegexpLiteral:
5272
Enabled: false
5373

74+
Style/Lambda:
75+
Enabled: false
76+
77+
Rails/HasAndBelongsToMany:
78+
Enabled: false
79+
5480
AllCops:
55-
TargetRubyVersion: 2.2
81+
TargetRubyVersion: 2.3
5682
Exclude:
5783
- 'spec/**/*'
5884
- 'db/**/*'
5985
- 'app/views/**/*'
6086
- 'config/**/*'
87+
- 'bin/*'
88+
- 'Rakefile'

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gem 'rails', '5.0.0.1'

app/channels/application_cable/channel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Channel < ActionCable::Channel::Base
35
protected

app/channels/application_cable/connection.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module ApplicationCable
24
class Connection < ActionCable::Connection::Base
35
identified_by :current_user

app/channels/hashtag_channel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class HashtagChannel < ApplicationCable::Channel
24
def subscribed
35
tag = params[:tag].downcase

app/channels/public_channel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class PublicChannel < ApplicationCable::Channel
24
def subscribed
35
stream_from 'timeline:public', lambda { |encoded_message|

app/channels/timeline_channel.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class TimelineChannel < ApplicationCable::Channel
24
def subscribed
35
stream_from "timeline:#{current_user.account_id}"

app/controllers/about_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class AboutController < ApplicationController
24
before_action :set_body_classes
35

app/controllers/accounts_controller.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class AccountsController < ApplicationController
24
layout 'public'
35

@@ -41,10 +43,7 @@ def set_account
4143
end
4244

4345
def set_link_headers
44-
response.headers['Link'] = LinkHeader.new([
45-
[webfinger_account_url, [['rel', 'lrdd'], ['type', 'application/xrd+xml']]],
46-
[account_url(@account, format: 'atom'), [['rel', 'alternate'], ['type', 'application/atom+xml']]]
47-
])
46+
response.headers['Link'] = LinkHeader.new([[webfinger_account_url, [%w(rel lrdd), %w(type application/xrd+xml)]], [account_url(@account, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
4847
end
4948

5049
def webfinger_account_url

app/controllers/api/salmon_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::SalmonController < ApiController
24
before_action :set_account
35
respond_to :txt

app/controllers/api/subscriptions_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::SubscriptionsController < ApiController
24
before_action :set_account
35
respond_to :txt

app/controllers/api/v1/accounts_controller.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::V1::AccountsController < ApiController
24
before_action -> { doorkeeper_authorize! :read }, except: [:follow, :unfollow, :block, :unblock]
35
before_action -> { doorkeeper_authorize! :follow }, only: [:follow, :unfollow, :block, :unblock]
@@ -20,7 +22,7 @@ def following
2022
@accounts = results.map { |f| accounts[f.target_account_id] }
2123

2224
next_path = following_api_v1_account_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
23-
prev_path = following_api_v1_account_url(since_id: results.first.id) if results.size > 0
25+
prev_path = following_api_v1_account_url(since_id: results.first.id) unless results.empty?
2426

2527
set_pagination_headers(next_path, prev_path)
2628

@@ -33,7 +35,7 @@ def followers
3335
@accounts = results.map { |f| accounts[f.account_id] }
3436

3537
next_path = followers_api_v1_account_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
36-
prev_path = followers_api_v1_account_url(since_id: results.first.id) if results.size > 0
38+
prev_path = followers_api_v1_account_url(since_id: results.first.id) unless results.empty?
3739

3840
set_pagination_headers(next_path, prev_path)
3941

@@ -56,7 +58,7 @@ def statuses
5658
set_maps(@statuses)
5759

5860
next_path = statuses_api_v1_account_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
59-
prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) if @statuses.size > 0
61+
prev_path = statuses_api_v1_account_url(since_id: @statuses.first.id) unless @statuses.empty?
6062

6163
set_pagination_headers(next_path, prev_path)
6264
end

app/controllers/api/v1/apps_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::V1::AppsController < ApiController
24
respond_to :json
35

app/controllers/api/v1/follows_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::V1::FollowsController < ApiController
24
before_action -> { doorkeeper_authorize! :follow }
35
before_action :require_user!

app/controllers/api/v1/media_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::V1::MediaController < ApiController
24
before_action -> { doorkeeper_authorize! :write }
35
before_action :require_user!

app/controllers/api/v1/statuses_controller.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::V1::StatusesController < ApiController
24
before_action -> { doorkeeper_authorize! :read }, except: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
35
before_action -> { doorkeeper_authorize! :write }, only: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
@@ -10,7 +12,7 @@ def show
1012
end
1113

1214
def context
13-
@context = OpenStruct.new({ ancestors: @status.ancestors, descendants: @status.descendants })
15+
@context = OpenStruct.new(ancestors: @status.ancestors, descendants: @status.descendants)
1416
set_maps([@status] + @context[:ancestors] + @context[:descendants])
1517
end
1618

@@ -20,7 +22,7 @@ def reblogged_by
2022
@accounts = results.map { |r| accounts[r.account_id] }
2123

2224
next_path = reblogged_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
23-
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) if results.size > 0
25+
prev_path = reblogged_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
2426

2527
set_pagination_headers(next_path, prev_path)
2628

@@ -33,7 +35,7 @@ def favourited_by
3335
@accounts = results.map { |f| accounts[f.account_id] }
3436

3537
next_path = favourited_by_api_v1_status_url(max_id: results.last.id) if results.size == DEFAULT_ACCOUNTS_LIMIT
36-
prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) if results.size > 0
38+
prev_path = favourited_by_api_v1_status_url(since_id: results.first.id) unless results.empty?
3739

3840
set_pagination_headers(next_path, prev_path)
3941

app/controllers/api/v1/timelines_controller.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Api::V1::TimelinesController < ApiController
24
before_action -> { doorkeeper_authorize! :read }
35
before_action :require_user!, only: [:home, :mentions]
@@ -10,7 +12,7 @@ def home
1012
set_maps(@statuses)
1113

1214
next_path = api_v1_home_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
13-
prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
15+
prev_path = api_v1_home_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
1416

1517
set_pagination_headers(next_path, prev_path)
1618

@@ -23,7 +25,7 @@ def mentions
2325
set_maps(@statuses)
2426

2527
next_path = api_v1_mentions_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
26-
prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
28+
prev_path = api_v1_mentions_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
2729

2830
set_pagination_headers(next_path, prev_path)
2931

@@ -36,7 +38,7 @@ def public
3638
set_maps(@statuses)
3739

3840
next_path = api_v1_public_timeline_url(max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
39-
prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) if @statuses.size > 0
41+
prev_path = api_v1_public_timeline_url(since_id: @statuses.first.id) unless @statuses.empty?
4042

4143
set_pagination_headers(next_path, prev_path)
4244

@@ -50,7 +52,7 @@ def tag
5052
set_maps(@statuses)
5153

5254
next_path = api_v1_hashtag_timeline_url(params[:id], max_id: @statuses.last.id) if @statuses.size == DEFAULT_STATUSES_LIMIT
53-
prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) if @statuses.size > 0
55+
prev_path = api_v1_hashtag_timeline_url(params[:id], since_id: @statuses.first.id) unless @statuses.empty?
5456

5557
set_pagination_headers(next_path, prev_path)
5658

app/controllers/api_controller.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ApiController < ApplicationController
24
DEFAULT_STATUSES_LIMIT = 20
35
DEFAULT_ACCOUNTS_LIMIT = 40
@@ -51,8 +53,8 @@ def set_rate_limit_headers
5153

5254
def set_pagination_headers(next_path = nil, prev_path = nil)
5355
links = []
54-
links << [next_path, [['rel', 'next']]] if next_path
55-
links << [prev_path, [['rel', 'prev']]] if prev_path
56+
links << [next_path, [%w(rel next)]] if next_path
57+
links << [prev_path, [%w(rel prev)]] if prev_path
5658
response.headers['Link'] = LinkHeader.new(links)
5759
end
5860

@@ -76,7 +78,7 @@ def render_empty
7678
render json: {}, status: 200
7779
end
7880

79-
def set_maps(statuses)
81+
def set_maps(statuses) # rubocop:disable Style/AccessorMethodName
8082
if current_account.nil?
8183
@reblogs_map = {}
8284
@favourites_map = {}

app/controllers/application_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationController < ActionController::Base
24
# Prevent CSRF attacks by raising an exception.
35
# For APIs, you may want to use :null_session instead.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Auth::ConfirmationsController < Devise::ConfirmationsController
24
layout 'auth'
35
end
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Auth::PasswordsController < Devise::PasswordsController
24
layout 'auth'
35
end

app/controllers/auth/registrations_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Auth::RegistrationsController < Devise::RegistrationsController
24
layout 'auth'
35

app/controllers/auth/sessions_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Auth::SessionsController < Devise::SessionsController
24
include Devise::Controllers::Rememberable
35

app/controllers/home_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class HomeController < ApplicationController
24
before_action :authenticate_user!
35

app/controllers/media_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class MediaController < ApplicationController
24
before_action :set_media_attachment
35

app/controllers/oauth/authorizations_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Oauth::AuthorizationsController < Doorkeeper::AuthorizationsController
24
skip_before_action :authenticate_resource_owner!
35

app/controllers/settings/preferences_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Settings::PreferencesController < ApplicationController
24
layout 'auth'
35

app/controllers/settings/profiles_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Settings::ProfilesController < ApplicationController
24
layout 'auth'
35

app/controllers/stream_entries_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class StreamEntriesController < ApplicationController
24
layout 'public'
35

@@ -29,9 +31,7 @@ def set_account
2931
end
3032

3133
def set_link_headers
32-
response.headers['Link'] = LinkHeader.new([
33-
[account_stream_entry_url(@account, @stream_entry, format: 'atom'), [['rel', 'alternate'], ['type', 'application/atom+xml']]]
34-
])
34+
response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
3535
end
3636

3737
def set_stream_entry

app/controllers/tags_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class TagsController < ApplicationController
24
layout 'public'
35

0 commit comments

Comments
 (0)