From e84df097f960b6fc45b328a674ca66d5500202dc Mon Sep 17 00:00:00 2001 From: Alexandre Barret Date: Wed, 28 Feb 2024 14:01:50 +1300 Subject: [PATCH] Rubocop workflow with GitHub actions (#573) * Remove .hound.yml * Update Rubocop configuration and CI * Fix Style/MixinUsage cop include is used at the top level. Use inside class or module. * Fix Style/RedundantFreeze cop * Fix Lint/RedundantCopDisableDirective cop * Fix Style/CommentAnnotation cop Annotation keywords like Note should be all upper case, followed by a colon, and a space, then a note describing the problem. * Fix Style/MutableConstant cop Freeze mutable objects assigned to constants * Fix Style/MultipleComparison cop Avoid comparing a variable with multiple items in a conditional, use Array#include? instead. * Fix Naming/MemoizedInstanceVariableName cop Memoized variable @_remember_time_of_first_unprocessed_event does not match method name _wait_until_events. Use @_wait_until_events instead. --- .github/workflows/development.yml | 15 +++++++++++++++ .hound.yml | 4 ---- .rubocop.yml | 2 ++ Gemfile | 2 +- Rakefile | 4 ---- lib/listen/adapter/bsd.rb | 2 +- lib/listen/adapter/darwin.rb | 2 +- lib/listen/adapter/linux.rb | 4 ++-- lib/listen/adapter/polling.rb | 2 +- lib/listen/adapter/windows.rb | 2 +- lib/listen/event/processor.rb | 2 ++ lib/listen/fsm.rb | 2 +- lib/listen/options.rb | 2 -- lib/listen/record.rb | 2 +- lib/listen/record/symlink_detector.rb | 2 +- lib/listen/silencer.rb | 4 ++-- 16 files changed, 31 insertions(+), 22 deletions(-) delete mode 100644 .hound.yml diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 8d3edc12..5309c7c5 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -49,3 +49,18 @@ jobs: timeout-minutes: 6 run: | ${{matrix.env}} bundle exec rspec + + linting: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + bundler-cache: true + + - name: Run rubocop + timeout-minutes: 6 + run: | + bundle exec rake rubocop diff --git a/.hound.yml b/.hound.yml deleted file mode 100644 index a0f6cc45..00000000 --- a/.hound.yml +++ /dev/null @@ -1,4 +0,0 @@ -ruby: - enabled: true - version: 0.91.0 - config_file: .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml index 8043ab31..585ca424 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -200,6 +200,8 @@ Style/KeywordParametersOrder: Enabled: true Style/Lambda: Enabled: false +Style/MixinUsage: + Enabled: false Style/ModuleFunction: Enabled: false Style/NegatedIf: diff --git a/Gemfile b/Gemfile index 2ccc8c85..5c7348cf 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,6 @@ group :development do gem 'netrc', require: false gem 'octokit', require: false gem 'pry-rescue' - gem 'rubocop', '0.91.0' + gem 'rubocop' gem 'yard', require: false end diff --git a/Rakefile b/Rakefile index 10ba8b7e..131d63bf 100644 --- a/Rakefile +++ b/Rakefile @@ -5,13 +5,9 @@ require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -if ENV["CI"] != "true" require "rubocop/rake_task" RuboCop::RakeTask.new(:rubocop) task default: [:spec, :rubocop] -else - task default: [:spec] -end class Releaser def initialize(options = {}) diff --git a/lib/listen/adapter/bsd.rb b/lib/listen/adapter/bsd.rb index aafa2ceb..84266232 100644 --- a/lib/listen/adapter/bsd.rb +++ b/lib/listen/adapter/bsd.rb @@ -7,7 +7,7 @@ module Listen module Adapter class BSD < Base - OS_REGEXP = /bsd|dragonfly/i.freeze + OS_REGEXP = /bsd|dragonfly/i DEFAULTS = { events: [ diff --git a/lib/listen/adapter/darwin.rb b/lib/listen/adapter/darwin.rb index 3a610c5d..07c7a567 100644 --- a/lib/listen/adapter/darwin.rb +++ b/lib/listen/adapter/darwin.rb @@ -7,7 +7,7 @@ module Adapter # Adapter implementation for Mac OS X `FSEvents`. # class Darwin < Base - OS_REGEXP = /darwin(?(1|2)\d+)/i.freeze + OS_REGEXP = /darwin(?(1|2)\d+)/i # The default delay between checking for changes. DEFAULTS = { latency: 0.1 }.freeze diff --git a/lib/listen/adapter/linux.rb b/lib/listen/adapter/linux.rb index 32be05f4..5b78ee3d 100644 --- a/lib/listen/adapter/linux.rb +++ b/lib/listen/adapter/linux.rb @@ -4,7 +4,7 @@ module Listen module Adapter # @see https://github.com/nex3/rb-inotify class Linux < Base - OS_REGEXP = /linux/i.freeze + OS_REGEXP = /linux/i DEFAULTS = { events: [ @@ -60,7 +60,7 @@ def _process_event(dir, event) cookie_params = event.cookie.zero? ? {} : { cookie: event.cookie } - # Note: don't pass options to force rescanning the directory, so we can + # NOTE: don't pass options to force rescanning the directory, so we can # detect moving/deleting a whole tree if _dir_event?(event) _queue_change(:dir, dir, rel_path, cookie_params) diff --git a/lib/listen/adapter/polling.rb b/lib/listen/adapter/polling.rb index 9d281af6..57cda9c9 100644 --- a/lib/listen/adapter/polling.rb +++ b/lib/listen/adapter/polling.rb @@ -8,7 +8,7 @@ module Adapter # file IO than the other implementations. # class Polling < Base - OS_REGEXP = //.freeze # match every OS + OS_REGEXP = // # match every OS DEFAULTS = { latency: 1.0, wait_for_delay: 0.05 }.freeze diff --git a/lib/listen/adapter/windows.rb b/lib/listen/adapter/windows.rb index 26a64005..3b3a1854 100644 --- a/lib/listen/adapter/windows.rb +++ b/lib/listen/adapter/windows.rb @@ -5,7 +5,7 @@ module Adapter # Adapter implementation for Windows `wdm`. # class Windows < Base - OS_REGEXP = /mswin|mingw|cygwin/i.freeze + OS_REGEXP = /mswin|mingw|cygwin/i BUNDLER_DECLARE_GEM = <<-EOS.gsub(/^ {6}/, '') Please add the following to your Gemfile to avoid polling for changes: diff --git a/lib/listen/event/processor.rb b/lib/listen/event/processor.rb index 57656cbe..63e207c7 100644 --- a/lib/listen/event/processor.rb +++ b/lib/listen/event/processor.rb @@ -85,11 +85,13 @@ def _deadline # blocks until event is popped # returns the event or `nil` when the event_queue is closed + # rubocop:disable Naming/MemoizedInstanceVariableName def _wait_until_events config.event_queue.pop.tap do |_event| @_remember_time_of_first_unprocessed_event ||= MonotonicTime.now end end + # rubocop:enable Naming/MemoizedInstanceVariableName def _flush_wakeup_reasons until @reasons.empty? diff --git a/lib/listen/fsm.rb b/lib/listen/fsm.rb index 154ad2b3..f6ddc03d 100644 --- a/lib/listen/fsm.rb +++ b/lib/listen/fsm.rb @@ -38,7 +38,7 @@ def state(state_name, to: nil, &block) end end - # Note: including classes must call initialize_fsm from their initialize method. + # NOTE: including classes must call initialize_fsm from their initialize method. def initialize_fsm @fsm_initialized = true @state = self.class.start_state diff --git a/lib/listen/options.rb b/lib/listen/options.rb index 0f1abb1a..65025788 100644 --- a/lib/listen/options.rb +++ b/lib/listen/options.rb @@ -12,7 +12,6 @@ def initialize(opts, defaults) given_options.empty? or raise ArgumentError, "Unknown options: #{given_options.inspect}" end - # rubocop:disable Lint/MissingSuper def respond_to_missing?(name, *_) @options.has_key?(name) end @@ -21,6 +20,5 @@ def method_missing(name, *_) respond_to_missing?(name) or raise NameError, "Bad option: #{name.inspect} (valid:#{@options.keys.inspect})" @options[name] end - # rubocop:enable Lint/MissingSuper end end diff --git a/lib/listen/record.rb b/lib/listen/record.rb index 2218149f..87f5dd7c 100644 --- a/lib/listen/record.rb +++ b/lib/listen/record.rb @@ -73,7 +73,7 @@ def build private def empty_dirname?(dirname) - dirname == '.' || dirname == '' + ['.', ''].include?(dirname) end def reset_tree diff --git a/lib/listen/record/symlink_detector.rb b/lib/listen/record/symlink_detector.rb index f193043c..1da60f58 100644 --- a/lib/listen/record/symlink_detector.rb +++ b/lib/listen/record/symlink_detector.rb @@ -9,7 +9,7 @@ class Record class SymlinkDetector README_URL = 'https://github.com/guard/listen/blob/master/README.md' - SYMLINK_LOOP_ERROR = <<-EOS + SYMLINK_LOOP_ERROR = <<-EOS.freeze ** ERROR: directory is already being watched! ** Directory: %s diff --git a/lib/listen/silencer.rb b/lib/listen/silencer.rb index 7253a8b8..4e99b45e 100644 --- a/lib/listen/silencer.rb +++ b/lib/listen/silencer.rb @@ -18,7 +18,7 @@ class Silencer # emacs temp files | \#.+\# | \.\#.+ - )(/|\z)}x.freeze + )(/|\z)}x # The default list of files that get ignored. DEFAULT_IGNORED_EXTENSIONS = %r{(?: @@ -59,7 +59,7 @@ class Silencer | \.DS_Store | \.tmp | ~ - )\z}x.freeze + )\z}x # TODO: deprecate these mutators; use attr_reader instead attr_accessor :only_patterns, :ignore_patterns