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

Cop for raise arguments doesn't account for a splat operator #3577

Closed
mattdowdell opened this issue Oct 6, 2016 · 1 comment
Closed

Cop for raise arguments doesn't account for a splat operator #3577

mattdowdell opened this issue Oct 6, 2016 · 1 comment

Comments

@mattdowdell
Copy link

Related to #552.

The following example causes an offense:

class MyException < StandardError
  def initialize(message, other_arg)
    super "#{message.inspect} -- #{other_arg.inspect}"
  end
end

args = ['message', 'other argument']

begin
  raise MyException.new(*args)
rescue MyException => exc
  puts exc.message
end

The offense here being "Provide an exception class and message as arguments to raise."

I think the example is relatively self explanatory in what it's trying to achieve, but let me know if there's any questions.

Expected behavior

Rubocop should either not have a problem with use of the splat operator in this case, or detect if the array has more than one argument before raising the offense.

RuboCop version

$ rubocop -V
0.43.0 (using Parser 2.3.1.4, running on ruby 2.3.0 x86_64-linux)
@jonas054
Copy link
Collaborator

jonas054 commented Oct 6, 2016

Rubocop should either not have a problem with use of the splat operator in this case, or detect if the array has more than one argument before raising the offense.

Yes. I think we should contend ourselves with not reporting when the splat operator is used, like in raise MyException.new(*args). Determining the size of the array is just too hard, generally speaking.

savef added a commit to savef/rubocop that referenced this issue Oct 7, 2016
…tted args

With the default style (exploded) one is typically allowed to use the compact style if passing multiple args into the constructor. However an offence was being generated if those args were splatted in, this changes that so there is no offence.

Also refactored the cop to use guard clauses to reduce nesting.
@bbatsov bbatsov closed this as completed in 024bb49 Oct 7, 2016
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
…tted args

With the default style (exploded) one is typically allowed to use the compact style if passing multiple args into the constructor. However an offence was being generated if those args were splatted in, this changes that so there is no offence.

Also refactored the cop to use guard clauses to reduce nesting.
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