1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-10-17 14:01:01 +00:00

Fix a couple of Rubocop warnings

All of these changes are either simple formatting changes or clarify
existing meaning. None of these changes affects externally visible
behavior.
This commit is contained in:
Holger Just 2017-10-20 19:51:07 +02:00
parent 126e510edc
commit 8db2c917c2
12 changed files with 61 additions and 60 deletions

View File

@ -1,6 +1,20 @@
AllCops:
TargetRubyVersion: 2.1
# We use a different style where we add the short license header just below the
# magic comments separated by an empty comment line. Unfortunately, this cop
# clashes with our style
Layout/EmptyLineAfterMagicComment:
Enabled: false
Layout/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
Layout/MultilineOperationIndentation:
Enabled: false
# Sometimes we want to capture all exceptions. We need to make sure to re-raise
# these again in any case.
Lint/RescueException:
@ -60,14 +74,6 @@ 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:
Enabled: false
Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%w': '[]'

View File

@ -10,9 +10,5 @@ source 'https://rubygems.org'
gemspec name: 'rackstash'
group :test do
if ENV['RACK_VERSION']
gem 'rack', "~> #{ENV['RACK_VERSION']}"
else
gem 'rack'
end
gem 'rack', ENV['RACK_VERSION'] ? "~> #{ENV['RACK_VERSION']}" : nil
end

View File

@ -92,16 +92,17 @@ module Rackstash
def initialize(flows, buffering: :full, allow_silent: true)
@flows = flows
@buffering = case buffering
when :full, true
:full
when :data
:data
when :none, false
:none
else
raise TypeError, "Unknown buffering argument given: #{buffering.inspect}"
end
@buffering =
case buffering
when :full, true
:full
when :data
:data
when :none, false
:none
else
raise TypeError, "Unknown buffering argument given: #{buffering.inspect}"
end
@allow_silent = !!allow_silent

View File

@ -75,7 +75,6 @@ module Rackstash
@filters[id] = filter
end
filter
end
# Adds a new filter at the end of the filter chain. You can either give a

View File

@ -328,7 +328,6 @@ module Rackstash
(clock_time - began_at).round(ISO8601_PRECISION)
}
end
end
end
end

View File

@ -24,7 +24,7 @@ describe Rackstash::Buffer do
it 'adds the exception fields' do
begin
raise 'My Error'
rescue => e
rescue RuntimeError => e
buffer.add_exception(e)
end
@ -45,13 +45,13 @@ describe Rackstash::Buffer do
it 'overwrites exceptions' do
begin
raise 'Error'
rescue => first
rescue RuntimeError => first
buffer.add_exception(first, force: true)
end
begin
raise TypeError, 'Another Error'
rescue => second
rescue TypeError => second
buffer.add_exception(second, force: true)
end
@ -67,7 +67,7 @@ describe Rackstash::Buffer do
begin
raise TypeError, 'Error'
rescue => second
rescue TypeError => second
buffer.add_exception(second, force: false)
end

View File

@ -14,7 +14,7 @@ describe Rackstash::Encoders::Hash do
describe '#encode' do
it 'normalized the message' do
event = { 'message' => ["hello\n", "world\n", "foo", "bar"] }
event = { 'message' => ["hello\n", "world\n", 'foo', 'bar'] }
expect(encoder.encode(event)).to eql 'message' => "hello\nworld\nfoobar"
end
@ -22,12 +22,14 @@ describe Rackstash::Encoders::Hash do
time = Time.now
event = { 'message' => ['foo', 'bar'], '@timestamp' => time }
expect(encoder.encode(event)).to eql 'message' => 'foobar', '@timestamp' => time.getutc.iso8601(6)
expect(encoder.encode(event))
.to eql 'message' => 'foobar', '@timestamp' => time.getutc.iso8601(6)
end
it 'passes the normalized event hash through' do
event = { 'foo' => 'bar', 'baz' => :boing }
expect(encoder.encode(event)).to eql 'foo' => 'bar', 'baz' => :boing, 'message' => ''
expect(encoder.encode(event))
.to eql 'foo' => 'bar', 'baz' => :boing, 'message' => ''
end
end
end

View File

@ -53,7 +53,6 @@ describe Rackstash::Encoders::Message do
event = { 'message' => ["\n"], 'tags' => ['foo', 'bar'] }
expect(encoder.encode(event)).to eql "[foo,bar] \n"
end
end
end
end

View File

@ -279,7 +279,6 @@ describe Rackstash::Fields::AbstractCollection do
expect(normalize(hash, scope: scope)['beep']['SCOPE']).to eql 'scope'
end
end
end
describe 'with Array' do
@ -470,10 +469,10 @@ describe Rackstash::Fields::AbstractCollection do
exception = e
end
checker = Regexp.new <<-EOF.gsub(/^\s+/, '').rstrip, Regexp::MULTILINE
checker = Regexp.new <<-REGEXP.gsub(/^\s+/, '').rstrip, Regexp::MULTILINE
\\AAn Error \\(StandardError\\)
#{Regexp.escape __FILE__}:#{__LINE__ - 7}:in `block .*`
EOF
REGEXP
expect(normalize(exception)).to match checker
expect(normalize(exception).encoding).to eql Encoding::UTF_8
expect(normalize(exception)).to be_frozen
@ -506,17 +505,17 @@ describe Rackstash::Fields::AbstractCollection do
it 'stops on error and raises' do
called = Hash.new(false)
ok = -> {
ok = lambda {
called[:ok] = true
:ok
}
error = -> {
error = lambda {
called[:error] = true
raise 'Oh, no!'
}
ignored = ->() {
ignored = lambda {
called[:ignored] = true
'cherio'
}

View File

@ -24,44 +24,44 @@ describe Rackstash::Filters::DefaultFields do
it 'adds missing normalized fields' do
filter! 'new' => 'boing', 123 => :number
expect(event).to eql({
expect(event).to eql(
'foo' => 'v1',
'bar' => 'v2',
'new' => 'boing',
'123' => 'number'
})
)
end
it 'retains existing fields' do
filter! foo: 'ignored'
expect(event).to eql({
expect(event).to eql(
'foo' => 'v1',
'bar' => 'v2'
})
)
end
it 'deep_merges fields' do
event['deep'] = { 'key' => [42, { 'foo' => 'bar' }, nil], 'new' => nil }
filter! 'deep' => { key: [123], new: 'new' }
expect(event).to eql({
expect(event).to eql(
'foo' => 'v1',
'bar' => 'v2',
'deep' => {
'key' => [42, { 'foo' => 'bar' }, nil, 123],
'new' => 'new'
}
})
)
end
it 'resolves Procs' do
filter! -> { { 'beep' => -> { 'boop' } } }
expect(event).to eql({
expect(event).to eql(
'foo' => 'v1',
'bar' => 'v2',
'beep' => 'boop'
})
)
end
end

View File

@ -35,14 +35,14 @@ describe Rackstash::Formatter do
exception = nil
begin
raise StandardError, 'An Error'
rescue => e
rescue StandardError => e
exception = e
end
checker = Regexp.new <<-EOF.gsub(/^\s+/, '').rstrip, Regexp::MULTILINE
checker = Regexp.new <<-REGEXP.gsub(/^\s+/, '').rstrip, Regexp::MULTILINE
\\AAn Error \\(StandardError\\)
#{Regexp.escape __FILE__}:#{__LINE__ - 7}:in `block .*`
EOF
REGEXP
expect(formatter.call('ERROR', Time.now, 'progname', exception))
.to match(checker)
.and be_frozen

View File

@ -21,9 +21,9 @@ describe Rackstash::Rack::Middleware do
# Raise a RuntimeError if a raise parameter was set in the request
request = ::Rack::Request.new(env)
raise RuntimeError, request.params['raise'] if request.params['raise']
raise request.params['raise'] if request.params['raise']
[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
[200, { 'Content-Type' => 'text/plain' }, ['Hello, World!']]
}
}
@ -31,7 +31,7 @@ describe Rackstash::Rack::Middleware do
let(:logger) { Rackstash::Logger.new ->(event) { log << event } }
let(:args) { {} }
let(:stack) { described_class.new(app, logger, **args)}
let(:stack) { described_class.new(app, logger, **args) }
def get(path, opts = {})
::Rack::MockRequest.new(::Rack::Lint.new(stack)).get(path, opts)
@ -73,7 +73,7 @@ describe Rackstash::Rack::Middleware do
app = lambda do |env|
called = true
expect(env['rack.logger']).to equal logger
[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
[200, { 'Content-Type' => 'text/plain' }, ['Hello, World!']]
end
::Rack::MockRequest.new(described_class.new(app, logger)).get('/')
@ -85,7 +85,7 @@ describe Rackstash::Rack::Middleware do
app = lambda do |env|
called = true
expect(env['rackstash.logger']).to equal logger
[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
[200, { 'Content-Type' => 'text/plain' }, ['Hello, World!']]
end
::Rack::MockRequest.new(described_class.new(app, logger)).get('/')
@ -95,7 +95,7 @@ describe Rackstash::Rack::Middleware do
it 'logs basic request data' do
get('/demo')
expect(log.last).to match({
expect(log.last).to match(
'method' => 'GET',
'path' => '/demo',
'status' => 200,
@ -105,7 +105,7 @@ describe Rackstash::Rack::Middleware do
'@timestamp' => /\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{6}Z/,
'tags' => []
})
)
end
context 'with request_fields' do
@ -181,7 +181,7 @@ describe Rackstash::Rack::Middleware do
expect(log.last).to include(
'error' => 'RuntimeError',
'error_message' => 'Oh noes!',
'error_trace' => %r{\A#{__FILE__}:24:in},
'error_trace' => %r{\A#{__FILE__}:24:in}
)
end
@ -199,7 +199,7 @@ describe Rackstash::Rack::Middleware do
end
it 'handles errors on setting request_fields' do
args[:request_fields] = -> {
args[:request_fields] = lambda {
{
'foo' => 'bar',
'error' => -> { raise 'kaputt' }
@ -222,7 +222,7 @@ describe Rackstash::Rack::Middleware do
end
it 'handles errors on setting response_fields' do
args[:response_fields] = -> {
args[:response_fields] = lambda {
{
'foo' => 'bar',
'error' => -> { raise 'kaputt' }