From 6f84acfb6fbcbe70c38e874bc0e0ba75ec25e978 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 14 Sep 2024 00:29:34 +0200 Subject: [PATCH 1/4] Fix Style/CommentAnnotation offenses --- .rubocop_todo.yml | 8 -------- lib/converter.rb | 8 ++++---- lib/heathen/filename.rb | 2 +- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b62368..fa1467d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -243,14 +243,6 @@ Style/ColonMethodCall: - 'lib/autoheathen/config.rb' - 'spec/spec_helper.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: Keywords, RequireColon. -# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE -Style/CommentAnnotation: - Exclude: - - 'lib/converter.rb' - - 'lib/heathen/filename.rb' - # Configuration parameters: AllowedConstants. Style/Documentation: Exclude: diff --git a/lib/converter.rb b/lib/converter.rb index 81bb8b1..4d35f24 100644 --- a/lib/converter.rb +++ b/lib/converter.rb @@ -20,11 +20,11 @@ def initialize(storage_dir: C_.storage_directory, logger: Logger.new(C_.conversi def convert(doc_key, version, filename, action) doc = Document.load @storage_dir, doc_key ignore, orig_content = doc.get_file(version, filename) - language = 'en' # TODO - add to spec and upload + language = 'en' # TODO: add to spec and upload new_content = convert_file action, orig_content, language - # TODO - handling for variant formats with the same extension - # probably by adding format info before suffix - # e.g. foo.40x40.jpg + # TODO: handling for variant formats with the same extension + # probably by adding format info before suffix + # e.g. foo.40x40.jpg new_filename = Heathen::Filename.suggest filename, new_content.mime_type doc.add_file version, new_filename, new_content doc.save_metadata diff --git a/lib/heathen/filename.rb b/lib/heathen/filename.rb index 4a51b82..17d4a8a 100644 --- a/lib/heathen/filename.rb +++ b/lib/heathen/filename.rb @@ -8,7 +8,7 @@ def self.suggest(filename, mime_type) mime_type = muck_mime_type(mime_type) ext = File.extname(filename) temp_file = filename[0..-(ext.length + 1)] - ext = MIME::Types[mime_type].first.preferred_extension rescue 'txt' # FIXME use a saner extension + ext = MIME::Types[mime_type].first.preferred_extension rescue 'txt' # FIXME: use a saner extension "#{temp_file}.#{ext}" end From ff9e4695523a43c5e377089e2157686eda3ce65b Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 14 Sep 2024 00:34:45 +0200 Subject: [PATCH 2/4] Fix Style/MethodCallWithoutArgsParentheses offense --- .rubocop_todo.yml | 6 ------ lib/heathen/executioner.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fa1467d..46e690b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -324,12 +324,6 @@ Style/IfUnlessModifierOfIfUnless: Exclude: - 'lib/heathen/executioner.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedMethods, AllowedPatterns. -Style/MethodCallWithoutArgsParentheses: - Exclude: - - 'lib/heathen/executioner.rb' - # This cop supports unsafe autocorrection (--autocorrect-all). Style/MinMaxComparison: Exclude: diff --git a/lib/heathen/executioner.rb b/lib/heathen/executioner.rb index abeac65..88ebae4 100644 --- a/lib/heathen/executioner.rb +++ b/lib/heathen/executioner.rb @@ -58,7 +58,7 @@ def _execute(*argv, options) builder.directory(dir) end - process = builder.start() + process = builder.start # Dirty hack, works on UNIX only. pid = if process.is_a?(Java::JavaLang::UNIXProcess) From 2e4d7bf96ff6e8d9155378952f9afe545a14d3be Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 14 Sep 2024 00:35:48 +0200 Subject: [PATCH 3/4] Fix Style/NestedParenthesizedCalls offenses --- .rubocop_todo.yml | 14 ---------- lib/autoheathen/config.rb | 2 +- spec/heathen/filename_spec.rb | 12 ++++----- spec/lib/app_spec.rb | 2 +- spec/lib/autoheathen/email_processor_spec.rb | 6 ++--- spec/lib/converter_spec.rb | 2 +- spec/lib/document_spec.rb | 28 ++++++++++---------- spec/lib/legacy_converter_spec.rb | 2 +- spec/lib/utils_spec.rb | 2 +- 9 files changed, 28 insertions(+), 42 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 46e690b..5e9eed6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -353,20 +353,6 @@ Style/NestedModifier: Exclude: - 'lib/heathen/executioner.rb' -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedMethods. -# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with -Style/NestedParenthesizedCalls: - Exclude: - - 'lib/autoheathen/config.rb' - - 'spec/heathen/filename_spec.rb' - - 'spec/lib/app_spec.rb' - - 'spec/lib/autoheathen/email_processor_spec.rb' - - 'spec/lib/converter_spec.rb' - - 'spec/lib/document_spec.rb' - - 'spec/lib/legacy_converter_spec.rb' - - 'spec/lib/utils_spec.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: Strict, AllowedNumbers, AllowedPatterns. Style/NumericLiterals: diff --git a/lib/autoheathen/config.rb b/lib/autoheathen/config.rb index 70bc746..91f325d 100644 --- a/lib/autoheathen/config.rb +++ b/lib/autoheathen/config.rb @@ -3,7 +3,7 @@ module Config def load_config(defaults = {}, config_file = nil, overwrites = {}) cfg = symbolize_keys(defaults) if config_file && File.exist?(config_file) - cfg.merge! symbolize_keys(YAML::load_file config_file) + cfg.merge! symbolize_keys(YAML::load_file(config_file)) end cfg.merge! symbolize_keys(overwrites) # non-file opts have precedence return cfg diff --git a/spec/heathen/filename_spec.rb b/spec/heathen/filename_spec.rb index 44e69e0..e0fd06b 100644 --- a/spec/heathen/filename_spec.rb +++ b/spec/heathen/filename_spec.rb @@ -6,32 +6,32 @@ let(:mime_type) { content.mime_type } context '.suggest' do it 'suggests foo.pdf' do - expect(described_class.suggest 'foo.pdf', mime_type).to eq 'foo.txt' + expect(described_class.suggest('foo.pdf', mime_type)).to eq 'foo.txt' end it 'suggests bar/foo.pdf' do - expect(described_class.suggest 'bar/foo.pdf', mime_type).to eq 'bar/foo.txt' + expect(described_class.suggest('bar/foo.pdf', mime_type)).to eq 'bar/foo.txt' end it 'suggests foo' do - expect(described_class.suggest 'foo', mime_type).to eq 'foo.txt' + expect(described_class.suggest('foo', mime_type)).to eq 'foo.txt' end it 'suggests bar/foo' do - expect(described_class.suggest 'bar/foo', mime_type).to eq 'bar/foo.txt' + expect(described_class.suggest('bar/foo', mime_type)).to eq 'bar/foo.txt' end end context '.suggest_in_new_dir' do it 'suggests (short dir) -> (longer dir)' do expect( - described_class.suggest_in_new_dir '/home/joe/src/foo.pdf', mime_type, '/home', '/opt/users' + described_class.suggest_in_new_dir('/home/joe/src/foo.pdf', mime_type, '/home', '/opt/users') ).to eq '/opt/users/joe/src/foo.txt' end it 'suggests (longer dir) -> (short dir)' do expect( - described_class.suggest_in_new_dir '/opt/users/joe/src/foo.pdf', mime_type, '/opt/users', '/home' + described_class.suggest_in_new_dir('/opt/users/joe/src/foo.pdf', mime_type, '/opt/users', '/home') ).to eq '/home/joe/src/foo.txt' end end diff --git a/spec/lib/app_spec.rb b/spec/lib/app_spec.rb index 093d578..81191d1 100644 --- a/spec/lib/app_spec.rb +++ b/spec/lib/app_spec.rb @@ -16,7 +16,7 @@ def show_backtrace(response) return unless response.status == 500 begin - puts JSON.pretty_generate(JSON.parse response.body) + puts JSON.pretty_generate(JSON.parse(response.body)) rescue StandardError => e puts response.body end diff --git a/spec/lib/autoheathen/email_processor_spec.rb b/spec/lib/autoheathen/email_processor_spec.rb index e29fb2e..52b63e0 100644 --- a/spec/lib/autoheathen/email_processor_spec.rb +++ b/spec/lib/autoheathen/email_processor_spec.rb @@ -79,9 +79,9 @@ end it 'validates content types' do - expect(processor.get_action 'image/tiff').to eq 'ocr' - expect(processor.get_action 'application/pdf; charset=utf-8').to eq 'ocr' - expect(processor.get_action 'application/msword').to eq 'pdf' + expect(processor.get_action('image/tiff')).to eq 'ocr' + expect(processor.get_action('application/pdf; charset=utf-8')).to eq 'ocr' + expect(processor.get_action('application/msword')).to eq 'pdf' expect { processor.get_action 'foobar' }.to raise_error(RuntimeError) end diff --git a/spec/lib/converter_spec.rb b/spec/lib/converter_spec.rb index 284b718..d0fcdf9 100644 --- a/spec/lib/converter_spec.rb +++ b/spec/lib/converter_spec.rb @@ -25,7 +25,7 @@ foo = double(Heathen::Converter) allow(Heathen::Converter).to receive(:new) { foo } allow(foo).to receive(:convert) { "The quick brown fox" } - expect(converter.convert doc_key, version, filename, action).to eq new_filename + expect(converter.convert(doc_key, version, filename, action)).to eq new_filename content_type, content = document.get_file version, new_filename expect(content_type).to eq 'text/plain; charset=us-ascii' expect(content.to_s).to eq 'The quick brown fox' diff --git a/spec/lib/document_spec.rb b/spec/lib/document_spec.rb index 9c984f3..c2f94df 100644 --- a/spec/lib/document_spec.rb +++ b/spec/lib/document_spec.rb @@ -65,7 +65,7 @@ context '.delete' do it 'runs' do Colore::Document.delete storage_dir, doc_key - expect(Colore::Document.exists? storage_dir, doc_key).to eq false + expect(Colore::Document.exists?(storage_dir, doc_key)).to eq false end end @@ -73,7 +73,7 @@ it 'runs' do dir = document.directory expect(dir).to_not be_nil - expect(File.exist? dir).to eq true + expect(File.exist?(dir)).to eq true end end @@ -105,13 +105,13 @@ context '#has_version?' do it 'runs' do - expect(document.has_version? 'v001').to eq true + expect(document.has_version?('v001')).to eq true end it 'accepts current' do - expect(document.has_version? 'current').to eq true + expect(document.has_version?('current')).to eq true end it 'rejects invalid' do - expect(document.has_version? 'foo').to eq false + expect(document.has_version?('foo')).to eq false end end @@ -131,9 +131,9 @@ it 'runs' do version = document.new_version expect(version).to_not be_nil - expect(File.exist? 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 + expect(new_doc.versions.include?(version)).to eq true end end @@ -142,21 +142,21 @@ file = __FILE__ body = File.read(file) document.add_file 'v002', File.basename(file), body - expect(File.exist? 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.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.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.exist? document.directory + 'v002' + File.basename(file)).to eq true + expect(File.exist?(document.directory + 'v002' + File.basename(file))).to eq true end end @@ -184,7 +184,7 @@ context '#delete_version' do it 'runs' do document.delete_version 'v001' - expect(File.exist? document.directory + 'v001').to eq false + expect(File.exist?(document.directory + 'v001')).to eq false end it 'refuses to delete "current"' do expect { @@ -203,7 +203,7 @@ context '#file_path' do it 'runs' do - expect(document.file_path 'v001', 'arglebargle.docx').to eq "/document/#{app}/#{doc_id}/v001/arglebargle.docx" + expect(document.file_path('v001', 'arglebargle.docx')).to eq "/document/#{app}/#{doc_id}/v001/arglebargle.docx" end end @@ -256,7 +256,7 @@ context '#save_metadata' do it 'runs' do document.save_metadata - expect(File.exist? document.directory + 'metadata.json').to eq true + expect(File.exist?(document.directory + 'metadata.json')).to eq true # expect this to pass JSON.parse File.read(document.directory + 'metadata.json') end diff --git a/spec/lib/legacy_converter_spec.rb b/spec/lib/legacy_converter_spec.rb index b291950..14ba0b0 100644 --- a/spec/lib/legacy_converter_spec.rb +++ b/spec/lib/legacy_converter_spec.rb @@ -41,7 +41,7 @@ context '#get_file' do it 'runs' do filename = converter.convert_file new_format, content - expect(converter.get_file File.basename(filename)).to eq 'The quick brown fox' + expect(converter.get_file(File.basename(filename))).to eq 'The quick brown fox' end end end diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb index 6324a1c..367861a 100644 --- a/spec/lib/utils_spec.rb +++ b/spec/lib/utils_spec.rb @@ -20,7 +20,7 @@ { 'type' => 'George Cross', reason: 'Bravery' }, ] } - expect(symbolize_keys h).to eq({ + expect(symbolize_keys(h)).to eq({ name: 'Fred', address: { house_number: 12, From 033c64e216f9646fdf25e48413b12ddf4080d02b Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sat, 14 Sep 2024 08:23:47 +0200 Subject: [PATCH 4/4] Fix Layout/ArgumentAlignment offenses --- .rubocop_todo.yml | 7 ------- lib/heathen/executioner.rb | 4 ++-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5e9eed6..5cc2840 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'lib/heathen/executioner.rb' - # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, IndentationWidth. # SupportedStyles: with_first_element, with_fixed_indentation diff --git a/lib/heathen/executioner.rb b/lib/heathen/executioner.rb index 88ebae4..536b4c4 100644 --- a/lib/heathen/executioner.rb +++ b/lib/heathen/executioner.rb @@ -3,7 +3,7 @@ module Heathen # STDOUT and STDERR for perusal. class Executioner attr_reader :logger, :last_exit_status, :last_messages, :last_command, - :stdout, :stderr + :stdout, :stderr def initialize(log) @logger = log @@ -96,7 +96,7 @@ def _execute(*argv, options) command = argv.shift Open3.popen3(ENV, [command, "heathen: #{command}"], *argv, - chdir: options[:dir] || Dir.getwd + chdir: options[:dir] || Dir.getwd ) do |stdin, stdout, stderr, wait_thr| pid = wait_thr[:pid] logger.info "[#{pid}] spawn '#{command} #{argv.join(' ')}'"