crystal-ameba / ameba

A static code analysis tool for Crystal
https://crystal-ameba.github.io
MIT License
514 stars 35 forks source link

[Feature Request] Unused `rescue` variable name #462

Open Blacksmoke16 opened 2 months ago

Blacksmoke16 commented 2 months ago

I recently learned in a rescue block, you do not have to provide a variable name if you do not need access to the exception instance. E.g.

begin
  raise MyException.new("OH NO!")
rescue MyException
  puts "Rescued MyException"
end

# Output: Rescued MyException

works just fine.

Similar to how ameba will flag unused local/block variables, I'm wondering if it should also flag cases like:

begin
  raise MyException.new("OH NO!")
rescue ex : MyException
  puts "Rescued MyException"
end

where the ex variable is unused, and suggest changing it to rescue MyException.