From 2f5386dd5859aca472eebd815220a5596c5f6789 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Wed, 19 Jun 2024 16:22:40 +0200 Subject: [PATCH] DEV: Fix linting (#353) Moves linting to a separate CI step and removes rubocop from the Rakefile (at least until we drop Ruby 2.6) --- .github/workflows/ci.yml | 46 ++++++++++++++-------- .rubocop.yml | 8 +++- Rakefile | 6 +-- lib/message_bus.rb | 3 +- lib/message_bus/backends/base.rb | 1 - lib/message_bus/backends/postgres.rb | 2 +- lib/message_bus/backends/redis.rb | 2 +- message_bus.gemspec | 6 ++- spec/lib/message_bus/multi_process_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 10 files changed, 47 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 117e1df5..215af254 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,34 @@ on: pull_request: jobs: - build: + lint: + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + bundler-cache: true + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Setup npm + run: npm install + + - name: Rubocop + run: bundle exec rubocop + + - name: ESLint + run: npx eslint . + + test: runs-on: ubuntu-latest name: Ruby ${{ matrix.ruby }} (redis ${{ matrix.redis }}) timeout-minutes: 10 @@ -20,7 +47,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: [2.6, 2.7, '3.0', 3.1] + ruby: [2.6, 2.7, "3.0", 3.1] redis: [5, 6] services: @@ -50,27 +77,14 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: npm - - - name: Setup npm - run: npm install - - name: Tests env: TESTOPTS: --verbose run: bundle exec rake - timeout-minutes: 3 - - - name: Linting - run: npx eslint . publish: if: github.event_name == 'push' && github.ref == 'refs/heads/main' - needs: build + needs: [lint, test] runs-on: ubuntu-latest steps: diff --git a/.rubocop.yml b/.rubocop.yml index 5e845dbb..aca79daa 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,11 +1,15 @@ inherit_gem: - rubocop-discourse: .rubocop.yml + rubocop-discourse: stree-compat.yml inherit_mode: merge: - Exclude + AllCops: Exclude: - - 'examples/**/*' + - "examples/**/*" + +Discourse/Plugins: + Enabled: false RSpec: Enabled: false diff --git a/Rakefile b/Rakefile index 9b6acb18..4c33c6f1 100644 --- a/Rakefile +++ b/Rakefile @@ -4,12 +4,10 @@ require 'rake/testtask' require 'bundler' require 'bundler/gem_tasks' require 'bundler/setup' -require 'rubocop/rake_task' require 'yard' Bundler.require(:default, :test) -RuboCop::RakeTask.new YARD::Rake::YardocTask.new BACKENDS = Dir["lib/message_bus/backends/*.rb"].map { |file| file.match(%r{backends/(?.*).rb})[:backend] } - ["base"] @@ -99,5 +97,5 @@ task :performance do end end -desc "Run all tests, link checks and confirms documentation compiles without error" -task default: [:spec, :rubocop, :test_doc] +desc "Run all tests and confirm the documentation compiles without error" +task default: [:spec, :test_doc] diff --git a/lib/message_bus.rb b/lib/message_bus.rb index 5f534ef6..ee249b05 100644 --- a/lib/message_bus.rb +++ b/lib/message_bus.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "monitor" -require "set" require_relative "message_bus/version" require_relative "message_bus/message" @@ -772,7 +771,7 @@ def global_subscribe_thread globals, locals, local_globals, global_globals = nil @mutex.synchronize do - return if @destroyed + return if @destroyed # rubocop:disable Lint/NonLocalExitFromIterator next unless @subscriptions globals = @subscriptions[nil] diff --git a/lib/message_bus/backends/base.rb b/lib/message_bus/backends/base.rb index e25218d4..be83e5f6 100644 --- a/lib/message_bus/backends/base.rb +++ b/lib/message_bus/backends/base.rb @@ -48,7 +48,6 @@ module Backends # # @abstract class Base - # rubocop:disable Lint/UnusedMethodArgument # Raised to indicate that the concrete backend implementation does not implement part of the API ConcreteClassMustImplementError = Class.new(StandardError) diff --git a/lib/message_bus/backends/postgres.rb b/lib/message_bus/backends/postgres.rb index b4c2a897..dc9cc2f2 100644 --- a/lib/message_bus/backends/postgres.rb +++ b/lib/message_bus/backends/postgres.rb @@ -406,7 +406,7 @@ def global_subscribe(last_id = nil) on.message do |_c, m| if m == UNSUB_MESSAGE @subscribed = false - return + return # rubocop:disable Lint/NonLocalExitFromIterator end m = MessageBus::Message.decode m diff --git a/lib/message_bus/backends/redis.rb b/lib/message_bus/backends/redis.rb index bce6c14c..3a34c229 100644 --- a/lib/message_bus/backends/redis.rb +++ b/lib/message_bus/backends/redis.rb @@ -300,7 +300,7 @@ def global_subscribe(last_id = nil, &blk) if m == UNSUB_MESSAGE @subscribed = false global_redis.unsubscribe - return + return # rubocop:disable Lint/NonLocalExitFromIterator end m = MessageBus::Message.decode m diff --git a/message_bus.gemspec b/message_bus.gemspec index 596d827c..9a67e030 100644 --- a/message_bus.gemspec +++ b/message_bus.gemspec @@ -35,6 +35,8 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'byebug' gem.add_development_dependency 'oj' gem.add_development_dependency 'yard' - gem.add_development_dependency 'rubocop-discourse' - gem.add_development_dependency 'rubocop-rspec' + + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0') + gem.add_development_dependency 'rubocop-discourse', '3.8.1' + end end diff --git a/spec/lib/message_bus/multi_process_spec.rb b/spec/lib/message_bus/multi_process_spec.rb index 9f78d6d0..345cda45 100644 --- a/spec/lib/message_bus/multi_process_spec.rb +++ b/spec/lib/message_bus/multi_process_spec.rb @@ -22,7 +22,7 @@ def work_it if msg.data == "done" bus.global_unsubscribe else - bus.publish("/response", "#{msg.data}-#{Process.pid.to_s}") + bus.publish("/response", "#{msg.data}-#{Process.pid}") end end ensure diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ac46ff7c..6dbeccb3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,7 +19,7 @@ puts "Running with backend: #{CURRENT_BACKEND}" def test_only(*backends) - skip "Test doesn't apply to #{CURRENT_BACKEND}" unless backends.include?(CURRENT_BACKEND) + skip "Test doesn't apply to #{CURRENT_BACKEND}" if backends.exclude?(CURRENT_BACKEND) end def test_never(*backends)