Skip to content

Commit

Permalink
Rubocop workflow with GitHub actions (#573)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
AlexB52 authored Feb 28, 2024
1 parent 7b7a2f5 commit e84df09
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 22 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions .hound.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ Style/KeywordParametersOrder:
Enabled: true
Style/Lambda:
Enabled: false
Style/MixinUsage:
Enabled: false
Style/ModuleFunction:
Enabled: false
Style/NegatedIf:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 0 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/adapter/bsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module Listen
module Adapter
class BSD < Base
OS_REGEXP = /bsd|dragonfly/i.freeze
OS_REGEXP = /bsd|dragonfly/i

DEFAULTS = {
events: [
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/adapter/darwin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Adapter
# Adapter implementation for Mac OS X `FSEvents`.
#
class Darwin < Base
OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i.freeze
OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i

# The default delay between checking for changes.
DEFAULTS = { latency: 0.1 }.freeze
Expand Down
4 changes: 2 additions & 2 deletions lib/listen/adapter/linux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/adapter/polling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/listen/adapter/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions lib/listen/event/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/fsm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/listen/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/listen/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def build
private

def empty_dirname?(dirname)
dirname == '.' || dirname == ''
['.', ''].include?(dirname)
end

def reset_tree
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/record/symlink_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/listen/silencer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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{(?:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e84df09

Please sign in to comment.