Bump rubocop from 0.86.0 to 0.88.0 (#14412)

* Bump rubocop from 0.86.0 to 0.88.0

Bumps [rubocop](https://github.com/rubocop-hq/rubocop) from 0.86.0 to 0.88.0.
- [Release notes](https://github.com/rubocop-hq/rubocop/releases)
- [Changelog](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop-hq/rubocop/compare/v0.86.0...v0.88.0)

Signed-off-by: dependabot[bot] <support@github.com>

* Fix for latest RuboCop

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Yamagishi Kazutoshi <ykzts@desire.sh>
lolsob-rspec
dependabot[bot] 2020-09-01 03:04:00 +02:00 committed by GitHub
parent ae32cd7a14
commit 61b768572e
21 changed files with 208 additions and 37 deletions

View File

@ -30,7 +30,7 @@ plugins:
channel: eslint-7 channel: eslint-7
rubocop: rubocop:
enabled: true enabled: true
channel: rubocop-0-82 channel: rubocop-0-88
sass-lint: sass-lint:
enabled: true enabled: true
exclude_patterns: exclude_patterns:

View File

@ -25,30 +25,68 @@ Layout/AccessModifierIndentation:
Layout/EmptyLineAfterMagicComment: Layout/EmptyLineAfterMagicComment:
Enabled: false Enabled: false
Layout/EmptyLineAfterGuardClause:
Enabled: false
Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true
Layout/HashAlignment:
Enabled: false
# EnforcedHashRocketStyle: table
# EnforcedColonStyle: table
Layout/SpaceAroundMethodCallOperator:
Enabled: true
Layout/SpaceInsideHashLiteralBraces: Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: space EnforcedStyle: space
Lint/DeprecatedOpenSSLConstant:
Enabled: true
Lint/DuplicateElsifCondition:
Enabled: true
Lint/MixedRegexpCaptureTypes:
Enabled: true
Lint/RaiseException:
Enabled: true
Lint/StructNewOverride:
Enabled: true
Lint/UselessAccessModifier: Lint/UselessAccessModifier:
ContextCreatingMethods: ContextCreatingMethods:
- class_methods - class_methods
Metrics/AbcSize: Metrics/AbcSize:
Max: 100 Max: 100
Exclude:
- 'lib/mastodon/*_cli.rb'
Metrics/BlockLength: Metrics/BlockLength:
Max: 35 Max: 55
Exclude: Exclude:
- 'lib/tasks/**/*' - 'lib/tasks/**/*'
- 'lib/mastodon/*_cli.rb'
Metrics/BlockNesting: Metrics/BlockNesting:
Max: 3 Max: 3
Exclude:
- 'lib/mastodon/*_cli.rb'
Metrics/ClassLength: Metrics/ClassLength:
CountComments: false CountComments: false
Max: 300 Max: 400
Exclude:
- 'lib/mastodon/*_cli.rb'
Metrics/CyclomaticComplexity: Metrics/CyclomaticComplexity:
Max: 25 Max: 25
Exclude:
- 'lib/mastodon/*_cli.rb'
Layout/LineLength: Layout/LineLength:
AllowURI: true AllowURI: true
@ -56,7 +94,9 @@ Layout/LineLength:
Metrics/MethodLength: Metrics/MethodLength:
CountComments: false CountComments: false
Max: 55 Max: 65
Exclude:
- 'lib/mastodon/*_cli.rb'
Metrics/ModuleLength: Metrics/ModuleLength:
CountComments: false CountComments: false
@ -67,34 +107,90 @@ Metrics/ParameterLists:
CountKeywordArgs: true CountKeywordArgs: true
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Max: 20 Max: 25
Naming/MemoizedInstanceVariableName: Naming/MemoizedInstanceVariableName:
Enabled: false Enabled: false
Naming/MethodParameterName:
Enabled: true
Rails: Rails:
Enabled: true Enabled: true
Rails/ApplicationController:
Enabled: false
Exclude:
- 'app/controllers/well_known/**/*.rb'
Rails/BelongsTo:
Enabled: false
Rails/ContentTag:
Enabled: false
Rails/EnumHash: Rails/EnumHash:
Enabled: false Enabled: false
Rails/HasAndBelongsToMany:
Enabled: false
Rails/SkipsModelValidations:
Enabled: false
Rails/HttpStatus:
Enabled: false
Rails/Exit: Rails/Exit:
Exclude: Exclude:
- 'lib/mastodon/*' - 'lib/mastodon/*'
- 'lib/cli.rb' - 'lib/cli.rb'
Rails/FilePath:
Enabled: false
Rails/HasAndBelongsToMany:
Enabled: false
Rails/HasManyOrHasOneDependent:
Enabled: false
Rails/HelperInstanceVariable: Rails/HelperInstanceVariable:
Enabled: false Enabled: false
Rails/HttpStatus:
Enabled: false
Rails/IndexBy:
Enabled: false
Rails/InverseOf:
Enabled: false
Rails/LexicallyScopedActionFilter:
Enabled: false
Rails/OutputSafety:
Enabled: true
Rails/RakeEnvironment:
Enabled: false
Rails/RedundantForeignKey:
Enabled: false
Rails/SkipsModelValidations:
Enabled: false
Rails/UniqueValidationWithoutIndex:
Enabled: false
Style/AccessorGrouping:
Enabled: true
Style/AccessModifierDeclarations:
Enabled: false
Style/ArrayCoercion:
Enabled: true
Style/BisectedAttrAccessor:
Enabled: true
Style/CaseLikeIf:
Enabled: false
Style/ClassAndModuleChildren: Style/ClassAndModuleChildren:
Enabled: false Enabled: false
@ -109,6 +205,15 @@ Style/Documentation:
Style/DoubleNegation: Style/DoubleNegation:
Enabled: true Enabled: true
Style/ExpandPathArguments:
Enabled: false
Style/ExponentialNotation:
Enabled: true
Style/FormatString:
Enabled: false
Style/FormatStringToken: Style/FormatStringToken:
Enabled: false Enabled: false
@ -118,9 +223,33 @@ Style/FrozenStringLiteralComment:
Style/GuardClause: Style/GuardClause:
Enabled: false Enabled: false
Style/HashAsLastArrayItem:
Enabled: false
Style/HashEachMethods:
Enabled: true
Style/HashLikeCase:
Enabled: true
Style/HashTransformKeys:
Enabled: true
Style/HashTransformValues:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/InverseMethods:
Enabled: false
Style/Lambda: Style/Lambda:
Enabled: false Enabled: false
Style/MutableConstant:
Enabled: false
Style/PercentLiteralDelimiters: Style/PercentLiteralDelimiters:
PreferredDelimiters: PreferredDelimiters:
'%i': '()' '%i': '()'
@ -129,9 +258,36 @@ Style/PercentLiteralDelimiters:
Style/PerlBackrefs: Style/PerlBackrefs:
AutoCorrect: false AutoCorrect: false
Style/RedundantAssignment:
Enabled: false
Style/RedundantFetchBlock:
Enabled: true
Style/RedundantFileExtensionInRequire:
Enabled: true
Style/RedundantRegexpCharacterClass:
Enabled: false
Style/RedundantRegexpEscape:
Enabled: false
Style/RedundantReturn:
Enabled: true
Style/RegexpLiteral: Style/RegexpLiteral:
Enabled: false Enabled: false
Style/RescueStandardError:
Enabled: false
Style/SignalException:
Enabled: false
Style/SlicingWithRange:
Enabled: true
Style/SymbolArray: Style/SymbolArray:
Enabled: false Enabled: false
@ -140,3 +296,6 @@ Style/TrailingCommaInArrayLiteral:
Style/TrailingCommaInHashLiteral: Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: 'comma' EnforcedStyleForMultiline: 'comma'
Style/UnpackFirst:
Enabled: false

View File

@ -140,7 +140,7 @@ group :development do
gem 'letter_opener', '~> 1.7' gem 'letter_opener', '~> 1.7'
gem 'letter_opener_web', '~> 1.4' gem 'letter_opener_web', '~> 1.4'
gem 'memory_profiler' gem 'memory_profiler'
gem 'rubocop', '~> 0.86', require: false gem 'rubocop', '~> 0.88', require: false
gem 'rubocop-rails', '~> 2.6', require: false gem 'rubocop-rails', '~> 2.6', require: false
gem 'brakeman', '~> 4.9', require: false gem 'brakeman', '~> 4.9', require: false
gem 'bundler-audit', '~> 0.7', require: false gem 'bundler-audit', '~> 0.7', require: false

View File

@ -535,13 +535,13 @@ GEM
rspec-support (3.9.3) rspec-support (3.9.3)
rspec_junit_formatter (0.4.1) rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0) rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.86.0) rubocop (0.88.0)
parallel (~> 1.10) parallel (~> 1.10)
parser (>= 2.7.0.1) parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0) rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7) regexp_parser (>= 1.7)
rexml rexml
rubocop-ast (>= 0.0.3, < 1.0) rubocop-ast (>= 0.1.0, < 1.0)
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0) unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0) rubocop-ast (0.3.0)
@ -778,7 +778,7 @@ DEPENDENCIES
rspec-rails (~> 4.0) rspec-rails (~> 4.0)
rspec-sidekiq (~> 3.1) rspec-sidekiq (~> 3.1)
rspec_junit_formatter (~> 0.4) rspec_junit_formatter (~> 0.4)
rubocop (~> 0.86) rubocop (~> 0.88)
rubocop-rails (~> 2.6) rubocop-rails (~> 2.6)
ruby-progressbar (~> 1.10) ruby-progressbar (~> 1.10)
sanitize (~> 5.2) sanitize (~> 5.2)

View File

@ -71,6 +71,7 @@ class Api::BaseController < ApplicationController
def limit_param(default_limit) def limit_param(default_limit)
return default_limit unless params[:limit] return default_limit unless params[:limit]
[params[:limit].to_i.abs, default_limit * 2].min [params[:limit].to_i.abs, default_limit * 2].min
end end

View File

@ -32,7 +32,6 @@ module ChallengableConcern
if params.key?(:form_challenge) if params.key?(:form_challenge)
if challenge_passed? if challenge_passed?
session[:challenge_passed_at] = Time.now.utc session[:challenge_passed_at] = Time.now.utc
return
else else
flash.now[:alert] = I18n.t('challenge.invalid_password') flash.now[:alert] = I18n.t('challenge.invalid_password')
render_challenge render_challenge

View File

@ -131,7 +131,7 @@ module SignatureVerification
end end
def verify_signature(account, signature, compare_signed_string) def verify_signature(account, signature, compare_signed_string)
if account.keypair.public_key.verify(OpenSSL::Digest::SHA256.new, signature, compare_signed_string) if account.keypair.public_key.verify(OpenSSL::Digest.new('SHA256'), signature, compare_signed_string)
@signed_request_account = account @signed_request_account = account
@signed_request_account @signed_request_account
end end

View File

@ -162,6 +162,8 @@ module ApplicationHelper
end end
json = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(state_params), serializer: InitialStateSerializer).to_json json = ActiveModelSerializers::SerializableResource.new(InitialStatePresenter.new(state_params), serializer: InitialStateSerializer).to_json
# rubocop:disable Rails/OutputSafety
content_tag(:script, json_escape(json).html_safe, id: 'initial-state', type: 'application/json') content_tag(:script, json_escape(json).html_safe, id: 'initial-state', type: 'application/json')
# rubocop:enable Rails/OutputSafety
end end
end end

View File

@ -27,7 +27,7 @@ class ActivityPub::LinkedDataSignature
document_hash = hash(@json.without('signature')) document_hash = hash(@json.without('signature'))
to_be_verified = options_hash + document_hash to_be_verified = options_hash + document_hash
if creator.keypair.public_key.verify(OpenSSL::Digest::SHA256.new, Base64.decode64(signature), to_be_verified) if creator.keypair.public_key.verify(OpenSSL::Digest.new('SHA256'), Base64.decode64(signature), to_be_verified)
creator creator
end end
end end
@ -44,7 +44,7 @@ class ActivityPub::LinkedDataSignature
to_be_signed = options_hash + document_hash to_be_signed = options_hash + document_hash
keypair = sign_with.present? ? OpenSSL::PKey::RSA.new(sign_with) : creator.keypair keypair = sign_with.present? ? OpenSSL::PKey::RSA.new(sign_with) : creator.keypair
signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest::SHA256.new, to_be_signed)) signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest.new('SHA256'), to_be_signed))
@json.merge('signature' => options.merge('signatureValue' => signature)) @json.merge('signature' => options.merge('signatureValue' => signature))
end end

View File

@ -16,7 +16,7 @@ class EntityCache
end end
def emoji(shortcodes, domain) def emoji(shortcodes, domain)
shortcodes = [shortcodes] unless shortcodes.is_a?(Array) shortcodes = Array(shortcodes)
cached = Rails.cache.read_multi(*shortcodes.map { |shortcode| to_key(:emoji, shortcode, domain) }) cached = Rails.cache.read_multi(*shortcodes.map { |shortcode| to_key(:emoji, shortcode, domain) })
uncached_ids = [] uncached_ids = []

View File

@ -135,6 +135,7 @@ class Formatter
end end
end end
# rubocop:disable Metrics/BlockNesting
def encode_custom_emojis(html, emojis, animate = false) def encode_custom_emojis(html, emojis, animate = false)
return html if emojis.empty? return html if emojis.empty?
@ -189,6 +190,7 @@ class Formatter
html html
end end
# rubocop:enable Metrics/BlockNesting
def rewrite(text, entities) def rewrite(text, entities)
text = text.to_s text = text.to_s

View File

@ -114,7 +114,7 @@ class Request
def signature def signature
algorithm = 'rsa-sha256' algorithm = 'rsa-sha256'
signature = Base64.strict_encode64(@keypair.sign(OpenSSL::Digest::SHA256.new, signed_string)) signature = Base64.strict_encode64(@keypair.sign(OpenSSL::Digest.new('SHA256'), signed_string))
"keyId=\"#{key_id}\",algorithm=\"#{algorithm}\",headers=\"#{signed_headers.keys.join(' ').downcase}\",signature=\"#{signature}\"" "keyId=\"#{key_id}\",algorithm=\"#{algorithm}\",headers=\"#{signed_headers.keys.join(' ').downcase}\",signature=\"#{signature}\""
end end

View File

@ -17,8 +17,10 @@ class SidekiqErrorHandler
private private
# rubocop:disable Naming/MethodParameterName
def limit_backtrace_and_raise(e) def limit_backtrace_and_raise(e)
e.set_backtrace(e.backtrace.first(BACKTRACE_LIMIT)) e.set_backtrace(e.backtrace.first(BACKTRACE_LIMIT))
raise e raise e
end end
# rubocop:enable Naming/MethodParameterName
end end

View File

@ -72,6 +72,7 @@ class PreviewCard < ApplicationRecord
class << self class << self
private private
# rubocop:disable Naming/MethodParameterName
def image_styles(f) def image_styles(f)
styles = { styles = {
original: { original: {
@ -85,6 +86,7 @@ class PreviewCard < ApplicationRecord
styles[:original][:format] = 'jpg' if f.instance.image_content_type == 'image/gif' styles[:original][:format] = 'jpg' if f.instance.image_content_type == 'image/gif'
styles styles
end end
# rubocop:enable Naming/MethodParameterName
end end
private private

View File

@ -253,16 +253,16 @@ class User < ApplicationRecord
@shows_application ||= settings.show_application @shows_application ||= settings.show_application
end end
# rubocop:disable Naming/MethodParameterName
def token_for_app(a) def token_for_app(a)
return nil if a.nil? || a.owner != self return nil if a.nil? || a.owner != self
Doorkeeper::AccessToken Doorkeeper::AccessToken.find_or_create_by(application_id: a.id, resource_owner_id: id) do |t|
.find_or_create_by(application_id: a.id, resource_owner_id: id) do |t|
t.scopes = a.scopes t.scopes = a.scopes
t.expires_in = Doorkeeper.configuration.access_token_expires_in t.expires_in = Doorkeeper.configuration.access_token_expires_in
t.use_refresh_token = Doorkeeper.configuration.refresh_token_enabled? t.use_refresh_token = Doorkeeper.configuration.refresh_token_enabled?
end end
end end
# rubocop:enable Naming/MethodParameterName
def activate_session(request) def activate_session(request)
session_activations.activate(session_id: SecureRandom.hex, session_activations.activate(session_id: SecureRandom.hex,
@ -413,7 +413,7 @@ class User < ApplicationRecord
end end
def notify_staff_about_pending_account! def notify_staff_about_pending_account!
User.staff.includes(:account).each do |u| User.staff.includes(:account).find_each do |u|
next unless u.allows_pending_account_emails? next unless u.allows_pending_account_emails?
AdminMailer.new_pending_account(u.account, self).deliver_later AdminMailer.new_pending_account(u.account, self).deliver_later
end end

View File

@ -78,6 +78,7 @@ class FetchLinkCardService < BaseService
uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme) uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme)
end end
# rubocop:disable Naming/MethodParameterName
def mention_link?(a) def mention_link?(a)
@status.mentions.any? do |mention| @status.mentions.any? do |mention|
a['href'] == ActivityPub::TagManager.instance.url_for(mention.account) a['href'] == ActivityPub::TagManager.instance.url_for(mention.account)
@ -88,6 +89,7 @@ class FetchLinkCardService < BaseService
# Avoid links for hashtags and mentions (microformats) # Avoid links for hashtags and mentions (microformats)
a['rel']&.include?('tag') || a['class']&.match?(/u-url|h-card/) || mention_link?(a) a['rel']&.include?('tag') || a['class']&.match?(/u-url|h-card/) || mention_link?(a)
end end
# rubocop:enable Naming/MethodParameterName
def attempt_oembed def attempt_oembed
service = FetchOEmbedService.new service = FetchOEmbedService.new

View File

@ -13,7 +13,9 @@ class NotifyService < BaseService
push_to_conversation! if direct_message? push_to_conversation! if direct_message?
send_email! if email_enabled? send_email! if email_enabled?
rescue ActiveRecord::RecordInvalid rescue ActiveRecord::RecordInvalid
# rubocop:disable Style/RedundantReturn
return return
# rubocop:enable Style/RedundantReturn
end end
private private

View File

@ -12,8 +12,8 @@ class UpdateAccountService < BaseService
check_links(account) check_links(account)
process_hashtags(account) process_hashtags(account)
end end
rescue Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => de rescue Mastodon::DimensionsValidationError, Mastodon::StreamValidationError => e
account.errors.add(:avatar, de.message) account.errors.add(:avatar, e.message)
false false
end end

View File

@ -23,7 +23,7 @@ end
setup_redis_env_url setup_redis_env_url
setup_redis_env_url(:cache, false) setup_redis_env_url(:cache, false)
namespace = ENV.fetch('REDIS_NAMESPACE') { nil } namespace = ENV.fetch('REDIS_NAMESPACE', nil)
cache_namespace = namespace ? namespace + '_cache' : 'cache' cache_namespace = namespace ? namespace + '_cache' : 'cache'
REDIS_CACHE_PARAMS = { REDIS_CACHE_PARAMS = {

View File

@ -33,16 +33,16 @@ module Mastodon
end end
def repository def repository
ENV.fetch('GITHUB_REPOSITORY') { 'tootsuite/mastodon' } ENV.fetch('GITHUB_REPOSITORY', 'tootsuite/mastodon')
end end
def source_base_url def source_base_url
ENV.fetch('SOURCE_BASE_URL') { "https://github.com/#{repository}" } ENV.fetch('SOURCE_BASE_URL', "https://github.com/#{repository}")
end end
# specify git tag or commit hash here # specify git tag or commit hash here
def source_tag def source_tag
ENV.fetch('SOURCE_TAG') { nil } ENV.fetch('SOURCE_TAG', nil)
end end
def source_url def source_url

View File

@ -89,7 +89,7 @@ module Paperclip
end end
end end
# rubocop:disable Style/MethodParameterName # rubocop:disable Naming/MethodParameterName
def rgb_to_hsl(r, g, b) def rgb_to_hsl(r, g, b)
r /= 255.0 r /= 255.0
g /= 255.0 g /= 255.0
@ -156,7 +156,7 @@ module Paperclip
[(r * 255).round, (g * 255).round, (b * 255).round] [(r * 255).round, (g * 255).round, (b * 255).round]
end end
# rubocop:enable Style/MethodParameterName # rubocop:enable Naming/MethodParameterName
def lighten_or_darken(color, by) def lighten_or_darken(color, by)
hue, saturation, light = rgb_to_hsl(color.r, color.g, color.b) hue, saturation, light = rgb_to_hsl(color.r, color.g, color.b)