diff --git a/.rubocop.yml b/.rubocop.yml index 3f68c13..4244577 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,10 +23,6 @@ Metrics/ClassLength: Metrics/MethodLength: Enabled: false -# As long as methods are readable, this should be fine. -# In any case, this shouldn't be a hard error. We try to improve where sensible -# using tools like RubyCritic instead - # rspec uses long blocks by definition Metrics/BlockLength: Exclude: @@ -64,6 +60,9 @@ Style/DoubleNegation: Style/EmptyMethod: EnforcedStyle: expanded +Style/MultilineMethodCallIndentation: + EnforcedStyle: indented + # Multiline indentation is always tricky. Format it as deemed useful in the # local method, but try to avoid it at all wherever possible Style/MultilineOperationIndentation: diff --git a/lib/rackstash/adapters/adapter.rb b/lib/rackstash/adapters/adapter.rb index f8e5c1a..e15550f 100644 --- a/lib/rackstash/adapters/adapter.rb +++ b/lib/rackstash/adapters/adapter.rb @@ -90,7 +90,7 @@ module Rackstash # @return [void] # @raise NotImplementedHereError def write_single(log) - raise NotImplementedHereError, 'write_single needs to be implemented ' + + raise NotImplementedHereError, 'write_single needs to be implemented ' \ 'in the actual adapter subclass' end diff --git a/lib/rackstash/filters.rb b/lib/rackstash/filters.rb index 076f92b..d484ec4 100644 --- a/lib/rackstash/filters.rb +++ b/lib/rackstash/filters.rb @@ -64,8 +64,8 @@ module Rackstash next unless filter_class.is_a?(Class) filter_class_name = const.to_s - .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') - .gsub(/([a-z\d])([A-Z])/,'\1_\2') + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase .to_sym diff --git a/spec/rackstash/adapters/file_spec.rb b/spec/rackstash/adapters/file_spec.rb index b8100f2..9761bcb 100644 --- a/spec/rackstash/adapters/file_spec.rb +++ b/spec/rackstash/adapters/file_spec.rb @@ -30,7 +30,7 @@ describe Rackstash::Adapters::File do end it 'accepts a Pathname' do - expect(described_class.new(Pathname.new logfile.path).filename) + expect(described_class.new(Pathname.new(logfile.path)).filename) .to eql(logfile.path) .and be_a String end @@ -43,13 +43,13 @@ describe Rackstash::Adapters::File do it 'creates the file and leading directories' do Dir.mktmpdir do |base| - expect(File.exist? File.join(base, 'dir')).to be false + expect(File.exist?(File.join(base, 'dir'))).to be false adapter = described_class.new File.join(base, 'dir', 'sub', 'test.log') expect(adapter.filename).to eql File.join(base, 'dir', 'sub', 'test.log') - expect(File.directory? File.join(base, 'dir')).to be true - expect(File.file? File.join(base, 'dir', 'sub', 'test.log')).to be true + expect(File.directory?(File.join(base, 'dir'))).to be true + expect(File.file?(File.join(base, 'dir', 'sub', 'test.log'))).to be true end end end diff --git a/spec/rackstash/buffer_spec.rb b/spec/rackstash/buffer_spec.rb index 228d462..3f1c4c8 100644 --- a/spec/rackstash/buffer_spec.rb +++ b/spec/rackstash/buffer_spec.rb @@ -400,7 +400,7 @@ describe Rackstash::Buffer do end it 'merges fields and tags as values' do - fields = {foo: :bar} + fields = { foo: :bar } tags = ['default_tag'] expect(buffer.fields).to receive(:deep_merge).with(fields, force: false) @@ -410,8 +410,8 @@ describe Rackstash::Buffer do end it 'merges fields and tags as Procs' do - fields = ->{} - tags = ->{} + fields = -> {} + tags = -> {} expect(buffer.fields).to receive(:deep_merge).with(fields, force: false) expect(buffer.tags).to receive(:merge).with(tags) diff --git a/spec/rackstash/fields/abstract_collection_spec.rb b/spec/rackstash/fields/abstract_collection_spec.rb index 18fd202..523fe9f 100644 --- a/spec/rackstash/fields/abstract_collection_spec.rb +++ b/spec/rackstash/fields/abstract_collection_spec.rb @@ -474,7 +474,7 @@ describe Rackstash::Fields::AbstractCollection do it 'returns the inspected proc on errors' do error = -> { raise 'Oh, no!' } - expected_arguments = ->(arg1, args, arg3) { 'cherio' } + expected_arguments = ->(_arg1, _args, _arg3) { 'cherio' } ok = -> { :ok } outer = -> { [ok, error, expected_arguments] } diff --git a/spec/rackstash/fields/array_spec.rb b/spec/rackstash/fields/array_spec.rb index eaa0659..45ef8a7 100644 --- a/spec/rackstash/fields/array_spec.rb +++ b/spec/rackstash/fields/array_spec.rb @@ -339,7 +339,7 @@ describe Rackstash::Fields::Array do describe '#push' do it 'can append multiple values' do - expect(array.push 'value', 'value2').to equal array + expect(array.push('value', 'value2')).to equal array expect(array[0]).to eql 'value' expect(array[1]).to eql 'value2' end @@ -353,7 +353,7 @@ describe Rackstash::Fields::Array do end it 'can use append as an alias' do - expect(array.append 'foo').to equal array + expect(array.append('foo')).to equal array expect(array[0]).to eql 'foo' end end diff --git a/spec/rackstash/fields/hash_spec.rb b/spec/rackstash/fields/hash_spec.rb index 0dd08ce..bf34b05 100644 --- a/spec/rackstash/fields/hash_spec.rb +++ b/spec/rackstash/fields/hash_spec.rb @@ -24,9 +24,7 @@ describe Rackstash::Fields::Hash do expect(hash.forbidden_keys) .to be_a(Set) .and be_frozen - .and all( - be_frozen.and be_a String - ) + .and all be_frozen.and be_a String end it 'accepts forbidden_keys as a Set' do @@ -36,9 +34,7 @@ describe Rackstash::Fields::Hash do expect(hash.forbidden_keys) .to be_a(Set) .and be_frozen - .and all( - be_frozen.and be_a String - ) + .and all be_frozen.and be_a String # We create a new set without affecting the passed one expect(hash.forbidden_keys).not_to equal forbidden_keys diff --git a/spec/rackstash/filters/skip_event_spec.rb b/spec/rackstash/filters/skip_event_spec.rb index 8528531..d147802 100644 --- a/spec/rackstash/filters/skip_event_spec.rb +++ b/spec/rackstash/filters/skip_event_spec.rb @@ -20,13 +20,13 @@ describe Rackstash::Filters::SkipEvent do end it 'accepts a block' do - expect { described_class.new { } }.not_to raise_error + expect { described_class.new {} }.not_to raise_error end end describe '#call' do it 'returns the event if the condition is falsey' do - event = {'foo' => 'bar'} + event = { 'foo' => 'bar' } expect(described_class.new(->(_event) { false }).call(event)).to equal event expect(described_class.new(->(_event) { nil }).call(event)).to equal event @@ -35,7 +35,7 @@ describe Rackstash::Filters::SkipEvent do end it 'returns false if the condition is truethy' do - event = {'foo' => 'bar'} + event = { 'foo' => 'bar' } expect(described_class.new(->(_event) { true }).call(event)).to be false expect(described_class.new(->(_event) { event }).call(event)).to be false diff --git a/spec/rackstash/flow_spec.rb b/spec/rackstash/flow_spec.rb index 39f1965..8550381 100644 --- a/spec/rackstash/flow_spec.rb +++ b/spec/rackstash/flow_spec.rb @@ -124,7 +124,7 @@ describe Rackstash::Flow do expect { flow.encoder 23 }.to raise_error TypeError expect { flow.encoder true }.to raise_error TypeError expect { flow.encoder false }.to raise_error TypeError - expect { flow.encoder ->{} }.to raise_error TypeError + expect { flow.encoder -> {} }.to raise_error TypeError end end @@ -173,7 +173,7 @@ describe Rackstash::Flow do it 'calls FilterChain#append' do expect(flow.filter_chain).to receive(:append).twice.and_call_original - expect(flow.filter_append ->(event) { event }).to equal flow + expect(flow.filter_append(->(event) { event })).to equal flow expect(flow.filter_append { |event| event }).to equal flow expect(flow.filter_chain.size).to eql 2 @@ -184,7 +184,6 @@ describe Rackstash::Flow do end end - describe '#filter_delete' do before(:each) do flow.filter_chain << ->(event) {} @@ -217,7 +216,7 @@ describe Rackstash::Flow do it 'calls FilterChain#unshift' do expect(flow.filter_chain).to receive(:unshift).twice.and_call_original - expect(flow.filter_unshift ->(event) { event }).to equal flow + expect(flow.filter_unshift(->(event) { event })).to equal flow expect(flow.filter_unshift { |event| event }).to equal flow expect(flow.filter_chain.size).to eql 2 diff --git a/spec/rackstash/logger_spec.rb b/spec/rackstash/logger_spec.rb index e748e48..07d5f12 100644 --- a/spec/rackstash/logger_spec.rb +++ b/spec/rackstash/logger_spec.rb @@ -33,7 +33,7 @@ describe Rackstash::Logger do end it 'allows to set #formatter' do - logger = described_class.new('output.log', formatter: ->{}) + logger = described_class.new('output.log', formatter: -> {}) expect(logger.formatter).to be_a Proc end end @@ -80,7 +80,7 @@ describe Rackstash::Logger do describe '#default_fields=' do it 'forwards to the sink' do - expect(logger.sink).to receive(:default_fields=).with({ 'key' => 'value' }) + expect(logger.sink).to receive(:default_fields=).with('key' => 'value') logger.default_fields = { 'key' => 'value' } end end @@ -421,7 +421,7 @@ describe Rackstash::Logger do expect(buffer).not_to receive(:add_message) - expect(logger.add(0, { foo: 'bar' })).to eql(foo: 'bar') + expect(logger.add(0, foo: 'bar')).to eql(foo: 'bar') end it 'can use debug shortcut' do