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

Style/RaiseArgs autocorrection removes part of code with compact style #10622

Closed
DocX opened this issue May 11, 2022 · 0 comments · Fixed by #10623
Closed

Style/RaiseArgs autocorrection removes part of code with compact style #10622

DocX opened this issue May 11, 2022 · 0 comments · Fixed by #10623
Labels

Comments

@DocX
Copy link

@DocX DocX commented May 11, 2022

When running rubocop -a with autocorrect enabled with following configuration

Style/RaiseArgs:
  Enabled: true
  EnforcedStyle: compact

on this code:

raise MyError.new(data: "mydata"), "some error message"

Expected behavior

Should autocorrect to

raise MyError.new("some error message", data: "mydata")

or error as not-auto correctable but violating the cmopact style

Actual behavior

replaces the code with:

raise MyError.new("some error message")

removing the data: "mydata" parameter silently

Steps to reproduce the problem

Run rubocop -a with the configuration and code above

RuboCop version

1.29.0 (using Parser 3.1.2.0, rubocop-ast 1.17.0, running on ruby 3.1.0 x86_64-darwin20)
@koic koic added the bug label May 11, 2022
koic added a commit to koic/rubocop that referenced this issue May 11, 2022
Fixes rubocop#10622.

This PR fixes a false positive for `Style/RaiseArgs` when
error type class constructor with keyword arguments and message argument.

The signature of `raise` is below.

```ruby
raiseclick to toggle source
raise(string, cause: $!)
raise(exception [, string [, array]], cause: $!)
```

https://ruby-doc.org/core-3.1.0/Kernel.html#method-i-raise

So rubocop#10622 would be a false positive because `raise MyError.new(data: 'mydata'), 'message'` and
`raise MyError.new('message', data: 'mydata')` are incompatible,
koic added a commit to koic/rubocop that referenced this issue May 11, 2022
Fixes rubocop#10622.

This PR fixes a false positive for `Style/RaiseArgs` when
error type class constructor with keyword arguments and message argument.

The signature of `raise` is below.

```ruby
raise
raise(string, cause: $!)
raise(exception [, string [, array]], cause: $!)
```

https://ruby-doc.org/core-3.1.0/Kernel.html#method-i-raise

So rubocop#10622 would be a false positive because `raise MyError.new(data: 'mydata'), 'message'` and
`raise MyError.new('message', data: 'mydata')` are incompatible,
koic added a commit to koic/rubocop that referenced this issue May 11, 2022
Fixes rubocop#10622.

This PR fixes a false positive for `Style/RaiseArgs` when
error type class constructor with keyword arguments and message argument.

The signature of `raise` is below.

```ruby
raise
raise(string, cause: $!)
raise(exception [, string [, array]], cause: $!)
```

https://ruby-doc.org/core-3.1.0/Kernel.html#method-i-raise

So rubocop#10622 would be a false positive because `raise MyError.new(data: 'mydata'), 'message'` and
`raise MyError.new('message', data: 'mydata')` are incompatible.
bbatsov pushed a commit that referenced this issue May 12, 2022
Fixes #10622.

This PR fixes a false positive for `Style/RaiseArgs` when
error type class constructor with keyword arguments and message argument.

The signature of `raise` is below.

```ruby
raise
raise(string, cause: $!)
raise(exception [, string [, array]], cause: $!)
```

https://ruby-doc.org/core-3.1.0/Kernel.html#method-i-raise

So #10622 would be a false positive because `raise MyError.new(data: 'mydata'), 'message'` and
`raise MyError.new('message', data: 'mydata')` are incompatible.
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