forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
useless_else_without_rescue.rb
45 lines (42 loc) · 1.03 KB
/
useless_else_without_rescue.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
module RuboCop
module Cop
module Lint
# This cop checks for useless `else` in `begin..end` without `rescue`.
#
# NOTE: This syntax is no longer valid on Ruby 2.6 or higher and
# this cop is going to be removed at some point the future.
#
# @example
#
# # bad
#
# begin
# do_something
# else
# do_something_else # This will never be run.
# end
#
# @example
#
# # good
#
# begin
# do_something
# rescue
# handle_errors
# else
# do_something_else
# end
class UselessElseWithoutRescue < Base
MSG = '`else` without `rescue` is useless.'
def on_new_investigation
processed_source.diagnostics.each do |diagnostic|
next unless diagnostic.reason == :useless_else
add_offense(diagnostic.location, severity: diagnostic.level)
end
end
end
end
end
end