diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5f1dde..fa98800 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,13 +86,15 @@ jobs: gemfile: gemfiles/rails_8.1.gemfile - ruby: "3.1" gemfile: gemfiles/rails_8.1.gemfile - # NOTE: Rails edge requires Ruby version >= 3.2 + # NOTE: Rails edge requires Ruby version >= 3.3.1 - ruby: "2.7" gemfile: gemfiles/rails_edge.gemfile - ruby: "3.0" gemfile: gemfiles/rails_edge.gemfile - ruby: "3.1" gemfile: gemfiles/rails_edge.gemfile + - ruby: "3.2" + gemfile: gemfiles/rails_edge.gemfile env: @@ -106,5 +108,20 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle exec rake + # Specs only. Linting is handled once by the `lint` job below: RuboCop + # resolves to a different version on each Ruby, so running it across the + # matrix makes lint results depend on the leg rather than on the code. + - run: bundle exec rake spec + + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.4" + bundler-cache: true + - run: bundle exec rubocop diff --git a/.rubocop.yml b/.rubocop.yml index 265ef77..1b59e00 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,13 +12,28 @@ Lint/AmbiguousBlockAssociation: Exclude: - spec/**/*_spec.rb +# The no-op logger methods are intentionally empty. Configured here rather than +# with an inline directive so the suppression is understood by every RuboCop +# version in the CI matrix. +Lint/EmptyBlock: + Exclude: + - lib/lograge/silent_logger.rb + Metrics/AbcSize: Enabled: false +# RuboCop excludes gemspecs from this cop by default, but a local Exclude +# replaces the default list rather than extending it, so restate it here. Metrics/BlockLength: Exclude: + - '**/*.gemspec' - spec/**/*_spec.rb +# Lograge's public API lives in a single module. See the note on Lint/EmptyBlock. +Metrics/ModuleLength: + Exclude: + - lib/lograge.rb + Style/BlockDelimiters: Enabled: false diff --git a/lib/lograge.rb b/lib/lograge.rb index 7e31653..0607942 100644 --- a/lib/lograge.rb +++ b/lib/lograge.rb @@ -22,7 +22,6 @@ require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/string/inflections' -# rubocop:disable Metrics/ModuleLength module Lograge module_function @@ -241,6 +240,5 @@ def notification_listeners_for(name) end end end -# rubocop:enable Metrics/ModuleLength require 'lograge/railtie' if defined?(Rails) diff --git a/lib/lograge/silent_logger.rb b/lib/lograge/silent_logger.rb index 04c9055..41b1243 100644 --- a/lib/lograge/silent_logger.rb +++ b/lib/lograge/silent_logger.rb @@ -5,9 +5,7 @@ module Lograge class SilentLogger < SimpleDelegator %i[debug info warn error fatal unknown].each do |method_name| - # rubocop:disable Lint/EmptyBlock define_method(method_name) { |*_args| } - # rubocop:enable Lint/EmptyBlock end end end diff --git a/lograge.gemspec b/lograge.gemspec index 2d439ea..b8f02e5 100644 --- a/lograge.gemspec +++ b/lograge.gemspec @@ -22,10 +22,11 @@ Gem::Specification.new do |s| s.files = `git ls-files lib LICENSE.txt`.split("\n") - # base64, bigdecimal and mutex_m were extracted from the default gems in - # Ruby 3.4; older Rails releases still `require` them, and JRuby (which - # targets Ruby 3.4) does not bundle them, so declare them explicitly. + # base64, benchmark, bigdecimal and mutex_m were extracted from the default + # gems in Ruby 3.4/4.1; older Rails releases still `require` them, and JRuby + # (which targets Ruby 3.4) does not bundle them, so declare them explicitly. s.add_development_dependency 'base64' + s.add_development_dependency 'benchmark' s.add_development_dependency 'bigdecimal' s.add_development_dependency 'mutex_m' # rdoc 8 depends on rbs, whose C extension cannot be built on JRuby. Keep diff --git a/spec/log_subscribers/action_cable_spec.rb b/spec/log_subscribers/action_cable_spec.rb index 0dfa385..28e3f0e 100644 --- a/spec/log_subscribers/action_cable_spec.rb +++ b/spec/log_subscribers/action_cable_spec.rb @@ -33,7 +33,7 @@ context 'with custom_options configured for cee output' do before do - Lograge.formatter = ->(data) { "My test: #{data.to_json}" } + Lograge.formatter = ->(data) { "My test: #{JSON.dump(data)}" } end it 'combines the hash properly for the output' do diff --git a/spec/log_subscribers/action_controller_spec.rb b/spec/log_subscribers/action_controller_spec.rb index 35e60ec..5402927 100644 --- a/spec/log_subscribers/action_controller_spec.rb +++ b/spec/log_subscribers/action_controller_spec.rb @@ -39,7 +39,7 @@ context 'with custom_options configured for cee output' do before do - Lograge.formatter = ->(data) { "My test: #{data.to_json}" } + Lograge.formatter = ->(data) { "My test: #{JSON.dump(data)}" } end it 'combines the hash properly for the output' do