Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #504: try merging invoca .rubocop.yml #508

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2307dcf
issue #504: bump robocop to v0.91.0 and update cop names to match
ColinDKelley Nov 6, 2020
09b0b34
issue #504: try Invoca's .rubocop.yml; disable a few more cops that d…
ColinDKelley Nov 6, 2020
89c7b77
issue #504: rubocop -a
ColinDKelley Nov 6, 2020
55c3929
issue #504: rubocop -A
ColinDKelley Nov 6, 2020
9573077
issue #504: in .hound.yml, pin rubocop to v0.91.0
ColinDKelley Nov 6, 2020
ab870f5
issue #504: stub warn instead of puts
ColinDKelley Nov 6, 2020
870e8f0
issue #504: address many rubocop offenses
ColinDKelley Nov 6, 2020
a6b6b5d
issue #504: TargetRubyVersion: 2.7
ColinDKelley Nov 6, 2020
e9d888a
issue #504: spell out exception; # rubocop:disable Lint/RescueException
ColinDKelley Nov 23, 2020
a871455
issue #504: rubocop -a
ColinDKelley Nov 23, 2020
f6f144e
issue #504: merge in vendor/hound/config/style_guides/ruby.yml
ColinDKelley Nov 23, 2020
395fdd5
issue #504: move . back to previous line
ColinDKelley Nov 23, 2020
e2b0066
issue #504: sort .rubocop.yml
ColinDKelley Nov 23, 2020
e422472
issue #504: shorten change_fs
ColinDKelley Nov 23, 2020
cfacb88
issue #504: drop some disabled cops; tune MethodLength to 15 with a f…
ColinDKelley Nov 23, 2020
2da3b5e
issue #504: shorten long methods/disable MethodLength cop
ColinDKelley Nov 23, 2020
12df4c4
issue #504: add method_defined?
ColinDKelley Nov 23, 2020
7aa0320
issue #504: add inline rubocop:disable
ColinDKelley Nov 23, 2020
2645262
issue #504: fix cop violations: respond_to_missing?; open
ColinDKelley Nov 23, 2020
5860ed7
issue #504: add newer cops
ColinDKelley Nov 23, 2020
46aa56a
issue #504: rubocop -a -A
ColinDKelley Nov 23, 2020
5b6948b
issue #504: fix keyword arg
ColinDKelley Nov 24, 2020
cd980a7
issue #504: rubocop:disable Lint/MissingSuper
ColinDKelley Nov 24, 2020
c6fe53b
issue #504: remove early returns and private attr_readers
ColinDKelley Nov 24, 2020
ff8450d
issue #504: remove more early returns
ColinDKelley Nov 24, 2020
b2fbfaf
issue #504: fix stubbing to use @_remember_time_of_first_unprocessed_…
ColinDKelley Nov 24, 2020
01cc75b
issue #504: fix *[] refactor bug
ColinDKelley Nov 24, 2020
745d0e3
issue #504: indent if from left; add parens
ColinDKelley Nov 24, 2020
e1045d2
issue #504: set Layout/EndAlignment: EnforcedStyleAlignWith: variable…
ColinDKelley Nov 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .hound.yml
@@ -1,3 +1,4 @@
ruby:
enabled: true
version: 0.91.0
config_file: .rubocop.yml
181 changes: 179 additions & 2 deletions .rubocop.yml
Expand Up @@ -7,13 +7,190 @@ AllCops:

# Files you want to exclude
AllCops:
TargetRubyVersion: 2.3
TargetRubyVersion: 2.7
Exclude:
- db/schema.rb
- Gemfile
- Guardfile
- Rakefile

# TODO: put your overrides here:

Layout/AccessModifierIndentation:
IndentationWidth: 2

Layout/HashAlignment:
Enabled: false

Layout/EmptyLineAfterGuardClause:
Enabled: false

Layout/EmptyLinesAroundClassBody:
Enabled: false

Layout/EndOfLine:
Enabled: false

Layout/ExtraSpacing:
Enabled: false

Layout/HeredocIndentation:
EnforcedStyle: unindent

Layout/MultilineMethodCallBraceLayout:
Enabled: false

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented_relative_to_receiver

Layout/SpaceBeforeFirstArg:
Enabled: false

Layout/SpaceInsideBlockBraces:
EnforcedStyleForEmptyBraces: space

Lint/AmbiguousRegexpLiteral:
Enabled: false

Lint/AmbiguousBlockAssociation:
Enabled: false

Lint/EmptyWhen:
Enabled: false

Lint/RedundantRequireStatement:
Enabled: false

Metrics/AbcSize:
Max: 25

Metrics/BlockLength:
Exclude:
- 'Rakefile'
- '**/*.rake'
- '**/*_test.rb'
- '**/*_spec.rb'

Metrics/ClassLength:
Max: 200

Metrics/CyclomaticComplexity:
Max: 10

Metrics/LineLength:
Max: 150

Metrics/MethodLength:
Max: 20

Metrics/ModuleLength:
Max: 200

Metrics/ParameterLists:
Max: 10

Metrics/PerceivedComplexity:
Max: 10

Naming/HeredocDelimiterNaming:
Enabled: false

Naming/RescuedExceptionsVariableName:
Enabled: false

Naming/VariableNumber:
Enabled: false

Style/AndOr:
EnforcedStyle: conditionals

Style/ClassAndModuleChildren:
Enabled: true

# Mapping of methods to prefer, alternate => preferred
Style/CollectionMethods:
Enabled: true
PreferredMethods:
collect: 'map'
collect!: 'map!'
inject: 'reduce'
detect: 'find'
find_all: 'select'
length: 'size'

Style/CommentedKeyword:
Enabled: false

Style/Documentation:
Enabled: false

Style/DoubleNegation:
Enabled: false

Style/EachWithObject:
Enabled: false

Style/EmptyMethod:
Enabled: false

Style/FormatStringToken:
Enabled: false

Style/GuardClause:
Enabled: false

Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys

Style/IfUnlessModifier:
Enabled: false

Style/NegatedIf:
Enabled: false

Style/Lambda:
Enabled: false

Style/Next:
Enabled: false

Style/NumericLiteralPrefix:
Enabled: false

Style/NumericLiterals:
MinDigits: 9

Style/NumericPredicate:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Style/PreferredHashMethods:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Style/RescueStandardError:
Enabled: false

Style/SignalException:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/SymbolArray:
Enabled: false

Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/TrailingCommaInHashLiteral:
Enabled: false

Style/TrailingUnderscoreVariable:
Enabled: false

Style/WordArray:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -34,6 +34,6 @@ group :development do
gem 'netrc', require: false
gem 'octokit', require: false
gem 'pry-rescue'
gem 'rubocop', '~> 0.49.0' # TODO: should match Gemfile HoundCi
gem 'rubocop', '0.91.0'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to 1.2.0, I think there will be not much changes as I have checked in my local machine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the highest supported by hound is 0.91.0.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use something else than hound in that case? Github actions like lint-action.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KapilSachdev That sounds reasonable. So that we don't bog this Issue down, can you file a separate issue for that?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time i commented about lint-action, i was unaware of one issue that they have i.e. annotations don't work when PR is created from a fork. Which is where most PRs come from. Though there is a new pull_request_target event for that, but it still isn't working (from what i had tried).
shoulda-matcher gem also recently reverted from lint-action (which initially uses hound) and has fallen back to non-annotation based rubocop linting (like what rails uses).

I will create a issue for rubocop linting based on github actions.

gem 'yard', require: false
end
1 change: 1 addition & 0 deletions bin/listen
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'listen'
require 'listen/cli'
Expand Down
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")
ColinDKelley marked this conversation as resolved.
Show resolved Hide resolved
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
ColinDKelley marked this conversation as resolved.
Show resolved Hide resolved

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
8 changes: 4 additions & 4 deletions lib/listen/event/processor.rb
Expand Up @@ -70,22 +70,22 @@ def _sleep(seconds)
end

def _remember_time_of_first_unprocessed_event
@first_unprocessed_event_time ||= _timestamp
@_remember_time_of_first_unprocessed_event ||= _timestamp
end

def _reset_no_unprocessed_events
@first_unprocessed_event_time = nil
@_remember_time_of_first_unprocessed_event = nil
end

def _deadline
@first_unprocessed_event_time + @latency
@_remember_time_of_first_unprocessed_event + @latency
end

# blocks until event is popped
# returns the event or `nil` when the event_queue is closed
def _wait_until_events
config.event_queue.pop.tap do |_event|
@first_unprocessed_event_time ||= _timestamp
@_remember_time_of_first_unprocessed_event ||= _timestamp
end
end

Expand Down
8 changes: 4 additions & 4 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,8 +33,8 @@ def verify_unwatched!(entry)
private

def _fail(symlinked, real_path)
STDERR.puts format(SYMLINK_LOOP_ERROR, symlinked, real_path)
fail Error, 'Failed due to looped symlinks'
warn(format(SYMLINK_LOOP_ERROR, symlinked, real_path))
raise Error, 'Failed due to looped symlinks'
end
end
end
Expand Down