Skip to content

Commit

Permalink
issue #504: rubocop -a
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Nov 6, 2020
1 parent 9ca11e6 commit 931106f
Show file tree
Hide file tree
Showing 29 changed files with 131 additions and 139 deletions.
4 changes: 2 additions & 2 deletions lib/listen/adapter.rb
Expand Up @@ -11,7 +11,7 @@ module Listen
module Adapter
OPTIMIZED_ADAPTERS = [Darwin, Linux, BSD, Windows].freeze
POLLING_FALLBACK_MESSAGE = 'Listen will be polling for changes.'\
'Learn more at https://github.com/guard/listen#listen-adapters.'.freeze
'Learn more at https://github.com/guard/listen#listen-adapters.'

class << self
def select(options = {})
Expand All @@ -24,7 +24,7 @@ def select(options = {})
Polling
rescue
Listen.logger.warn format('Adapter: failed: %s:%s', $ERROR_POSITION.inspect,
$ERROR_POSITION * "\n")
$ERROR_POSITION * "\n")
raise
end

Expand Down
5 changes: 2 additions & 3 deletions lib/listen/adapter/bsd.rb
Expand Up @@ -7,7 +7,7 @@
module Listen
module Adapter
class BSD < Base
OS_REGEXP = /bsd|dragonfly/i
OS_REGEXP = /bsd|dragonfly/i.freeze

DEFAULTS = {
events: [
Expand Down Expand Up @@ -73,8 +73,7 @@ def _process_event(dir, event)
def _change(event_flags)
{ modified: [:attrib, :extend],
added: [:write],
removed: [:rename, :delete]
}.each do |change, flags|
removed: [:rename, :delete] }.each do |change, flags|
return change unless (flags & event_flags).empty?
end
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/adapter/darwin.rb
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
OS_REGEXP = /darwin(?<major_version>(1|2)\d+)/i.freeze

# 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
Expand Up @@ -4,7 +4,7 @@ module Listen
module Adapter
# @see https://github.com/nex3/rb-inotify
class Linux < Base
OS_REGEXP = /linux/i
OS_REGEXP = /linux/i.freeze

DEFAULTS = {
events: [
Expand All @@ -22,7 +22,7 @@ class Linux < Base
private

WIKI_URL = 'https://github.com/guard/listen'\
'/wiki/Increasing-the-amount-of-inotify-watchers'.freeze
'/wiki/Increasing-the-amount-of-inotify-watchers'

INOTIFY_LIMIT_MESSAGE = <<-EOS.gsub(/^\s*/, '')
FATAL: Listen error: unable to monitor directories for changes.
Expand Down
2 changes: 1 addition & 1 deletion lib/listen/adapter/polling.rb
Expand Up @@ -8,7 +8,7 @@ module Adapter
# file IO than the other implementations.
#
class Polling < Base
OS_REGEXP = // # match every OS
OS_REGEXP = //.freeze # match every OS

DEFAULTS = { latency: 1.0, wait_for_delay: 0.05 }.freeze

Expand Down
6 changes: 3 additions & 3 deletions lib/listen/adapter/windows.rb
Expand Up @@ -5,7 +5,7 @@ module Adapter
# Adapter implementation for Windows `wdm`.
#
class Windows < Base
OS_REGEXP = /mswin|mingw|cygwin/i
OS_REGEXP = /mswin|mingw|cygwin/i.freeze

BUNDLER_DECLARE_GEM = <<-EOS.gsub(/^ {6}/, '')
Please add the following to your Gemfile to avoid polling for changes:
Expand All @@ -18,7 +18,7 @@ def self.usable?
true
rescue LoadError
Listen.logger.debug format('wdm - load failed: %s:%s', $ERROR_INFO,
$ERROR_POSITION * "\n")
$ERROR_POSITION * "\n")

Kernel.warn BUNDLER_DECLARE_GEM
false
Expand Down Expand Up @@ -83,7 +83,7 @@ def _process_event(dir, event)
rescue
details = event.inspect
Listen.logger.error format('wdm - callback (%s): %s:%s', details, $ERROR_INFO,
$ERROR_POSITION * "\n")
$ERROR_POSITION * "\n")
raise
end

Expand Down
2 changes: 0 additions & 2 deletions lib/listen/directory.rb
Expand Up @@ -38,11 +38,9 @@ def self.scan(snapshot, rel_path, options)
previous = previous.reject { |entry, _| current.include? path + entry }

_async_changes(snapshot, Pathname.new(rel_path), previous, options)

rescue Errno::ENOENT, Errno::EHOSTDOWN
record.unset_path(rel_path)
_async_changes(snapshot, Pathname.new(rel_path), previous, options)

rescue Errno::ENOTDIR
# TODO: path not tested
record.unset_path(rel_path)
Expand Down
5 changes: 3 additions & 2 deletions lib/listen/event/config.rb
Expand Up @@ -12,7 +12,8 @@ def initialize(
event_queue,
queue_optimizer,
wait_for_delay,
&block)
&block
)

@listener = listener
@event_queue = event_queue
Expand All @@ -26,7 +27,7 @@ def sleep(seconds)
end

def call(*args)
@block.call(*args) if @block
@block&.call(*args)
end

def timestamp
Expand Down
6 changes: 3 additions & 3 deletions lib/listen/record/symlink_detector.rb
Expand Up @@ -6,9 +6,9 @@ module Listen
# @private api
class Record
class SymlinkDetector
WIKI = 'https://github.com/guard/listen/wiki/Duplicate-directory-errors'.freeze
WIKI = 'https://github.com/guard/listen/wiki/Duplicate-directory-errors'

SYMLINK_LOOP_ERROR = <<-EOS.freeze
SYMLINK_LOOP_ERROR = <<-EOS
** ERROR: directory is already being watched! **
Directory: %s
Expand All @@ -33,7 +33,7 @@ def verify_unwatched!(entry)
private

def _fail(symlinked, real_path)
STDERR.puts format(SYMLINK_LOOP_ERROR, symlinked, real_path)
warn format(SYMLINK_LOOP_ERROR, symlinked, real_path)
fail Error, 'Failed due to looped symlinks'
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/listen/silencer.rb
Expand Up @@ -14,7 +14,7 @@ class Silencer
| log
| tmp
|vendor/ruby
)(/|$)}x
)(/|$)}x.freeze

# The default list of files that get ignored.
DEFAULT_IGNORED_EXTENSIONS = %r{(?:
Expand Down Expand Up @@ -55,7 +55,7 @@ class Silencer
| \.DS_Store
| \.tmp
| ~
)$}x
)$}x.freeze

attr_accessor :only_patterns, :ignore_patterns

Expand Down
10 changes: 4 additions & 6 deletions lib/listen/thread.rb
Expand Up @@ -14,12 +14,10 @@ def new(name)

caller_stack = caller
::Thread.new do
begin
yield
rescue Exception => ex
_log_exception(ex, thread_name, caller_stack)
nil
end
yield
rescue Exception => ex
_log_exception(ex, thread_name, caller_stack)
nil
end.tap do |thread|
thread.name = thread_name
end
Expand Down
5 changes: 1 addition & 4 deletions spec/acceptance/listen_spec.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true

# encoding: UTF-8

RSpec.describe 'Listen', acceptance: true do
let(:base_options) { { latency: 0.1 } }
let(:polling_options) { {} }
Expand Down Expand Up @@ -144,8 +142,7 @@
it 'listens to file move' do
expected = { modified: [],
added: %w(file.rb),
removed: %w(dir/file.rb)
}
removed: %w(dir/file.rb) }

expect(wrapper.listen do
mv 'dir/file.rb', 'file.rb'
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/listen/adapter/base_spec.rb
Expand Up @@ -54,10 +54,10 @@ def _process_event(dir, event)
allow(Listen::Record).to receive(:new).with(dir1).and_return(record)

allow(Listen::Change::Config).to receive(:new).with(queue, silencer).
and_return(config)
and_return(config)

allow(Listen::Change).to receive(:new).with(config, record).
and_return(snapshot)
and_return(snapshot)
end

describe '#start' do
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/listen/adapter/config_spec.rb
Expand Up @@ -43,15 +43,15 @@
allow(Pathname).to receive(:new).with(path2).and_return(path2)

allow(Pathname).to receive(:new).with('symlinked_dir1').
and_return(symlinked_dir1)
and_return(symlinked_dir1)

allow(Pathname).to receive(:new).with('symlinked_dir2').
and_return(symlinked_dir2)
and_return(symlinked_dir2)

allow(Dir).to receive(:pwd).and_return('/real/current_path')

allow(Pathname).to receive(:new).
with('/real/current_path').and_return(current_path)
with('/real/current_path').and_return(current_path)
end

describe '#initialize' do
Expand Down Expand Up @@ -85,7 +85,7 @@
end

context 'with no directories' do
let(:directories) {}
let(:directories) { }
it 'returns the current path in array' do
expect(subject.directories).to eq([real_current_path])
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/listen/adapter/linux_spec.rb
Expand Up @@ -89,9 +89,9 @@

allow(Listen::Record).to receive(:new).with(dir1).and_return(record)
allow(Listen::Change::Config).to receive(:new).with(queue, silencer).
and_return(config)
and_return(config)
allow(Listen::Change).to receive(:new).with(config, record).
and_return(snapshot)
and_return(snapshot)

allow(subject).to receive(:require).with('rb-inotify')
subject.configure
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/listen/adapter/polling_spec.rb
Expand Up @@ -38,9 +38,9 @@
allow(Listen::Record).to receive(:new).with(dir1).and_return(record)

allow(Listen::Change).to receive(:new).with(config, record).
and_return(snapshot)
and_return(snapshot)
allow(Listen::Change::Config).to receive(:new).with(queue, silencer).
and_return(config)
and_return(config)
end

describe '#start' do
Expand All @@ -56,7 +56,7 @@

it 'notifies change on every listener directories path' do
expect(snapshot).to receive(:invalidate).
with(:dir, '.', recursive: true)
with(:dir, '.', recursive: true)

t = Thread.new { subject.start }
sleep 0.25
Expand Down
18 changes: 9 additions & 9 deletions spec/lib/listen/backend_spec.rb
Expand Up @@ -33,33 +33,33 @@
stub_const('Listen::Adapter::Config', adapter_config_class)

allow(adapter_config_class).to receive(:new).
with([dir1], queue, silencer, adapter_options).
and_return(adapter_config)
with([dir1], queue, silencer, adapter_options).
and_return(adapter_config)

allow(Listen::Adapter).to receive(:select).
with(select_options).and_return(adapter_class)
with(select_options).and_return(adapter_class)

allow(adapter_class).to receive(:new).
with(adapter_config).and_return(adapter)
with(adapter_config).and_return(adapter)

allow(Listen::Adapter::Polling).to receive(:new).with(adapter_config).
and_return(adapter)
and_return(adapter)

allow(config).to receive(:adapter_select_options).
and_return(select_options)
and_return(select_options)

allow(config).to receive(:adapter_instance_options).
and_return(adapter_options)
and_return(adapter_options)

allow(config).to receive(:min_delay_between_events).
and_return(config_min_delay_between_events)
and_return(config_min_delay_between_events)
end

describe '#initialize' do
context 'with config' do
it 'sets up an adapter class' do
expect(adapter_class).to receive(:new).
with(adapter_config).and_return(adapter)
with(adapter_config).and_return(adapter)

subject
end
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/listen/change_spec.rb
Expand Up @@ -31,7 +31,7 @@
context 'with known change' do
it 'notifies change directly to listener' do
expect(config).to receive(:queue).
with(:file, :modified, Pathname.new('/dir'), 'file.rb', {})
with(:file, :modified, Pathname.new('/dir'), 'file.rb', {})

subject.invalidate(:file, 'file.rb', change: :modified)
end
Expand All @@ -51,7 +51,7 @@

it "doesn't call Listen::File#change if path is silenced" do
expect(config).to receive(:silenced?).
with('file.rb', :file).and_return(true)
with('file.rb', :file).and_return(true)

expect(Listen::File).to_not receive(:change)
subject.invalidate(:file, 'file.rb', {})
Expand All @@ -63,7 +63,7 @@
context 'listener listen' do
it 'notifies change to listener' do
expect(config).to receive(:queue).
with(:file, :modified, Pathname.new('/dir'), 'file.rb')
with(:file, :modified, Pathname.new('/dir'), 'file.rb')

subject.invalidate(:file, 'file.rb', {})
end
Expand Down Expand Up @@ -93,7 +93,7 @@

it 'calls Listen::Directory#new' do
expect(Listen::Directory).to receive(:scan).
with(subject, 'dir1', dir_options)
with(subject, 'dir1', dir_options)

subject.invalidate(:dir, 'dir1', dir_options)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/listen/cli_spec.rb
Expand Up @@ -108,8 +108,8 @@
it 'passes relative option to Listen' do
value = double('value')
expect(Listen).to receive(:to).
with(nil, hash_including(relative: value)).
and_return(listener)
with(nil, hash_including(relative: value)).
and_return(listener)

described_class.new(relative: value).start
end
Expand Down

0 comments on commit 931106f

Please sign in to comment.