From b576ff64dafce5d3f3a32a0c52a8fb7f31bbe35d Mon Sep 17 00:00:00 2001 From: Colin Kelley Date: Tue, 24 Nov 2020 21:08:41 -0800 Subject: [PATCH] issue #504: set Layout/EndAlignment: EnforcedStyleAlignWith: variable; move LineLength to Layout namespace --- .rubocop.yml | 6 ++++-- lib/listen/event/queue.rb | 8 ++++---- lib/listen/fsm.rb | 4 ++-- lib/listen/logger.rb | 25 +++++++++++++------------ lib/listen/record.rb | 8 ++++---- lib/listen/thread.rb | 8 ++++---- spec/support/acceptance_helper.rb | 23 +++++++++++------------ 7 files changed, 42 insertions(+), 40 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1c2077ca..a6359189 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -18,10 +18,14 @@ Layout/EmptyLineAfterGuardClause: Enabled: false Layout/EmptyLinesAroundAttributeAccessor: Enabled: true +Layout/EndAlignment: + EnforcedStyleAlignWith: variable Layout/HashAlignment: Enabled: false Layout/HeredocIndentation: Enabled: true +Layout/LineLength: + Max: 150 Layout/MultilineMethodCallBraceLayout: Enabled: false Layout/MultilineMethodCallIndentation: @@ -99,8 +103,6 @@ Metrics/BlockLength: - "**/*_spec.rb" Metrics/CyclomaticComplexity: Max: 10 -Metrics/LineLength: - Max: 150 Metrics/MethodLength: Max: 15 Metrics/ModuleLength: diff --git a/lib/listen/event/queue.rb b/lib/listen/event/queue.rb index dcb5f227..ffcd67c5 100644 --- a/lib/listen/event/queue.rb +++ b/lib/listen/event/queue.rb @@ -31,10 +31,10 @@ def <<(args) fail "Invalid path: #{path.inspect}" unless path.is_a?(String) dir = if @config.relative? - _safe_relative_from_cwd(dir) - else - dir - end + _safe_relative_from_cwd(dir) + else + dir + end @event_queue << [type, change, dir, path, options] end diff --git a/lib/listen/fsm.rb b/lib/listen/fsm.rb index 80f1260c..ba63fd65 100644 --- a/lib/listen/fsm.rb +++ b/lib/listen/fsm.rb @@ -113,8 +113,8 @@ def initialize(name, transitions, &block) @name = name @block = block @transitions = if transitions - Array(transitions).map(&:to_sym) - end + Array(transitions).map(&:to_sym) + end end def call(obj) diff --git a/lib/listen/logger.rb b/lib/listen/logger.rb index f906e7ba..e839c02d 100644 --- a/lib/listen/logger.rb +++ b/lib/listen/logger.rb @@ -16,18 +16,19 @@ def logger private def default_logger - level = case ENV['LISTEN_GEM_DEBUGGING'].to_s - when /debug|2/i - ::Logger::DEBUG - when /info|true|yes|1/i - ::Logger::INFO - when /warn/i - ::Logger::WARN - when /fatal/i - ::Logger::FATAL - else - ::Logger::ERROR - end + level = + case ENV['LISTEN_GEM_DEBUGGING'].to_s + when /debug|2/i + ::Logger::DEBUG + when /info|true|yes|1/i + ::Logger::INFO + when /warn/i + ::Logger::WARN + when /fatal/i + ::Logger::FATAL + else + ::Logger::ERROR + end ::Logger.new(STDERR, level: level) end diff --git a/lib/listen/record.rb b/lib/listen/record.rb index 0dd718b4..144bc058 100644 --- a/lib/listen/record.rb +++ b/lib/listen/record.rb @@ -46,10 +46,10 @@ def file_data(rel_path) def dir_entries(rel_path) subtree = if [nil, '', '.'].include? rel_path.to_s - @tree - else - _sub_tree(rel_path) - end + @tree + else + _sub_tree(rel_path) + end subtree.transform_values do |values| # only get data for file entries diff --git a/lib/listen/thread.rb b/lib/listen/thread.rb index 3b3597cf..2143580e 100644 --- a/lib/listen/thread.rb +++ b/lib/listen/thread.rb @@ -32,10 +32,10 @@ def rescue_and_log(method_name, *args, caller_stack: nil) def _log_exception(exception, thread_name, caller_stack: nil) complete_backtrace = if caller_stack - [*exception.backtrace, "--- Thread.new ---", *caller_stack] - else - exception.backtrace - end + [*exception.backtrace, "--- Thread.new ---", *caller_stack] + else + exception.backtrace + end message = "Exception rescued in #{thread_name}:\n#{_exception_with_causes(exception)}\n#{complete_backtrace * "\n"}" Listen.logger.error(message) end diff --git a/spec/support/acceptance_helper.rb b/spec/support/acceptance_helper.rb index 99407ab1..dd717dcd 100644 --- a/spec/support/acceptance_helper.rb +++ b/spec/support/acceptance_helper.rb @@ -158,19 +158,18 @@ def initialize(callback, paths, *args) # Isolate collected changes between tests/listener instances @timed_changes = TimedChanges.new - @listener = - if callback - Listen.send(*args) do |modified, added, removed| - # Add changes to trigger frozen Hash error, making sure lag is enough - _add_changes(:modified, modified, changes) - _add_changes(:added, added, changes) - _add_changes(:removed, removed, changes) - - callback.call(modified, added, removed) unless callback == :track_changes - end - else - Listen.send(*args) + @listener = if callback + Listen.send(*args) do |modified, added, removed| + # Add changes to trigger frozen Hash error, making sure lag is enough + _add_changes(:modified, modified, changes) + _add_changes(:added, added, changes) + _add_changes(:removed, removed, changes) + + callback.call(modified, added, removed) unless callback == :track_changes end + else + Listen.send(*args) + end end def changes