Skip to content

Handle RescuedExceptionsVariableName with rescue_from #49

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

Open
anthony-robin opened this issue Apr 30, 2019 · 1 comment · May be fixed by #139 or #1440
Open

Handle RescuedExceptionsVariableName with rescue_from #49

anthony-robin opened this issue Apr 30, 2019 · 1 comment · May be fixed by #139 or #1440

Comments

@anthony-robin
Copy link
Contributor

anthony-robin commented Apr 30, 2019

Following what have been done in the Naming/RescuedExceptionsVariableName cop in the rubocop repo, we should also handle the Rails version that use rescue_from:

class MyController < ApplicationController
  rescue_from MyException do |exception| # <= should be flagged with an offense
    # do something
  end
end

Should this cop read the configuration of Naming/RescuedExceptionsVariableName or have its own duplicated ?

@anthony-robin anthony-robin changed the title Handle RescuedExceptionsVariableName with `rescue_from Handle RescuedExceptionsVariableName with rescue_from Apr 30, 2019
@koic
Copy link
Member

koic commented Jul 3, 2019

I think it is better to use PreferredName config value of Naming/RescuedExceptionsVariableName cop if the purpose is to make exception variable names consistent.

anthony-robin pushed a commit to anthony-robin/rubocop-rails that referenced this issue Oct 13, 2019
Follows rubocop/rubocop#7122
Closes rubocop#49

Inspired from @pocke [refactoring][1] in the `Naming/RescuedExceptionsVariableName` cop, this PR
handle the `rescue_from` Rails version.

Obstructing points:

- As discussed [in this comment][2], the `PreferredName` config should not be duplicated but read from the
`Naming/RescuedExceptionsVariableName` cop.
 How can I read the config from another cop ? Is there already some example of cop working this way ?

- I haven't been able to make the parser to not take the `||` of the block arguments which make the
offending message being `|my_var|` instead of `my_var`.
 What is the way to avoid this ?

[1]: rubocop/rubocop#7122
[2]: rubocop#49 (comment)
@anthony-robin anthony-robin linked a pull request Oct 13, 2019 that will close this issue
8 tasks
anthony-robin pushed a commit to anthony-robin/rubocop-rails that referenced this issue Oct 13, 2019
Follows rubocop/rubocop#7122
Closes rubocop#49

Inspired from @pocke [refactoring][1] in the `Naming/RescuedExceptionsVariableName` cop, this PR
handle the `rescue_from` Rails version.

Obstructing points:

- As discussed [in this comment][2], the `PreferredName` config should not be duplicated but read from the
`Naming/RescuedExceptionsVariableName` cop.
 How can I read the config from another cop ? Is there already some example of cop working this way ?

- I haven't been able to make the parser to not take the `||` of the block arguments which make the
offending message being `|my_var|` instead of `my_var`.
 What is the way to avoid this ?

[1]: rubocop/rubocop#7122
[2]: rubocop#49 (comment)
ydakuka pushed a commit to ydakuka/rubocop-rails that referenced this issue Feb 13, 2025
Follows rubocop/rubocop#7122
Closes rubocop#49

Inspired from @pocke [refactoring][1] in the `Naming/RescuedExceptionsVariableName` cop, this PR
handle the `rescue_from` Rails version.

Obstructing points:

- As discussed [in this comment][2], the `PreferredName` config should not be duplicated but read from the
`Naming/RescuedExceptionsVariableName` cop.
 How can I read the config from another cop ? Is there already some example of cop working this way ?

- I haven't been able to make the parser to not take the `||` of the block arguments which make the
offending message being `|my_var|` instead of `my_var`.
 What is the way to avoid this ?

[1]: rubocop/rubocop#7122
[2]: rubocop#49 (comment)
ydakuka added a commit to ydakuka/rubocop-rails that referenced this issue Feb 15, 2025
Ensures that rescued exception variables are named as expected.

The `PreferredName` config option specifies the required name of the variable.
Its default is `e`, as referenced from `Naming/RescuedExceptionsVariableName`.
@ydakuka ydakuka linked a pull request Feb 15, 2025 that will close this issue
9 tasks
ydakuka added a commit to ydakuka/rubocop-rails that referenced this issue Feb 15, 2025
Ensures that rescued exception variables are named as expected.

The `PreferredName` config option specifies the required name of the variable.
Its default is `e`, as referenced from `Naming/RescuedExceptionsVariableName`.
ydakuka added a commit to ydakuka/rubocop-rails that referenced this issue Feb 17, 2025
Ensures that rescued exception variables are named as expected.

The `PreferredName` config option specifies the required name of the variable.
Its default is `e`, as referenced from `Naming/RescuedExceptionsVariableName`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants