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

Regression: Lint/SuppressedException false positive at singleton method def #8096

Closed
Tietew opened this issue Jun 4, 2020 · 1 comment · Fixed by #8097
Closed

Regression: Lint/SuppressedException false positive at singleton method def #8096

Tietew opened this issue Jun 4, 2020 · 1 comment · Fixed by #8097
Labels

Comments

@Tietew
Copy link
Contributor

Tietew commented Jun 4, 2020

Lint/SuppressedException (with AllowComments: true) is detected at direct rescue in singleton method def.

class Foo
  def self.foo
    something
  rescue FooException
    # Ok
  end
end

Expected behavior

No offences detected.

Actual behavior

Lint/SuppressedException is detected at:

  • direct rescue (def ... rescue ... end) with/without exception class in singleton method def

Not detected at:

  • direct (def ... rescue ... end) rescue in non-singleton def
  • indirect (begin ... rescue ... end) rescue

Steps to reproduce the problem

test.rb

def foo
  something
rescue DirectRescueInBareDef
  # OK
end

def self.foo
  something
rescue DirectRescueInBareSingletonDef
  # OK
end

def bar
  begin
    something
  rescue IndirectRescueInBareDef
    # OK
  end
end

def bar
  begin
    something
  rescue IndirectRescueInBareSingletonDef
    # OK
  end
end

def baz
  something
rescue # DirectRescueInBareDef
  # OK
end

def self.baz
  something
rescue # DirectRescueInBareSingletonDef
  # OK
end

class Foo
  def foo
    something
  rescue DirectRescueInMethod
    # OK
  end

  def self.foo
    something
  rescue DirectRescueInSingletonMethod
    # OK
  end

  def bar
    begin
      something
    rescue IndirectRescueInMethod
      # OK
    end
  end

  def self.bar
    begin
      something
    rescue IndirectRescueInSingletonMethod
      # OK
    end
  end

  def baz
    something
  rescue # DirectRescueInMethod
    # OK
  end

  def self.baz
    something
  rescue # DirectRescueInSingletonMethod
    # OK
  end
end
$ bundle exec rubocop test.rb --only Lint/SuppressedException
Inspecting 1 file
W

Offenses:

test.rb:9:1: W: Lint/SuppressedException: Do not suppress exceptions.
rescue DirectRescueInBareSingletonDef
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:37:1: W: Lint/SuppressedException: Do not suppress exceptions.
rescue # DirectRescueInBareSingletonDef
^^^^^^
test.rb:50:3: W: Lint/SuppressedException: Do not suppress exceptions.
  rescue DirectRescueInSingletonMethod
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
test.rb:78:3: W: Lint/SuppressedException: Do not suppress exceptions.
  rescue # DirectRescueInSingletonMethod
  ^^^^^^

1 file inspected, 4 offenses detected

Bisect result

$ git bisect start master v0.84.0
Bisecting: 50 revisions left to test after this (roughly 6 steps)
[330f46d272d393f3e2b2a751d2876485679932d4] Clean up Layout/HeredocIndentation specs
$ git bisect run ./test.sh
(...snip...)
ebc19adbaef36733192af891995bdc6ef34cccab is the first bad commit
commit ebc19adbaef36733192af891995bdc6ef34cccab
Author: Koichi ITO <koic.ito@gmail.com>
Date:   Fri May 22 14:15:42 2020 +0900

    [Fix #8008] Fix an error for `Lint/SuppressedException`

    Fixes #8008.

    This PR fixes an error for `Lint/SuppressedException`
    when empty rescue block in `def`.

:100644 100644 34a336446d643ccc97f5b05f4d9fb0e2fe9be943 86585f83c4c1e049b58dacfbab40e584051ee17f M      CHANGELOG.md
:040000 040000 740733ff0d694dac78494e0cea73d7fed8196640 9f80846d6356767f2928cc1f1bf7bc0d55278a1d M      lib
:040000 040000 268ae54cd2ea411993220170c979c48a6690ffdc 8790220cbfc9f8ba32626f387992043bf29c894f M      spec
bisect run success

RuboCop version

$ [bundle exec] rubocop -V
0.85.0 (using Parser 2.7.1.3, rubocop-ast 0.0.3, running on ruby 2.6.5 x86_64-linux)
@Tietew
Copy link
Contributor Author

Tietew commented Jun 4, 2020

#8082 seems not to resolve this.

@koic koic added the bug label Jun 4, 2020
koic added a commit to koic/rubocop that referenced this issue Jun 4, 2020
Fixes rubocop#8096

This PR fixes a false positive for `Lint/SuppressedException`
when empty rescue block in defs.

```console
% cat example.rb
def self.foo
rescue Foo
  # ok
end

% bundle exec rubocop --only Lint/SuppressedException
(snip)

Inspecting 1 file
W

Offenses:

example.rb:2:1: W: Lint/SuppressedException: Do not suppress exceptions.
rescue Foo
^^^^^^^^^^

1 file inspected, 1 offense detected
```
bbatsov pushed a commit that referenced this issue Jun 5, 2020
Fixes #8096

This PR fixes a false positive for `Lint/SuppressedException`
when empty rescue block in defs.

```console
% cat example.rb
def self.foo
rescue Foo
  # ok
end

% bundle exec rubocop --only Lint/SuppressedException
(snip)

Inspecting 1 file
W

Offenses:

example.rb:2:1: W: Lint/SuppressedException: Do not suppress exceptions.
rescue Foo
^^^^^^^^^^

1 file inspected, 1 offense detected
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants