From 75eb519dc170ad6f40862255ab8d41cd4a48f801 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Fri, 13 Sep 2024 15:36:14 +0200 Subject: [PATCH] Fix safe offences in non-production code - Lint/DeprecatedClassMethods - Lint/RedundantRequireStatement - Style/GuardClause --- .rubocop_todo.yml | 16 ---------------- spec/integration/callback.rb | 1 - spec/lib/app_spec.rb | 12 ++++++------ spec/lib/document_spec.rb | 12 ++++++------ 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c685307..6c2d485 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -67,11 +67,6 @@ Lint/AmbiguousOperatorPrecedence: - 'lib/sidekiq_app.rb' - 'spec/spec_helper.rb' -# This cop supports safe autocorrection (--autocorrect). -Lint/DeprecatedClassMethods: - Exclude: - - 'spec/lib/document_spec.rb' - # Configuration parameters: AllowComments, AllowEmptyLambdas. Lint/EmptyBlock: Exclude: @@ -94,11 +89,6 @@ Lint/ParenthesesAsGroupedExpression: Exclude: - 'lib/autoheathen/email_processor.rb' -# This cop supports safe autocorrection (--autocorrect). -Lint/RedundantRequireStatement: - Exclude: - - 'spec/integration/callback.rb' - # This cop supports safe autocorrection (--autocorrect). Lint/RedundantStringCoercion: Exclude: @@ -320,12 +310,6 @@ Style/GlobalStdStream: - 'lib/heathen/processor.rb' - 'lib/sidekiq_workers.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. -Style/GuardClause: - Exclude: - - 'spec/lib/app_spec.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedReceivers. # AllowedReceivers: Thread.current diff --git a/spec/integration/callback.rb b/spec/integration/callback.rb index 08e37d6..eb2d31b 100755 --- a/spec/integration/callback.rb +++ b/spec/integration/callback.rb @@ -2,7 +2,6 @@ # # Simple sinatra app to receive and display callbacks # -require 'pp' require 'sinatra' set :port, 9230 diff --git a/spec/lib/app_spec.rb b/spec/lib/app_spec.rb index d333d9d..75f7d9a 100644 --- a/spec/lib/app_spec.rb +++ b/spec/lib/app_spec.rb @@ -13,12 +13,12 @@ let(:author) { 'spliffy' } def show_backtrace response - if response.status == 500 - begin - puts JSON.pretty_generate(JSON.parse response.body) - rescue StandardError => e - puts response.body - end + return unless response.status == 500 + + begin + puts JSON.pretty_generate(JSON.parse response.body) + rescue StandardError => e + puts response.body end end diff --git a/spec/lib/document_spec.rb b/spec/lib/document_spec.rb index d4e29bd..9c984f3 100644 --- a/spec/lib/document_spec.rb +++ b/spec/lib/document_spec.rb @@ -73,7 +73,7 @@ it 'runs' do dir = document.directory expect(dir).to_not be_nil - expect(File.exists? dir).to eq true + expect(File.exist? dir).to eq true end end @@ -131,7 +131,7 @@ it 'runs' do version = document.new_version expect(version).to_not be_nil - expect(File.exists? document.directory + version).to eq true + expect(File.exist? document.directory + version).to eq true new_doc = described_class.load storage_dir, doc_key expect(new_doc.versions.include? version).to eq true end @@ -142,21 +142,21 @@ file = __FILE__ body = File.read(file) document.add_file 'v002', File.basename(file), body - expect(File.exists? document.directory + 'v002' + File.basename(file)).to eq true + expect(File.exist? document.directory + 'v002' + File.basename(file)).to eq true end it 'runs with author' do file = __FILE__ body = File.read(file) document.add_file 'v002', File.basename(file), body, author - expect(File.exists? document.directory + 'v002' + File.basename(file)).to eq true - expect(File.exists? document.directory + 'v002' + described_class::AUTHOR_FILE).to eq true + expect(File.exist? document.directory + 'v002' + File.basename(file)).to eq true + expect(File.exist? document.directory + 'v002' + described_class::AUTHOR_FILE).to eq true expect(File.read(document.directory + 'v002' + described_class::AUTHOR_FILE).chomp).to eq author end it 'runs with IO for body' do file = __FILE__ body = File.open(file) document.add_file 'v002', File.basename(file), body - expect(File.exists? document.directory + 'v002' + File.basename(file)).to eq true + expect(File.exist? document.directory + 'v002' + File.basename(file)).to eq true end end