From f8269a0d9a7c55146e1002311e40d8567912728a Mon Sep 17 00:00:00 2001 From: Ivy Evans Date: Tue, 16 Nov 2021 02:50:16 +0000 Subject: [PATCH] Fix rubocop 1.23.0 violations These fixes were automatically made with: rubocop --auto-correct-all --- Gemfile | 2 ++ Rakefile | 4 ++- gemfiles/actionpack4.0.gemfile | 2 ++ gemfiles/actionpack5.0.gemfile | 4 ++- gemfiles/actionpack5.1.gemfile | 4 ++- gemfiles/actionpack5.2.gemfile | 4 ++- lib/lograge.rb | 10 +++---- lib/lograge/formatters/cee.rb | 2 ++ lib/lograge/formatters/graylog2.rb | 4 ++- .../formatters/helpers/method_and_path.rb | 2 ++ lib/lograge/formatters/json.rb | 2 ++ lib/lograge/formatters/key_value.rb | 2 ++ lib/lograge/formatters/l2met.rb | 30 ++++++++++--------- lib/lograge/formatters/lines.rb | 2 ++ lib/lograge/formatters/logstash.rb | 2 ++ lib/lograge/formatters/ltsv.rb | 2 ++ lib/lograge/formatters/raw.rb | 2 ++ lib/lograge/log_subscribers/action_cable.rb | 4 ++- .../log_subscribers/action_controller.rb | 2 ++ lib/lograge/log_subscribers/base.rb | 6 ++-- lib/lograge/ordered_options.rb | 2 ++ .../rails_ext/action_cable/channel/base.rb | 2 ++ .../rails_ext/action_cable/connection/base.rb | 24 +++++++-------- .../rails_ext/action_cable/server/base.rb | 2 ++ lib/lograge/rails_ext/rack/logger.rb | 5 ++-- lib/lograge/railtie.rb | 2 ++ lib/lograge/silent_logger.rb | 8 ++--- lib/lograge/version.rb | 4 ++- lograge.gemspec | 4 ++- spec/formatters/cee_spec.rb | 2 ++ spec/formatters/graylog2_spec.rb | 2 ++ .../helpers/method_and_path_spec.rb | 2 ++ spec/formatters/json_spec.rb | 2 ++ spec/formatters/key_value_spec.rb | 2 ++ spec/formatters/l2met_spec.rb | 2 ++ spec/formatters/lines_spec.rb | 2 ++ spec/formatters/logstash_spec.rb | 2 ++ spec/formatters/ltsv_spec.rb | 2 ++ spec/formatters/raw_spec.rb | 2 ++ spec/log_subscribers/action_cable_spec.rb | 16 +++++----- .../log_subscribers/action_controller_spec.rb | 20 +++++++------ spec/lograge_spec.rb | 2 ++ spec/silent_logger_spec.rb | 6 ++-- spec/spec_helper.rb | 2 ++ spec/support/examples.rb | 2 ++ tools/console | 1 + 46 files changed, 147 insertions(+), 67 deletions(-) diff --git a/Gemfile b/Gemfile index 1dae4070..959ca7f1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in lograge.gemspec diff --git a/Rakefile b/Rakefile index 7c9a8e8a..52780bb8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rspec/core/rake_task' @@ -7,6 +9,6 @@ require 'rubocop/rake_task' RuboCop::RakeTask.new desc 'Run specs, rubocop and reek' -task ci: %w(spec rubocop) +task ci: %w[spec rubocop] task default: :ci diff --git a/gemfiles/actionpack4.0.gemfile b/gemfiles/actionpack4.0.gemfile index f27cc0ab..905ad100 100644 --- a/gemfiles/actionpack4.0.gemfile +++ b/gemfiles/actionpack4.0.gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in lograge.gemspec diff --git a/gemfiles/actionpack5.0.gemfile b/gemfiles/actionpack5.0.gemfile index d156949d..757824e4 100644 --- a/gemfiles/actionpack5.0.gemfile +++ b/gemfiles/actionpack5.0.gemfile @@ -1,11 +1,13 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in lograge.gemspec gemspec path: '..' group :test do - gem 'activerecord', '~> 5.0.0' gem 'actionpack', '~> 5.0.0' + gem 'activerecord', '~> 5.0.0' # logstash does not release any gems on rubygems, but they have two gemspecs within their repo. # Using the tag is an attempt of having a stable version to test against where we can ensure that diff --git a/gemfiles/actionpack5.1.gemfile b/gemfiles/actionpack5.1.gemfile index 4f22c452..001a931e 100644 --- a/gemfiles/actionpack5.1.gemfile +++ b/gemfiles/actionpack5.1.gemfile @@ -1,11 +1,13 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in lograge.gemspec gemspec path: '..' group :test do - gem 'activerecord', '~> 5.1.0' gem 'actionpack', '~> 5.1.0' + gem 'activerecord', '~> 5.1.0' # logstash does not release any gems on rubygems, but they have two gemspecs within their repo. # Using the tag is an attempt of having a stable version to test against where we can ensure that diff --git a/gemfiles/actionpack5.2.gemfile b/gemfiles/actionpack5.2.gemfile index 806759cd..2f9193ec 100644 --- a/gemfiles/actionpack5.2.gemfile +++ b/gemfiles/actionpack5.2.gemfile @@ -1,11 +1,13 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in lograge.gemspec gemspec path: '..' group :test do - gem 'activerecord', '~> 5.2.0' gem 'actionpack', '~> 5.2.0' + gem 'activerecord', '~> 5.2.0' # logstash does not release any gems on rubygems, but they have two gemspecs within their repo. # Using the tag is an attempt of having a stable version to test against where we can ensure that diff --git a/lib/lograge.rb b/lib/lograge.rb index bde44f4f..9f60ba1b 100644 --- a/lib/lograge.rb +++ b/lib/lograge.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'lograge/version' require 'lograge/formatters/helpers/method_and_path' require 'lograge/formatters/cee' @@ -17,7 +19,7 @@ require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/string/inflections' -# rubocop:disable ModuleLength +# rubocop:disable Metrics/ModuleLength module Lograge module_function @@ -117,9 +119,7 @@ def unsubscribe(component, subscriber) events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' } events.each do |event| ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener| - if listener.instance_variable_get('@delegate') == subscriber - ActiveSupport::Notifications.unsubscribe listener - end + ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate') == subscriber end end end @@ -203,7 +203,7 @@ def keep_original_rails_log end def rack_cache_hashlike?(app) - app.config.action_dispatch.rack_cache && app.config.action_dispatch.rack_cache.respond_to?(:[]=) + app.config.action_dispatch.rack_cache&.respond_to?(:[]=) end private_class_method :rack_cache_hashlike? diff --git a/lib/lograge/formatters/cee.rb b/lib/lograge/formatters/cee.rb index 921c4ab9..782f19e3 100644 --- a/lib/lograge/formatters/cee.rb +++ b/lib/lograge/formatters/cee.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters class Cee diff --git a/lib/lograge/formatters/graylog2.rb b/lib/lograge/formatters/graylog2.rb index 341ce4e5..ce96ef54 100644 --- a/lib/lograge/formatters/graylog2.rb +++ b/lib/lograge/formatters/graylog2.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters class Graylog2 @@ -12,7 +14,7 @@ def call(data) } # Add underscore to every key to follow GELF additional field syntax. - data_clone.keys.each do |key| + data_clone.each_key do |key| data_clone[underscore_prefix(key)] = data_clone[key] data_clone.delete(key) end diff --git a/lib/lograge/formatters/helpers/method_and_path.rb b/lib/lograge/formatters/helpers/method_and_path.rb index 23a1f709..4167be5b 100644 --- a/lib/lograge/formatters/helpers/method_and_path.rb +++ b/lib/lograge/formatters/helpers/method_and_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters module Helpers diff --git a/lib/lograge/formatters/json.rb b/lib/lograge/formatters/json.rb index e1b5c636..f8f7aea2 100644 --- a/lib/lograge/formatters/json.rb +++ b/lib/lograge/formatters/json.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' module Lograge module Formatters diff --git a/lib/lograge/formatters/key_value.rb b/lib/lograge/formatters/key_value.rb index 42581b27..73bf013f 100644 --- a/lib/lograge/formatters/key_value.rb +++ b/lib/lograge/formatters/key_value.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters class KeyValue diff --git a/lib/lograge/formatters/l2met.rb b/lib/lograge/formatters/l2met.rb index 24201d6e..b15d60ff 100644 --- a/lib/lograge/formatters/l2met.rb +++ b/lib/lograge/formatters/l2met.rb @@ -1,24 +1,26 @@ +# frozen_string_literal: true + require 'lograge/formatters/key_value' module Lograge module Formatters class L2met < KeyValue - L2MET_FIELDS = [ - :method, - :path, - :format, - :source, - :status, - :error, - :duration, - :view, - :db, - :location + L2MET_FIELDS = %i[ + method + path + format + source + status + error + duration + view + db + location ].freeze - UNWANTED_FIELDS = [ - :controller, - :action + UNWANTED_FIELDS = %i[ + controller + action ].freeze def call(data) diff --git a/lib/lograge/formatters/lines.rb b/lib/lograge/formatters/lines.rb index 1664af66..95048c20 100644 --- a/lib/lograge/formatters/lines.rb +++ b/lib/lograge/formatters/lines.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters class Lines diff --git a/lib/lograge/formatters/logstash.rb b/lib/lograge/formatters/logstash.rb index 2c3702ed..09a65d12 100644 --- a/lib/lograge/formatters/logstash.rb +++ b/lib/lograge/formatters/logstash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters class Logstash diff --git a/lib/lograge/formatters/ltsv.rb b/lib/lograge/formatters/ltsv.rb index d2fddeed..fc393c13 100644 --- a/lib/lograge/formatters/ltsv.rb +++ b/lib/lograge/formatters/ltsv.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters class LTSV diff --git a/lib/lograge/formatters/raw.rb b/lib/lograge/formatters/raw.rb index aae9f6e4..79b97628 100644 --- a/lib/lograge/formatters/raw.rb +++ b/lib/lograge/formatters/raw.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module Formatters class Raw diff --git a/lib/lograge/log_subscribers/action_cable.rb b/lib/lograge/log_subscribers/action_cable.rb index ebf105f3..73d2649a 100644 --- a/lib/lograge/log_subscribers/action_cable.rb +++ b/lib/lograge/log_subscribers/action_cable.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module Lograge module LogSubscribers class ActionCable < Base - %i(perform_action subscribe unsubscribe connect disconnect).each do |method_name| + %i[perform_action subscribe unsubscribe connect disconnect].each do |method_name| define_method(method_name) do |event| process_main_event(event) end diff --git a/lib/lograge/log_subscribers/action_controller.rb b/lib/lograge/log_subscribers/action_controller.rb index 007239bc..5afde029 100644 --- a/lib/lograge/log_subscribers/action_controller.rb +++ b/lib/lograge/log_subscribers/action_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge module LogSubscribers class ActionController < Base diff --git a/lib/lograge/log_subscribers/base.rb b/lib/lograge/log_subscribers/base.rb index ae62623a..0a7bbff0 100644 --- a/lib/lograge/log_subscribers/base.rb +++ b/lib/lograge/log_subscribers/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'action_pack' require 'active_support/core_ext/class/attribute' @@ -32,8 +34,8 @@ def extract_request(event, payload) data.merge!(custom_options(event)) end - %i(initial_data extract_status extract_runtimes - extract_location extract_unpermitted_params).each do |method_name| + %i[initial_data extract_status extract_runtimes + extract_location extract_unpermitted_params].each do |method_name| define_method(method_name) { |*_arg| {} } end diff --git a/lib/lograge/ordered_options.rb b/lib/lograge/ordered_options.rb index c316ebe4..e15bb3be 100644 --- a/lib/lograge/ordered_options.rb +++ b/lib/lograge/ordered_options.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/ordered_options' module Lograge diff --git a/lib/lograge/rails_ext/action_cable/channel/base.rb b/lib/lograge/rails_ext/action_cable/channel/base.rb index 31286629..1387d023 100644 --- a/lib/lograge/rails_ext/action_cable/channel/base.rb +++ b/lib/lograge/rails_ext/action_cable/channel/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ActionCable module Channel class Base diff --git a/lib/lograge/rails_ext/action_cable/connection/base.rb b/lib/lograge/rails_ext/action_cable/connection/base.rb index 8f7c512f..253cf07b 100644 --- a/lib/lograge/rails_ext/action_cable/connection/base.rb +++ b/lib/lograge/rails_ext/action_cable/connection/base.rb @@ -1,23 +1,21 @@ +# frozen_string_literal: true + module ActionCable module Connection class Base - # rubocop:disable Metrics/MethodLength def handle_open ActiveSupport::Notifications.instrument('connect.action_cable', notification_payload('connect')) do - begin - @protocol = websocket.protocol - connect if respond_to?(:connect) - subscribe_to_internal_channel - send_welcome_message - - message_buffer.process! - server.add_connection(self) - rescue ActionCable::Connection::Authorization::UnauthorizedError - respond_to_invalid_request - end + @protocol = websocket.protocol + connect if respond_to?(:connect) + subscribe_to_internal_channel + send_welcome_message + + message_buffer.process! + server.add_connection(self) + rescue ActionCable::Connection::Authorization::UnauthorizedError + respond_to_invalid_request end end - # rubocop:enable Metrics/MethodLength def handle_close ActiveSupport::Notifications.instrument('disconnect.action_cable', notification_payload('disconnect')) do diff --git a/lib/lograge/rails_ext/action_cable/server/base.rb b/lib/lograge/rails_ext/action_cable/server/base.rb index b206b695..3264372a 100644 --- a/lib/lograge/rails_ext/action_cable/server/base.rb +++ b/lib/lograge/rails_ext/action_cable/server/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ActionCable module Server class Base diff --git a/lib/lograge/rails_ext/rack/logger.rb b/lib/lograge/rails_ext/rack/logger.rb index b697f427..f0cf3ab7 100644 --- a/lib/lograge/rails_ext/rack/logger.rb +++ b/lib/lograge/rails_ext/rack/logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/concern' require 'rails/rack/logger' @@ -18,8 +20,7 @@ def call_app(*args) end # Overwrites Rails 3.0/3.1 code that logs new requests - def before_dispatch(_env) - end + def before_dispatch(_env); end end end end diff --git a/lib/lograge/railtie.rb b/lib/lograge/railtie.rb index 5856f5e5..69cf5f98 100644 --- a/lib/lograge/railtie.rb +++ b/lib/lograge/railtie.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails/railtie' require 'action_view/log_subscriber' require 'action_controller/log_subscriber' diff --git a/lib/lograge/silent_logger.rb b/lib/lograge/silent_logger.rb index 6a7e241a..41b1243d 100644 --- a/lib/lograge/silent_logger.rb +++ b/lib/lograge/silent_logger.rb @@ -1,12 +1,10 @@ +# frozen_string_literal: true + require 'delegate' module Lograge class SilentLogger < SimpleDelegator - def initialize(logger) - super - end - - %i(debug info warn error fatal unknown).each do |method_name| + %i[debug info warn error fatal unknown].each do |method_name| define_method(method_name) { |*_args| } end end diff --git a/lib/lograge/version.rb b/lib/lograge/version.rb index 2c94b93b..405aa6c6 100644 --- a/lib/lograge/version.rb +++ b/lib/lograge/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Lograge - VERSION = '0.11.2'.freeze + VERSION = '0.11.2' end diff --git a/lograge.gemspec b/lograge.gemspec index f6df2c04..963bd13d 100644 --- a/lograge.gemspec +++ b/lograge.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require './lib/lograge/version' Gem::Specification.new do |s| @@ -15,8 +17,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '~> 3.1' s.add_development_dependency 'rubocop', '~> 1.23' - s.add_runtime_dependency 'activesupport', '>= 4' s.add_runtime_dependency 'actionpack', '>= 4' + s.add_runtime_dependency 'activesupport', '>= 4' s.add_runtime_dependency 'railties', '>= 4' s.add_runtime_dependency 'request_store', '~> 1.0' end diff --git a/spec/formatters/cee_spec.rb b/spec/formatters/cee_spec.rb index a1b744aa..1dc7760f 100644 --- a/spec/formatters/cee_spec.rb +++ b/spec/formatters/cee_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::Cee do it 'prepends the output with @cee' do expect(subject.call({})).to match(/^@cee/) diff --git a/spec/formatters/graylog2_spec.rb b/spec/formatters/graylog2_spec.rb index 06d4044c..56cc7cf4 100644 --- a/spec/formatters/graylog2_spec.rb +++ b/spec/formatters/graylog2_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::Graylog2 do let(:payload) do { diff --git a/spec/formatters/helpers/method_and_path_spec.rb b/spec/formatters/helpers/method_and_path_spec.rb index b5d38590..8f048c45 100644 --- a/spec/formatters/helpers/method_and_path_spec.rb +++ b/spec/formatters/helpers/method_and_path_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::Helpers::MethodAndPath do describe '#method_and_path_string' do let(:instance) do diff --git a/spec/formatters/json_spec.rb b/spec/formatters/json_spec.rb index 9cd5781e..2af8b471 100644 --- a/spec/formatters/json_spec.rb +++ b/spec/formatters/json_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::Json do let(:deserialized_output) { JSON.parse(subject.call(custom: 'data')) } diff --git a/spec/formatters/key_value_spec.rb b/spec/formatters/key_value_spec.rb index 3378c2e0..ee8140ab 100644 --- a/spec/formatters/key_value_spec.rb +++ b/spec/formatters/key_value_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::KeyValue do let(:payload) do { diff --git a/spec/formatters/l2met_spec.rb b/spec/formatters/l2met_spec.rb index 354897dc..0924b0e8 100644 --- a/spec/formatters/l2met_spec.rb +++ b/spec/formatters/l2met_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::L2met do let(:payload) do { diff --git a/spec/formatters/lines_spec.rb b/spec/formatters/lines_spec.rb index 47f0318d..670d2b68 100644 --- a/spec/formatters/lines_spec.rb +++ b/spec/formatters/lines_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::Lines do it 'can serialize custom data' do expect(subject.call(custom: 'data')).to eq('custom=data') diff --git a/spec/formatters/logstash_spec.rb b/spec/formatters/logstash_spec.rb index 73434682..9df435e7 100644 --- a/spec/formatters/logstash_spec.rb +++ b/spec/formatters/logstash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::Logstash do let(:payload) do { diff --git a/spec/formatters/ltsv_spec.rb b/spec/formatters/ltsv_spec.rb index 13850a48..e7d9fd45 100644 --- a/spec/formatters/ltsv_spec.rb +++ b/spec/formatters/ltsv_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::LTSV do let(:payload) do { diff --git a/spec/formatters/raw_spec.rb b/spec/formatters/raw_spec.rb index 56fcf929..ab54bf1e 100644 --- a/spec/formatters/raw_spec.rb +++ b/spec/formatters/raw_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Lograge::Formatters::Raw do it 'serializes custom attributes' do expect(subject.call(custom: 'data')).to eq(custom: 'data') diff --git a/spec/log_subscribers/action_cable_spec.rb b/spec/log_subscribers/action_cable_spec.rb index aa2ad34f..06081df0 100644 --- a/spec/log_subscribers/action_cable_spec.rb +++ b/spec/log_subscribers/action_cable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'lograge/log_subscribers/action_controller' require 'active_support/notifications' require 'active_support/core_ext/string' @@ -47,7 +49,7 @@ end it 'works when the method returns nil' do - Lograge.custom_options = ->(_event) { nil } + Lograge.custom_options = ->(_event) {} subscriber.perform_action(event) expect(log_output.string).to be_present @@ -66,7 +68,7 @@ it 'includes the duration' do subscriber.perform_action(event) - expect(log_output.string).to match(/duration=[\.0-9]{2,4}/) + expect(log_output.string).to match(/duration=[.0-9]{2,4}/) end context 'when an `ActiveRecord::RecordNotFound` is raised' do @@ -118,7 +120,7 @@ expect(log_output.string).to match(/ data=value/) end it 'works when the method returns nil' do - Lograge.custom_options = ->(_event) { nil } + Lograge.custom_options = ->(_event) {} subscriber.perform_action(event) expect(log_output.string).to be_present @@ -160,7 +162,7 @@ expect(log_output.string).to include('status=200') end it 'works if the method returns nil' do - Lograge.before_format = ->(_data, _payload) { nil } + Lograge.before_format = ->(_data, _payload) {} subscriber.perform_action(event) expect(log_output.string).to be_present @@ -205,14 +207,14 @@ end it 'does not log ignored events' do - Lograge.ignore(->(event) { 'pong' == event.payload[:action] }) + Lograge.ignore(->(event) { event.payload[:action] == 'pong' }) subscriber.perform_action(event) expect(log_output.string).to be_blank end it 'logs non-ignored events' do - Lograge.ignore(->(event) { 'foo' == event.payload[:action] }) + Lograge.ignore(->(event) { event.payload[:action] == 'foo' }) subscriber.perform_action(event) expect(log_output.string).not_to be_blank @@ -232,7 +234,7 @@ end describe 'other actions' do - %i(subscribe unsubscribe connect disconnect).each do |action_name| + %i[subscribe unsubscribe connect disconnect].each do |action_name| let(:event) do ActiveSupport::Notifications::Event.new( "#{action_name}.action_cable", diff --git a/spec/log_subscribers/action_controller_spec.rb b/spec/log_subscribers/action_controller_spec.rb index ea06d300..d47f22e6 100644 --- a/spec/log_subscribers/action_controller_spec.rb +++ b/spec/log_subscribers/action_controller_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'lograge/log_subscribers/action_controller' require 'active_support/notifications' require 'active_support/core_ext/string' @@ -53,7 +55,7 @@ end it 'works when the method returns nil' do - Lograge.custom_options = ->(_event) { nil } + Lograge.custom_options = ->(_event) {} subscriber.process_action(event) expect(log_output.string).to be_present @@ -85,13 +87,13 @@ Time.now, Time.now, 1, - keys: %w(foo bar) + keys: %w[foo bar] ) end it 'stores the parameters in a thread local variable' do subscriber.unpermitted_parameters(unpermitted_parameters_event) - expect(RequestStore.store[:lograge_unpermitted_params]).to eq(%w(foo bar)) + expect(RequestStore.store[:lograge_unpermitted_params]).to eq(%w[foo bar]) end end @@ -127,7 +129,7 @@ it 'includes the duration' do subscriber.process_action(event) - expect(log_output.string).to match(/duration=[\.0-9]{4,4} /) + expect(log_output.string).to match(/duration=[.0-9]{4,4} /) end it 'includes the view rendering time' do @@ -188,7 +190,7 @@ context 'with unpermitted_parameters' do before do - RequestStore.store[:lograge_unpermitted_params] = %w(florb blarf) + RequestStore.store[:lograge_unpermitted_params] = %w[florb blarf] end it 'adds the unpermitted_params to the log line' do @@ -226,7 +228,7 @@ expect(log_output.string).to match(/ data=value/) end it 'works when the method returns nil' do - Lograge.custom_options = ->(_event) { nil } + Lograge.custom_options = ->(_event) {} subscriber.process_action(event) expect(log_output.string).to be_present @@ -268,7 +270,7 @@ expect(log_output.string).to include('status=200') end it 'works if the method returns nil' do - Lograge.before_format = ->(_data, _payload) { nil } + Lograge.before_format = ->(_data, _payload) {} subscriber.process_action(event) expect(log_output.string).to be_present @@ -313,14 +315,14 @@ end it 'does not log ignored events' do - Lograge.ignore(->(event) { 'GET' == event.payload[:method] }) + Lograge.ignore(->(event) { event.payload[:method] == 'GET' }) subscriber.process_action(event) expect(log_output.string).to be_blank end it 'logs non-ignored events' do - Lograge.ignore(->(event) { 'foo' == event.payload[:method] }) + Lograge.ignore(->(event) { event.payload[:method] == 'foo' }) subscriber.process_action(event) expect(log_output.string).not_to be_blank diff --git a/spec/lograge_spec.rb b/spec/lograge_spec.rb index ce3afeb5..27ddf003 100644 --- a/spec/lograge_spec.rb +++ b/spec/lograge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/notifications' require 'active_support/core_ext/string' require 'active_support/deprecation' diff --git a/spec/silent_logger_spec.rb b/spec/silent_logger_spec.rb index 1aac31c4..f45b6947 100644 --- a/spec/silent_logger_spec.rb +++ b/spec/silent_logger_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'logger' describe Lograge::SilentLogger do - let(:base_logger) { Logger.new(STDOUT) } + let(:base_logger) { Logger.new($stdout) } subject(:silent_logger) { described_class.new(base_logger) } it "doesn't call base logger on either log method" do - %i(debug info warn error fatal unknown).each do |method_name| + %i[debug info warn error fatal unknown].each do |method_name| expect(base_logger).not_to receive(method_name) silent_logger.public_send(method_name) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ceb0e394..aedaa89f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # Require this file using `require "spec_helper.rb"` to ensure that it is only diff --git a/spec/support/examples.rb b/spec/support/examples.rb index ad008327..7507c997 100644 --- a/spec/support/examples.rb +++ b/spec/support/examples.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_examples_for 'a key value formatter' do let(:payload) do { diff --git a/tools/console b/tools/console index cf90aa5d..06b1831f 100755 --- a/tools/console +++ b/tools/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'pathname'