diff --git a/.rubocop.common.yml b/.rubocop.common.yml index c431e8d1a43..a0ea7c69fe2 100644 --- a/.rubocop.common.yml +++ b/.rubocop.common.yml @@ -226,6 +226,10 @@ Style/MutableConstant: Severity: error Style/NegatedIf: Severity: error +Style/NegatedUnless: + Severity: error +Style/NegatedWhile: + Severity: error Style/NumericPredicate: Enabled: false # `> 0` can be easier to read than `.positive?` Style/OrAssignment: diff --git a/app/models/attachment.rb b/app/models/attachment.rb index d2db552c585..92133d8ae3a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -777,7 +777,7 @@ class Attachment < ActiveRecord::Base valid_name = false self.shard.activate do iter_count = 1 - while !valid_name + until valid_name existing_names = self.folder.active_file_attachments.where.not(id: self.id).pluck(:display_name) new_name = opts[:name] || self.display_name self.display_name = Attachment.make_unique_filename(new_name, existing_names, iter_count) diff --git a/app/models/kaltura_media_file_handler.rb b/app/models/kaltura_media_file_handler.rb index 7aa5de21bc2..f872bc78a08 100644 --- a/app/models/kaltura_media_file_handler.rb +++ b/app/models/kaltura_media_file_handler.rb @@ -74,7 +74,7 @@ class KalturaMediaFileHandler Rails.logger.debug "waiting for bulk upload id: #{bulk_upload_id}" started_at = Time.now timeout = Setting.get('media_bulk_upload_timeout', 30.minutes.to_s).to_i - while !res[:ready] + until res[:ready] if Time.now > started_at + timeout refresh_later(res[:id], attachments, root_account_id) break diff --git a/app/models/quizzes/quiz_submission.rb b/app/models/quizzes/quiz_submission.rb index 4ddf82a9ca0..fc9283fa1ef 100644 --- a/app/models/quizzes/quiz_submission.rb +++ b/app/models/quizzes/quiz_submission.rb @@ -165,7 +165,7 @@ class Quizzes::QuizSubmission < ActiveRecord::Base end def temporary_data - raise "Cannot view temporary data for completed quiz" unless !self.completed? + raise "Cannot view temporary data for completed quiz" if self.completed? raise "Cannot view temporary data for completed quiz" if graded? (self.submission_data || {}).with_indifferent_access diff --git a/config/initializers/cache_store.rb b/config/initializers/cache_store.rb index f92cb5aaece..b9bfa7f711f 100644 --- a/config/initializers/cache_store.rb +++ b/config/initializers/cache_store.rb @@ -23,7 +23,7 @@ load_cache_config = -> do searched = Set.new clusters_to_search = Switchman::DatabaseServer.all.map(&:id) - while !clusters_to_search.empty? + until clusters_to_search.empty? cluster = clusters_to_search.shift next if searched.include?(cluster) diff --git a/gems/attachment_fu/lib/attachment_fu/processors/mini_magick_processor.rb b/gems/attachment_fu/lib/attachment_fu/processors/mini_magick_processor.rb index df3b50a6093..d7dac73e9b1 100644 --- a/gems/attachment_fu/lib/attachment_fu/processors/mini_magick_processor.rb +++ b/gems/attachment_fu/lib/attachment_fu/processors/mini_magick_processor.rb @@ -30,7 +30,7 @@ module AttachmentFu # :nodoc: # Yields a block containing an MiniMagick Image for the given binary data. def with_image(file) begin - binary_data = file.is_a?(MiniMagick::Image) ? file : MiniMagick::Image.open(file) unless !Object.const_defined?(:MiniMagick) + binary_data = file.is_a?(MiniMagick::Image) ? file : MiniMagick::Image.open(file) if Object.const_defined?(:MiniMagick) rescue # Log the failure to load the image. logger.debug("Exception working with image: #{$!}") diff --git a/gems/plugins/account_reports/lib/account_reports/report_helper.rb b/gems/plugins/account_reports/lib/account_reports/report_helper.rb index 6ba89ab072d..43bf727fe1d 100644 --- a/gems/plugins/account_reports/lib/account_reports/report_helper.rb +++ b/gems/plugins/account_reports/lib/account_reports/report_helper.rb @@ -552,7 +552,7 @@ module AccountReports::ReportHelper def read_csv_in_chunks(filename, chunk_size = 1000) CSV.open(filename) do |csv| rows = [] - while !(row = csv.readline).nil? + until (row = csv.readline).nil? rows << row if rows.size == chunk_size yield rows diff --git a/lib/active_support/cache/safe_redis_race_condition.rb b/lib/active_support/cache/safe_redis_race_condition.rb index 8873df28d77..e0e036f6bc2 100644 --- a/lib/active_support/cache/safe_redis_race_condition.rb +++ b/lib/active_support/cache/safe_redis_race_condition.rb @@ -46,7 +46,7 @@ module ActiveSupport::Cache::SafeRedisRaceCondition lock_key = "lock:#{key}" unless entry - while !entry + until entry unless (lock_nonce = lock(lock_key, options)) # someone else is already generating it; wait for them sleep 0.1 diff --git a/lib/sis/enrollment_importer.rb b/lib/sis/enrollment_importer.rb index d1f6058a37d..39729b76513 100644 --- a/lib/sis/enrollment_importer.rb +++ b/lib/sis/enrollment_importer.rb @@ -130,7 +130,7 @@ module SIS return unless any_left_to_process? enrollment_info = nil - while !@enrollment_batch.empty? + until @enrollment_batch.empty? enrollment_info = @enrollment_batch.shift @last_section = @section if @section diff --git a/lib/tasks/db_load_data.rake b/lib/tasks/db_load_data.rake index fee606bd678..31c401b8e74 100644 --- a/lib/tasks/db_load_data.rake +++ b/lib/tasks/db_load_data.rake @@ -124,7 +124,7 @@ namespace :db do unless user require 'highline/import' - while !Rails.env.test? do + until Rails.env.test? do if telemetry_enabled? print "\e[33mInput fields will be hidden to ensure that entered data will not be sent to the telemetry service.\nWe do not recommend using sensitive data for development environments.\e[0m\n" diff --git a/lib/text_helper.rb b/lib/text_helper.rb index f1ee55cbeae..3958a5794aa 100644 --- a/lib/text_helper.rb +++ b/lib/text_helper.rb @@ -188,8 +188,8 @@ module TextHelper end # remove everything else - while !current.is_a?(Nokogiri::HTML::Document) - while !current.next.nil? + until current.is_a?(Nokogiri::HTML::Document) + until current.next.nil? current.next.remove end current = current.parent diff --git a/lib/vericite.rb b/lib/vericite.rb index b4336f58100..3fd0e8ca69a 100644 --- a/lib/vericite.rb +++ b/lib/vericite.rb @@ -383,7 +383,7 @@ module VeriCite end def response_error_hash(response) - return {} unless !is_response_success?(response) + return {} if is_response_success?(response) { error_code: response[:return_code],