From a6f77aa28ae805e89b0a38c468b7193050174df4 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Fri, 17 Feb 2023 22:30:23 -0500 Subject: [PATCH] Autofix Rubocop Lint/AmbiguousOperatorPrecedence (#23681) --- .rubocop_todo.yml | 11 ---------- .../concerns/rate_limit_headers.rb | 2 +- app/lib/rate_limiter.rb | 2 +- app/models/system_key.rb | 2 +- app/models/webauthn_credential.rb | 2 +- app/workers/concerns/exponential_backoff.rb | 2 +- lib/paperclip/color_extractor.rb | 22 +++++++++---------- 7 files changed, 16 insertions(+), 27 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 68d3f2bd7..0fe77521d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -183,17 +183,6 @@ Lint/AmbiguousBlockAssociation: - 'spec/services/unsuspend_account_service_spec.rb' - 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb' -# Offense count: 17 -# This cop supports safe autocorrection (--autocorrect). -Lint/AmbiguousOperatorPrecedence: - Exclude: - - 'app/controllers/concerns/rate_limit_headers.rb' - - 'app/lib/rate_limiter.rb' - - 'app/models/system_key.rb' - - 'app/models/webauthn_credential.rb' - - 'app/workers/concerns/exponential_backoff.rb' - - 'lib/paperclip/color_extractor.rb' - # Offense count: 15 # Configuration parameters: AllowedMethods. # AllowedMethods: enums diff --git a/app/controllers/concerns/rate_limit_headers.rb b/app/controllers/concerns/rate_limit_headers.rb index b8696df73..b21abfb03 100644 --- a/app/controllers/concerns/rate_limit_headers.rb +++ b/app/controllers/concerns/rate_limit_headers.rb @@ -67,6 +67,6 @@ module RateLimitHeaders end def reset_period_offset - api_throttle_data[:period] - request_time.to_i % api_throttle_data[:period] + api_throttle_data[:period] - (request_time.to_i % api_throttle_data[:period]) end end diff --git a/app/lib/rate_limiter.rb b/app/lib/rate_limiter.rb index 0e2c9a894..4a0b35b08 100644 --- a/app/lib/rate_limiter.rb +++ b/app/lib/rate_limiter.rb @@ -48,7 +48,7 @@ class RateLimiter { 'X-RateLimit-Limit' => @limit.to_s, 'X-RateLimit-Remaining' => (@limit - (redis.get(key) || 0).to_i).to_s, - 'X-RateLimit-Reset' => (now + (@period - now.to_i % @period)).iso8601(6), + 'X-RateLimit-Reset' => (now + (@period - (now.to_i % @period))).iso8601(6), } end diff --git a/app/models/system_key.rb b/app/models/system_key.rb index f17db7c2d..1be399dd6 100644 --- a/app/models/system_key.rb +++ b/app/models/system_key.rb @@ -14,7 +14,7 @@ class SystemKey < ApplicationRecord before_validation :set_key - scope :expired, ->(now = Time.now.utc) { where(arel_table[:created_at].lt(now - ROTATION_PERIOD * 3)) } + scope :expired, ->(now = Time.now.utc) { where(arel_table[:created_at].lt(now - (ROTATION_PERIOD * 3))) } class << self def current_key diff --git a/app/models/webauthn_credential.rb b/app/models/webauthn_credential.rb index 7d423e38d..48abfc1d4 100644 --- a/app/models/webauthn_credential.rb +++ b/app/models/webauthn_credential.rb @@ -18,5 +18,5 @@ class WebauthnCredential < ApplicationRecord validates :external_id, uniqueness: true validates :nickname, uniqueness: { scope: :user_id } validates :sign_count, - numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 2**63 - 1 } + numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: (2**63) - 1 } end diff --git a/app/workers/concerns/exponential_backoff.rb b/app/workers/concerns/exponential_backoff.rb index f2b931e33..7626b2151 100644 --- a/app/workers/concerns/exponential_backoff.rb +++ b/app/workers/concerns/exponential_backoff.rb @@ -5,7 +5,7 @@ module ExponentialBackoff included do sidekiq_retry_in do |count| - 15 + 10 * (count**4) + rand(10 * (count**4)) + 15 + (10 * (count**4)) + rand(10 * (count**4)) end end end diff --git a/lib/paperclip/color_extractor.rb b/lib/paperclip/color_extractor.rb index d3b8e1022..d8a042c90 100644 --- a/lib/paperclip/color_extractor.rb +++ b/lib/paperclip/color_extractor.rb @@ -79,8 +79,8 @@ module Paperclip private def w3c_contrast(color1, color2) - luminance1 = color1.to_xyz.y * 0.01 + 0.05 - luminance2 = color2.to_xyz.y * 0.01 + 0.05 + luminance1 = (color1.to_xyz.y * 0.01) + 0.05 + luminance2 = (color2.to_xyz.y * 0.01) + 0.05 if luminance1 > luminance2 luminance1 / luminance2 @@ -109,11 +109,11 @@ module Paperclip case max when r - h = (g - b) / d + (g < b ? 6.0 : 0) + h = ((g - b) / d) + (g < b ? 6.0 : 0) when g - h = (b - r) / d + 2.0 + h = ((b - r) / d) + 2.0 when b - h = (r - g) / d + 4.0 + h = ((r - g) / d) + 4.0 end h /= 6.0 @@ -126,9 +126,9 @@ module Paperclip t += 1 if t.negative? t -= 1 if t > 1 - return (p + (q - p) * 6 * t) if t < 1 / 6.0 + return (p + ((q - p) * 6 * t)) if t < 1 / 6.0 return q if t < 1 / 2.0 - return (p + (q - p) * (2 / 3.0 - t) * 6) if t < 2 / 3.0 + return (p + ((q - p) * ((2 / 3.0) - t) * 6)) if t < 2 / 3.0 p end @@ -147,11 +147,11 @@ module Paperclip g = l.to_f b = l.to_f # achromatic else - q = l < 0.5 ? l * (s + 1) : l + s - l * s - p = 2 * l - q - r = hue_to_rgb(p, q, h + 1 / 3.0) + q = l < 0.5 ? l * (s + 1) : l + s - (l * s) + p = (2 * l) - q + r = hue_to_rgb(p, q, h + (1 / 3.0)) g = hue_to_rgb(p, q, h) - b = hue_to_rgb(p, q, h - 1 / 3.0) + b = hue_to_rgb(p, q, h - (1 / 3.0)) end [(r * 255).round, (g * 255).round, (b * 255).round]