Commit bf851133 authored by Yamagishi Kazutoshi's avatar Yamagishi Kazutoshi Committed by GitHub
Browse files

Fix all rubocop warnings

parent 05e39dc6
Showing with 67 additions and 39 deletions
+67 -39
...@@ -2,8 +2,9 @@ require: ...@@ -2,8 +2,9 @@ require:
- rubocop-rails - rubocop-rails
AllCops: AllCops:
TargetRubyVersion: 2.5 TargetRubyVersion: 2.6
NewCops: disable NewCops: disable
SuggestExtensions: false
Exclude: Exclude:
- 'spec/**/*' - 'spec/**/*'
- 'db/**/*' - 'db/**/*'
...@@ -41,6 +42,10 @@ Layout/FirstHashElementIndentation: ...@@ -41,6 +42,10 @@ Layout/FirstHashElementIndentation:
Layout/HashAlignment: Layout/HashAlignment:
Enabled: false Enabled: false
Layout/LineLength:
AllowURI: true
Enabled: false
Layout/SpaceAroundMethodCallOperator: Layout/SpaceAroundMethodCallOperator:
Enabled: true Enabled: true
...@@ -56,6 +61,9 @@ Lint/DuplicateElsifCondition: ...@@ -56,6 +61,9 @@ Lint/DuplicateElsifCondition:
Lint/MixedRegexpCaptureTypes: Lint/MixedRegexpCaptureTypes:
Enabled: true Enabled: true
Lint/NonLocalExitFromIterator:
Enabled: false
Lint/RaiseException: Lint/RaiseException:
Enabled: true Enabled: true
...@@ -93,10 +101,6 @@ Metrics/CyclomaticComplexity: ...@@ -93,10 +101,6 @@ Metrics/CyclomaticComplexity:
Exclude: Exclude:
- 'lib/mastodon/*_cli.rb' - 'lib/mastodon/*_cli.rb'
Layout/LineLength:
AllowURI: true
Enabled: false
Metrics/MethodLength: Metrics/MethodLength:
CountComments: false CountComments: false
Max: 65 Max: 65
...@@ -108,11 +112,14 @@ Metrics/ModuleLength: ...@@ -108,11 +112,14 @@ Metrics/ModuleLength:
Max: 200 Max: 200
Metrics/ParameterLists: Metrics/ParameterLists:
Max: 5 Max: 6
CountKeywordArgs: true CountKeywordArgs: true
MaxOptionalParameters: 4
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Max: 25 Max: 25
Exclude:
- 'lib/mastodon/*_cli.rb'
Naming/MemoizedInstanceVariableName: Naming/MemoizedInstanceVariableName:
Enabled: false Enabled: false
...@@ -166,6 +173,10 @@ Rails/InverseOf: ...@@ -166,6 +173,10 @@ Rails/InverseOf:
Rails/LexicallyScopedActionFilter: Rails/LexicallyScopedActionFilter:
Enabled: false Enabled: false
Rails/Output:
Exclude:
- 'lib/mastodon/*_cli.rb'
Rails/OutputSafety: Rails/OutputSafety:
Enabled: true Enabled: true
...@@ -204,6 +215,9 @@ Style/CollectionMethods: ...@@ -204,6 +215,9 @@ Style/CollectionMethods:
PreferredMethods: PreferredMethods:
find_all: 'select' find_all: 'select'
Style/CombinableLoops:
Enabled: false
Style/Documentation: Style/Documentation:
Enabled: false Enabled: false
...@@ -255,6 +269,9 @@ Style/Lambda: ...@@ -255,6 +269,9 @@ Style/Lambda:
Style/MutableConstant: Style/MutableConstant:
Enabled: false Enabled: false
Style/OptionalBooleanParameter:
Enabled: false
Style/PercentLiteralDelimiters: Style/PercentLiteralDelimiters:
PreferredDelimiters: PreferredDelimiters:
'%i': '()' '%i': '()'
...@@ -307,3 +324,7 @@ Style/TrailingCommaInHashLiteral: ...@@ -307,3 +324,7 @@ Style/TrailingCommaInHashLiteral:
Style/UnpackFirst: Style/UnpackFirst:
Enabled: false Enabled: false
Style/WordArray:
Exclude:
- 'app/helpers/languages_helper.rb'
...@@ -132,7 +132,7 @@ group :development do ...@@ -132,7 +132,7 @@ group :development do
gem 'letter_opener', '~> 1.8' gem 'letter_opener', '~> 1.8'
gem 'letter_opener_web', '~> 2.0' gem 'letter_opener_web', '~> 2.0'
gem 'memory_profiler' gem 'memory_profiler'
gem 'rubocop', '~> 1.30', require: false gem 'rubocop', '~> 1.31', require: false
gem 'rubocop-rails', '~> 2.15', require: false gem 'rubocop-rails', '~> 2.15', require: false
gem 'brakeman', '~> 5.2', require: false gem 'brakeman', '~> 5.2', require: false
gem 'bundler-audit', '~> 0.9', require: false gem 'bundler-audit', '~> 0.9', require: false
......
...@@ -305,7 +305,7 @@ GEM ...@@ -305,7 +305,7 @@ GEM
httplog (1.5.0) httplog (1.5.0)
rack (>= 1.0) rack (>= 1.0)
rainbow (>= 2.0.0) rainbow (>= 2.0.0)
i18n (1.10.0) i18n (1.12.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
i18n-tasks (1.0.11) i18n-tasks (1.0.11)
activesupport (>= 4.0.2) activesupport (>= 4.0.2)
...@@ -396,7 +396,7 @@ GEM ...@@ -396,7 +396,7 @@ GEM
mime-types-data (3.2022.0105) mime-types-data (3.2022.0105)
mini_mime (1.1.2) mini_mime (1.1.2)
mini_portile2 (2.8.0) mini_portile2 (2.8.0)
minitest (5.16.0) minitest (5.16.2)
msgpack (1.5.2) msgpack (1.5.2)
multi_json (1.15.0) multi_json (1.15.0)
multipart-post (2.1.1) multipart-post (2.1.1)
...@@ -569,7 +569,8 @@ GEM ...@@ -569,7 +569,8 @@ GEM
rspec-support (3.11.0) rspec-support (3.11.0)
rspec_junit_formatter (0.5.1) rspec_junit_formatter (0.5.1)
rspec-core (>= 2, < 4, != 2.12.0) rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.30.1) rubocop (1.31.2)
json (~> 2.3)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 3.1.0.0) parser (>= 3.1.0.0)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
...@@ -578,9 +579,9 @@ GEM ...@@ -578,9 +579,9 @@ GEM
rubocop-ast (>= 1.18.0, < 2.0) rubocop-ast (>= 1.18.0, < 2.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0) unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.18.0) rubocop-ast (1.19.1)
parser (>= 3.1.1.0) parser (>= 3.1.1.0)
rubocop-rails (2.15.0) rubocop-rails (2.15.2)
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0) rubocop (>= 1.7.0, < 2.0)
...@@ -678,7 +679,7 @@ GEM ...@@ -678,7 +679,7 @@ GEM
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.8.2) unf_ext (0.0.8.2)
unicode-display_width (2.1.0) unicode-display_width (2.2.0)
uniform_notifier (1.16.0) uniform_notifier (1.16.0)
validate_email (0.1.6) validate_email (0.1.6)
activemodel (>= 3.0) activemodel (>= 3.0)
...@@ -822,7 +823,7 @@ DEPENDENCIES ...@@ -822,7 +823,7 @@ DEPENDENCIES
rspec-rails (~> 5.1) rspec-rails (~> 5.1)
rspec-sidekiq (~> 3.1) rspec-sidekiq (~> 3.1)
rspec_junit_formatter (~> 0.5) rspec_junit_formatter (~> 0.5)
rubocop (~> 1.30) rubocop (~> 1.31)
rubocop-rails (~> 2.15) rubocop-rails (~> 2.15)
ruby-progressbar (~> 1.11) ruby-progressbar (~> 1.11)
sanitize (~> 6.0) sanitize (~> 6.0)
...@@ -848,3 +849,9 @@ DEPENDENCIES ...@@ -848,3 +849,9 @@ DEPENDENCIES
webpacker (~> 5.4) webpacker (~> 5.4)
webpush (~> 0.3) webpush (~> 0.3)
xorcist (~> 1.1) xorcist (~> 1.1)
RUBY VERSION
ruby 3.0.4p208
BUNDLED WITH
2.2.33
...@@ -30,7 +30,7 @@ class Api::V1::AccountsController < Api::BaseController ...@@ -30,7 +30,7 @@ class Api::V1::AccountsController < Api::BaseController
self.response_body = Oj.dump(response.body) self.response_body = Oj.dump(response.body)
self.status = response.status self.status = response.status
rescue ActiveRecord::RecordInvalid => e rescue ActiveRecord::RecordInvalid => e
render json: ValidationErrorFormatter.new(e, :'account.username' => :username, :'invite_request.text' => :reason).as_json, status: :unprocessable_entity render json: ValidationErrorFormatter.new(e, 'account.username': :username, 'invite_request.text': :reason).as_json, status: :unprocessable_entity
end end
def follow def follow
......
...@@ -122,7 +122,7 @@ class Auth::SessionsController < Devise::SessionsController ...@@ -122,7 +122,7 @@ class Auth::SessionsController < Devise::SessionsController
redirect_to new_user_session_path, alert: I18n.t('devise.failure.timeout') redirect_to new_user_session_path, alert: I18n.t('devise.failure.timeout')
end end
def set_attempt_session(user) def set_attempt_session(user) # rubocop:disable Naming/AccessorMethodName
session[:attempt_user_id] = user.id session[:attempt_user_id] = user.id
session[:attempt_user_updated_at] = user.updated_at.to_s session[:attempt_user_updated_at] = user.updated_at.to_s
end end
......
...@@ -112,7 +112,7 @@ module JsonLdHelper ...@@ -112,7 +112,7 @@ module JsonLdHelper
if value.is_a?(Hash) && compacted_value.is_a?(Hash) if value.is_a?(Hash) && compacted_value.is_a?(Hash)
patch_for_forwarding!(value, compacted_value) patch_for_forwarding!(value, compacted_value)
elsif value.is_a?(Array) elsif value.is_a?(Array)
compacted_value = [compacted_value] unless compacted_value.is_a?(Array) compacted_value = [compacted_value] unless compacted_value.is_a?(Array) # rubocop:disable Style/ArrayCoercion
return if value.size != compacted_value.size return if value.size != compacted_value.size
compacted[key] = value.zip(compacted_value).map do |v, vc| compacted[key] = value.zip(compacted_value).map do |v, vc|
...@@ -143,7 +143,7 @@ module JsonLdHelper ...@@ -143,7 +143,7 @@ module JsonLdHelper
def safe_for_forwarding?(original, compacted) def safe_for_forwarding?(original, compacted)
original.without('@context', 'signature').all? do |key, value| original.without('@context', 'signature').all? do |key, value|
compacted_value = compacted[key] compacted_value = compacted[key]
return false unless value.class == compacted_value.class return false unless value.class == compacted_value.class # rubocop:disable Style/ClassEqualityComparison
if value.is_a?(Hash) if value.is_a?(Hash)
safe_for_forwarding?(value, compacted_value) safe_for_forwarding?(value, compacted_value)
......
# frozen_string_literal: true # frozen_string_literal: true
module LanguagesHelper module LanguagesHelper # rubocop:disable Metrics/ModuleLength
ISO_639_1 = { ISO_639_1 = {
aa: ['Afar', 'Afaraf'].freeze, aa: ['Afar', 'Afaraf'].freeze,
ab: ['Abkhaz', 'аҧсуа бызшәа'].freeze, ab: ['Abkhaz', 'аҧсуа бызшәа'].freeze,
......
...@@ -13,7 +13,7 @@ module ActivityPub::CaseTransform ...@@ -13,7 +13,7 @@ module ActivityPub::CaseTransform
when Symbol then camel_lower(value.to_s).to_sym when Symbol then camel_lower(value.to_s).to_sym
when String when String
camel_lower_cache[value] ||= if value.start_with?('_:') camel_lower_cache[value] ||= if value.start_with?('_:')
'_:' + value.gsub(/\A_:/, '').underscore.camelize(:lower) "_:#{value.gsub(/\A_:/, '').underscore.camelize(:lower)}"
else else
value.underscore.camelize(:lower) value.underscore.camelize(:lower)
end end
......
...@@ -62,7 +62,7 @@ class EmojiFormatter ...@@ -62,7 +62,7 @@ class EmojiFormatter
end end
end end
result << html[last_index..-1] result << html[last_index..]
result.html_safe # rubocop:disable Rails/OutputSafety result.html_safe # rubocop:disable Rails/OutputSafety
end end
......
...@@ -29,7 +29,7 @@ module Extractor ...@@ -29,7 +29,7 @@ module Extractor
text.scan(Account::MENTION_RE) do |screen_name, _| text.scan(Account::MENTION_RE) do |screen_name, _|
match_data = $LAST_MATCH_INFO match_data = $LAST_MATCH_INFO
after = $' after = Regexp.last_match.post_match
unless Twitter::TwitterText::Regex[:end_mention_match].match?(after) unless Twitter::TwitterText::Regex[:end_mention_match].match?(after)
_, domain = screen_name.split('@') _, domain = screen_name.split('@')
...@@ -64,7 +64,7 @@ module Extractor ...@@ -64,7 +64,7 @@ module Extractor
match_data = $LAST_MATCH_INFO match_data = $LAST_MATCH_INFO
start_position = match_data.char_begin(1) - 1 start_position = match_data.char_begin(1) - 1
end_position = match_data.char_end(1) end_position = match_data.char_end(1)
after = $' after = Regexp.last_match.post_match
if %r{\A://}.match?(after) if %r{\A://}.match?(after)
hash_text.match(/(.+)(https?\Z)/) do |matched| hash_text.match(/(.+)(https?\Z)/) do |matched|
......
...@@ -7,8 +7,8 @@ class RedisConfiguration ...@@ -7,8 +7,8 @@ class RedisConfiguration
@pool = ConnectionPool.new(size: new_pool_size) { new.connection } @pool = ConnectionPool.new(size: new_pool_size) { new.connection }
end end
def with def with(&block)
pool.with { |redis| yield redis } pool.with(&block)
end end
def pool def pool
......
...@@ -64,7 +64,7 @@ class TextFormatter ...@@ -64,7 +64,7 @@ class TextFormatter
indices.last indices.last
end end
result << h(text[last_index..-1]) result << h(text[last_index..])
result result
end end
...@@ -75,8 +75,8 @@ class TextFormatter ...@@ -75,8 +75,8 @@ class TextFormatter
prefix = url.match(URL_PREFIX_REGEX).to_s prefix = url.match(URL_PREFIX_REGEX).to_s
display_url = url[prefix.length, 30] display_url = url[prefix.length, 30]
suffix = url[prefix.length + 30..-1] suffix = url[prefix.length + 30..]
cutoff = url[prefix.length..-1].length > 30 cutoff = url[prefix.length..].length > 30
<<~HTML.squish <<~HTML.squish
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a> <a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>
......
...@@ -53,7 +53,7 @@ class TOCGenerator ...@@ -53,7 +53,7 @@ class TOCGenerator
next unless LISTED_ELEMENTS.include?(node.name) next unless LISTED_ELEMENTS.include?(node.name)
depth = node.name[1..-1] depth = node.name[1..]
latest_section = @headers.last latest_section = @headers.last
if latest_section.nil? || latest_section.depth >= depth if latest_section.nil? || latest_section.depth >= depth
......
...@@ -14,7 +14,7 @@ class UserSettingsDecorator ...@@ -14,7 +14,7 @@ class UserSettingsDecorator
private private
def process_update def process_update # rubocop:disable Metrics/AbcSize
user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails') user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails')
user.settings['interactions'] = merged_interactions if change?('interactions') user.settings['interactions'] = merged_interactions if change?('interactions')
user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy') user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy')
......
...@@ -19,7 +19,7 @@ class ValidationErrorFormatter ...@@ -19,7 +19,7 @@ class ValidationErrorFormatter
messages = errors.messages[attribute_name] messages = errors.messages[attribute_name]
h[@aliases[attribute_name] || attribute_name] = attribute_errors.map.with_index do |error, index| 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
end end
......
...@@ -99,7 +99,7 @@ class Webfinger ...@@ -99,7 +99,7 @@ class Webfinger
end end
def standard_url def standard_url
if @domain.end_with? ".onion" if @domain.end_with? '.onion'
"http://#{@domain}/.well-known/webfinger?resource=#{@uri}" "http://#{@domain}/.well-known/webfinger?resource=#{@uri}"
else else
"https://#{@domain}/.well-known/webfinger?resource=#{@uri}" "https://#{@domain}/.well-known/webfinger?resource=#{@uri}"
...@@ -107,7 +107,7 @@ class Webfinger ...@@ -107,7 +107,7 @@ class Webfinger
end end
def host_meta_url def host_meta_url
if @domain.end_with? ".onion" if @domain.end_with? '.onion'
"http://#{@domain}/.well-known/host-meta" "http://#{@domain}/.well-known/host-meta"
else else
"https://#{@domain}/.well-known/host-meta" "https://#{@domain}/.well-known/host-meta"
......
...@@ -9,9 +9,7 @@ class ApplicationMailer < ActionMailer::Base ...@@ -9,9 +9,7 @@ class ApplicationMailer < ActionMailer::Base
protected protected
def locale_for_account(account) def locale_for_account(account, &block)
I18n.with_locale(account.user_locale || I18n.default_locale) do I18n.with_locale(account.user_locale || I18n.default_locale, &block)
yield
end
end end
end end
...@@ -25,7 +25,7 @@ class AccountAlias < ApplicationRecord ...@@ -25,7 +25,7 @@ class AccountAlias < ApplicationRecord
def acct=(val) def acct=(val)
val = val.to_s.strip val = val.to_s.strip
super(val.start_with?('@') ? val[1..-1] : val) super(val.start_with?('@') ? val[1..] : val)
end end
def pretty_acct def pretty_acct
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# #
class AccountWarning < ApplicationRecord class AccountWarning < ApplicationRecord
# rubocop:disable Lint/RedundantCopDisableDirective, Layout/FirstHashElementIndentation
enum action: { enum action: {
none: 0, none: 0,
disable: 1_000, disable: 1_000,
...@@ -25,6 +26,7 @@ class AccountWarning < ApplicationRecord ...@@ -25,6 +26,7 @@ class AccountWarning < ApplicationRecord
silence: 3_000, silence: 3_000,
suspend: 4_000, suspend: 4_000,
}, _suffix: :action }, _suffix: :action
# rubocop:enable Lint/RedundantCopDisableDirective, Layout/FirstHashElementIndentation
belongs_to :account, inverse_of: :account_warnings belongs_to :account, inverse_of: :account_warnings
belongs_to :target_account, class_name: 'Account', inverse_of: :strikes belongs_to :target_account, class_name: 'Account', inverse_of: :strikes
......
# frozen_string_literal: true # frozen_string_literal: true
module AccountInteractions module AccountInteractions # rubocop:disable Metrics/ModuleLength
extend ActiveSupport::Concern extend ActiveSupport::Concern
class_methods do class_methods do
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment