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

Conversation

ColinDKelley
Copy link
Collaborator

@ColinDKelley ColinDKelley commented Nov 6, 2020

I made an attempt to address issue #504 :

After the above tuning and auto-correcting, there were 15 remaining offenses:
lib/listen/event/processor.rb:73:9: C: Naming/MemoizedInstanceVariableName: Memoized variable @first_unprocessed_event_time does not match method name _remember_time_of_first_unprocessed_event. Use @_remember_time_of_first_unprocessed_event instead.
        @first_unprocessed_event_time ||= _timestamp
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/listen/options.rb:19:5: C: Style/MissingRespondToMissing: When using method_missing, define respond_to_missing?.
    def method_missing(name, *_) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/listen/thread.rb:18:9: W: Lint/RescueException: Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
        rescue Exception => ex ...
        ^^^^^^^^^^^^^^^^^^^^^^
lib/listen/thread.rb:21:9: C: Style/MultilineBlockChain: Avoid multi-line chains of blocks.
        end.tap do |thread|
        ^^^^^^^
lib/listen/thread.rb:28:26: C: Naming/MethodParameterName: Method parameter must be at least 3 characters long.
      def _log_exception(ex, thread_name, caller_stack)
                         ^^
lib/listen/thread.rb:34:34: C: Naming/MethodParameterName: Method parameter must be at least 3 characters long.
      def _exception_with_causes(ex)
                                 ^^
listen.gemspec:30:31: C: Gemspec/RequiredRubyVersion: required_ruby_version (2.2, declared in listen.gemspec) and TargetRubyVersion (2.6, which may be specified in .rubocop.yml) should be equal.
  gem.required_ruby_version = '>= 2.2.7'
                              ^^^^^^^^^^
spec/acceptance/listen_spec.rb:20:48: W: Lint/LiteralAsCondition: Literal 'both' appeared as a condition.
      case ENV['TEST_LISTEN_ADAPTER_MODES'] || 'both'
                                               ^^^^^^
spec/lib/listen/directory_spec.rb:16:21: C: Naming/MethodParameterName: Method parameter must be at least 3 characters long.
  def fake_children(ex, dir, *args, &block)
                    ^^
spec/lib/listen/thread_spec.rb:32:151: C: Layout/LineLength: Line is too long. [177/150]
                                 with(/Exception rescued in listen-worker_thread:\nArgumentError: boom!\n.*\/listen\/thread\.rb.*--- Thread.new ---.*\/listen\/thread_spec\.rb/m)
                                                                                                                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/lib/listen/thread_spec.rb:54:34: C: Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
                                 .with(/RuntimeError: nested outer\n--- Caused by: ---\nRuntimeError: nested inner\n--- Caused by: ---\nArgumentError: boom!/)
                                 ^
spec/lib/listen/thread_spec.rb:54:151: C: Layout/LineLength: Line is too long. [158/150]
                                 .with(/RuntimeError: nested outer\n--- Caused by: ---\nRuntimeError: nested inner\n--- Caused by: ---\nArgumentError: boom!/)
                                                                                                                                                      ^^^^^^^^
spec/support/acceptance_helper.rb:46:5: C: Security/Open: The use of Kernel#open is a serious security risk.
    open(path, 'a') { |f| f.write('foo') }
    ^^^^
spec/support/acceptance_helper.rb:59:5: C: Security/Open: The use of Kernel#open is a serious security risk.
    open(path, 'w') { |f| f.write('foo') }
    ^^^^
spec/support/acceptance_helper.rb:181:3: W: Lint/DuplicateMethods: Method ListenerWrapper#changes is defined at both spec/support/acceptance_helper.rb:146 and spec/support/acceptance_helper.rb:181.
  def changes
  ^^^^^^^^^^^
After fixing the easy ones, there are 5 offenses left:
lib/listen/options.rb:19:5: C: Style/MissingRespondToMissing: When using method_missing, define respond_to_missing?.
    def method_missing(name, *_) ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/listen/thread.rb:18:9: W: Lint/RescueException: Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
        rescue Exception => exception ...
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
listen.gemspec:30:31: C: Gemspec/RequiredRubyVersion: required_ruby_version (2.2, declared in listen.gemspec) and TargetRubyVersion (2.6, which may be specified in .rubocop.yml) should be equal.
  gem.required_ruby_version = '>= 2.2.7'
                              ^^^^^^^^^^
spec/support/acceptance_helper.rb:46:5: C: Security/Open: The use of Kernel#open is a serious security risk.
    open(path, 'a') { |f| f.write('foo') }
    ^^^^
spec/support/acceptance_helper.rb:59:5: C: Security/Open: The use of Kernel#open is a serious security risk.
    open(path, 'w') { |f| f.write('foo') }
    ^^^^

65 files inspected, 5 offenses detected

Copy link

@houndci-bot houndci-bot left a comment

Choose a reason for hiding this comment

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

Some files could not be reviewed due to errors:

.rubocop.yml: Layout/EmptyLineAfterGuardClause has the wrong namespace - shou...
.rubocop.yml: Layout/EmptyLineAfterGuardClause has the wrong namespace - should be Style
Warning: unrecognized cop Lint/SuppressedException found in .rubocop.yml
Warning: unrecognized cop Layout/HashAlignment found in .rubocop.yml
Warning: unrecognized cop Layout/HeredocIndentation found in .rubocop.yml
Warning: unrecognized cop Lint/RedundantRequireStatement found in .rubocop.yml
Warning: unrecognized cop Naming/RescuedExceptionsVariableName found in .rubocop.yml
Error: Unknown Ruby version 2.6 found in `TargetRubyVersion` parameter (in .rubocop.yml).
Supported versions: 2.1, 2.2, 2.3, 2.4, 2.5

@ColinDKelley
Copy link
Collaborator Author

@KapilSachdev What do you think?

lib/listen/thread.rb Outdated Show resolved Hide resolved
spec/lib/listen/thread_spec.rb Outdated Show resolved Hide resolved
spec/lib/listen/thread_spec.rb Outdated Show resolved Hide resolved
lib/listen/thread.rb Outdated Show resolved Hide resolved
.rubocop.yml Outdated Show resolved Hide resolved
@@ -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.

Comment on lines 165 to 178
@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)

unless callback == :track_changes
callback.call(modified, added, removed)
end
end
else
Listen.send(*args)
end

Choose a reason for hiding this comment

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

Adding the assignment in the next line could help in less indentation spaces.

Suggested change
@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)
unless callback == :track_changes
callback.call(modified, added, removed)
end
end
else
Listen.send(*args)
end
@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)
unless callback == :track_changes
callback.call(modified, added, removed)
end
end
else
Listen.send(*args)
end

Copy link
Member

Choose a reason for hiding this comment

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

I also agree, this alignment change is a mess, and it should probably just be

@listener = if callback
  Listen.send(...)
else
  ...
end

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rubocop wouldn't tolerate that formatting. I put 10 minutes into finding an option that would, but I didn't find it. Instead, I tried the if on the next line and it was ok with that. Of course then it complained that the method was too long! So I moved an unless from leading to trailing. 🤦

745d0e3

Choose a reason for hiding this comment

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

I think below should help. However as you have used next line, you won't need this then. Next lines looks good to me.

Layout/EndAlignment:
  EnforcedStyleAlignWith: variable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @KapilSachdev. I made that EnforcedStyleAlignWith: variable change and put the @listener = code back the way it was, then ran rubocop -a -A. e1045d2

@ColinDKelley ColinDKelley linked an issue Nov 23, 2020 that may be closed by this pull request
@ColinDKelley ColinDKelley added this to the 3.3.2 milestone Nov 23, 2020
@ColinDKelley ColinDKelley force-pushed the issue-504/try-merging-invoca-.rubocop.yml branch from cfdd1f1 to a6b6b5d Compare November 23, 2020 21:17
spec/acceptance/listen_spec.rb Outdated Show resolved Hide resolved
spec/acceptance/listen_spec.rb Outdated Show resolved Hide resolved
spec/acceptance/listen_spec.rb Outdated Show resolved Hide resolved
spec/lib/listen/thread_spec.rb Outdated Show resolved Hide resolved
spec/lib/listen/thread_spec.rb Outdated Show resolved Hide resolved
spec/lib/listen/thread_spec.rb Outdated Show resolved Hide resolved
@ColinDKelley
Copy link
Collaborator Author

@KapilSachdev I merged up to latest master and applied all the changes in discussion here.

$ rubocop
Inspecting 65 files
.................................................................

65 files inspected, no offenses detected

lib/listen/record.rb Outdated Show resolved Hide resolved
lib/listen/record.rb Outdated Show resolved Hide resolved
@ColinDKelley ColinDKelley force-pushed the issue-504/try-merging-invoca-.rubocop.yml branch from ad57854 to c9a6205 Compare November 24, 2020 00:23
@ColinDKelley ColinDKelley force-pushed the issue-504/try-merging-invoca-.rubocop.yml branch from 39a2a4c to b2fbfaf Compare November 24, 2020 01:11
@ColinDKelley ColinDKelley merged commit b576ff6 into guard:master Nov 27, 2020
@ColinDKelley ColinDKelley deleted the issue-504/try-merging-invoca-.rubocop.yml branch November 27, 2020 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rubocop Usage
4 participants