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

SymbolProc may break code #2135

Closed
klippx opened this issue Aug 11, 2015 · 3 comments
Closed

SymbolProc may break code #2135

klippx opened this issue Aug 11, 2015 · 3 comments

Comments

@klippx
Copy link

klippx commented Aug 11, 2015

I have a piece of controller code like this:

class Api::SubstancesController < Api::BaseController
  ...
  def destroy
    super([:pharmaceut]) do |substance|
      substance.destroyable?
    end
  end
  ...
end

Rubocop wants to autocorrect this to:

> rubocop -a app/controllers/api/substances_controller.rb
Inspecting 1 file
E

Offenses:

app/controllers/api/substances_controller.rb:20:5: C: [Corrected] Pass &:destroyable? as an argument to  instead of a block.
    super([:pharmaceut]) do |substance|
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/controllers/api/substances_controller.rb:20:25: E: unexpected token tLPAREN2
    super([:pharmaceut])(&:destroyable?)
                        ^
app/controllers/api/substances_controller.rb:42:1: E: unexpected token $end

1 file inspected, 3 offenses detected, 1 offense corrected

Rubocop even detects two Errors - all due to the code it generated on its own.

The final result:

  def destroy
    super([:pharmaceut])(&:destroyable?)
  end

As you can see this is clearly erroneous syntax.

Version

> rubocop -v
warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.6-compliant syntax, but you are running 2.1.5.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
0.33.0

I have tried to add 'super' to ignored methods in config (seeing this cop inspects this configuration attribute) but that did not help

Style/BlockDelimiters:
  IgnoredMethods:
    - super
    - lambda
    - proc
    - it
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 21, 2015

super is not a method. We need to add an exception for it in the code.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 21, 2015

Or even better - we should auto-correct code with super as:

def destroy
    super([:pharmaceut], &:destroyable?)
end

@klippx
Copy link
Author

klippx commented Aug 24, 2015

Thanks, @bbatsov !

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

No branches or pull requests

2 participants