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

Autofix results to invalid syntax when rubocop comment is removed. Style/RaiseArgs: EnforcedStyle: compact #9298

Closed
jlahtinen opened this issue Dec 28, 2020 · 0 comments · Fixed by #9299
Labels

Comments

@jlahtinen
Copy link

Testfiles

$ more .* *

::::::::::::::
.rubocop.yml
::::::::::::::

Style/RaiseArgs:
  EnforcedStyle: compact
AllCops:
  NewCops: enable

::::::::::::::
foo.rb
::::::::::::::

class Foo
  def bar; end

  def bar_bar # rubocop:disable Metrics/MethodLength
    @bars.map do |b|
      begin
        b.foo
      rescue A => e
        e
      end
    end
  end
end

All is fine if bar_bar is first method. So def bar; end is needed.

Running rubocop

$ rubocop -a

warning: parser/current is loading parser/ruby27, which recognizes
warning: 2.7.2-compliant syntax, but you are running 2.7.0.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Inspecting 1 file
E

Offenses:

foo.rb:1:1: E: Lint/Syntax: class definition in method body
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
class Foo
^^^^^
foo.rb:1:1: C: Style/Documentation: Missing top-level class documentation comment.
class Foo
^^^^^
foo.rb:1:1: C: [Correctable] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Foo
^
foo.rb:4:15: W: [Corrected] Lint/RedundantCopDisableDirective: Unnecessary disabling of Metrics/MethodLength.
  def bar_bar # rubocop:disable Metrics/MethodLength
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
foo.rb:4:19: E: Lint/Syntax: formal argument cannot be an instance variable
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
  def bar_bar     @bars.map do |b|
                  ^^^^^

1 file inspected, 5 offenses detected, 1 offense corrected, 1 more offense can be corrected with `rubocop -A`

Diff between actual result and expected

diff --git a/foo.rb b/foo.rb
index a421fb2..d09747d 100644
--- a/foo.rb
+++ b/foo.rb
@@ -1,7 +1,8 @@
 class Foo
   def bar; end
 
-  def bar_bar     @bars.map do |b|
+  def bar_bar
+    @bars.map do |b|
       begin
         b.foo
       rescue A => e
@koic koic added the bug label Dec 28, 2020
koic added a commit to koic/rubocop that referenced this issue Dec 29, 2020
…opDisableDirective`

Fixes rubocop#9298.

This PR fixes an incorrect auto-correct for `Lint/RedundantCopDisableDirective`
when there is a blank line before inline comment.
jonas054 added a commit that referenced this issue Dec 30, 2020
…ndant_cop_disable_directive

[Fix #9298] Fix an incorrect auto-correct for `Lint/RedundantCopDisableDirective`
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