|
4 | 4 | shared_examples 'common behavior' do |keyword, runtime_error|
|
5 | 5 | it "reports an offense for a #{keyword} with #{runtime_error}" do
|
6 | 6 | expect_offense(<<~RUBY, keyword: keyword, runtime_error: runtime_error)
|
7 |
| - %{keyword} %{runtime_error}, msg |
8 |
| - ^{keyword}^^{runtime_error}^^^^^ Redundant `RuntimeError` argument can be removed. |
| 7 | + %{keyword} %{runtime_error}, "message" |
| 8 | + ^{keyword}^^{runtime_error}^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed. |
9 | 9 | RUBY
|
10 | 10 |
|
11 | 11 | expect_correction(<<~RUBY)
|
12 |
| - #{keyword} msg |
| 12 | + #{keyword} "message" |
13 | 13 | RUBY
|
14 | 14 | end
|
15 | 15 |
|
16 | 16 | it "reports an offense for a #{keyword} with #{runtime_error} and ()" do
|
17 | 17 | expect_offense(<<~RUBY, keyword: keyword, runtime_error: runtime_error)
|
18 |
| - %{keyword}(%{runtime_error}, msg) |
19 |
| - ^{keyword}^^{runtime_error}^^^^^^ Redundant `RuntimeError` argument can be removed. |
| 18 | + %{keyword}(%{runtime_error}, "message") |
| 19 | + ^{keyword}^^{runtime_error}^^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed. |
20 | 20 | RUBY
|
21 | 21 |
|
22 | 22 | expect_correction(<<~RUBY)
|
23 |
| - #{keyword}(msg) |
| 23 | + #{keyword}("message") |
24 | 24 | RUBY
|
25 | 25 | end
|
26 | 26 |
|
27 | 27 | it "reports an offense for a #{keyword} with #{runtime_error}.new" do
|
28 | 28 | expect_offense(<<~RUBY, keyword: keyword, runtime_error: runtime_error)
|
29 |
| - %{keyword} %{runtime_error}.new msg |
30 |
| - ^{keyword}^^{runtime_error}^^^^^^^^ Redundant `RuntimeError.new` call can be replaced with just the message. |
| 29 | + %{keyword} %{runtime_error}.new "message" |
| 30 | + ^{keyword}^^{runtime_error}^^^^^^^^^^^^^^ Redundant `RuntimeError.new` call can be replaced with just the message. |
31 | 31 | RUBY
|
32 | 32 |
|
33 | 33 | expect_correction(<<~RUBY)
|
34 |
| - #{keyword} msg |
| 34 | + #{keyword} "message" |
35 | 35 | RUBY
|
36 | 36 | end
|
37 | 37 |
|
38 | 38 | it "reports an offense for a #{keyword} with #{runtime_error}.new" do
|
39 | 39 | expect_offense(<<~RUBY, keyword: keyword, runtime_error: runtime_error)
|
40 |
| - %{keyword} %{runtime_error}.new(msg) |
41 |
| - ^{keyword}^^{runtime_error}^^^^^^^^^ Redundant `RuntimeError.new` call can be replaced with just the message. |
| 40 | + %{keyword} %{runtime_error}.new("message") |
| 41 | + ^{keyword}^^{runtime_error}^^^^^^^^^^^^^^^ Redundant `RuntimeError.new` call can be replaced with just the message. |
42 | 42 | RUBY
|
43 | 43 |
|
44 | 44 | expect_correction(<<~RUBY)
|
45 |
| - #{keyword} msg |
| 45 | + #{keyword} "message" |
46 | 46 | RUBY
|
47 | 47 | end
|
48 | 48 |
|
49 | 49 | it "accepts a #{keyword} with #{runtime_error} if it does not have 2 args" do
|
50 |
| - expect_no_offenses("#{keyword} #{runtime_error}, msg, caller") |
| 50 | + expect_no_offenses("#{keyword} #{runtime_error}, 'message', caller") |
51 | 51 | end
|
52 | 52 |
|
53 | 53 | it 'accepts rescue w/ non redundant error' do
|
54 |
| - expect_no_offenses "#{keyword} OtherError, msg" |
| 54 | + expect_no_offenses "#{keyword} OtherError, 'message'" |
55 | 55 | end
|
56 | 56 | end
|
57 | 57 |
|
58 | 58 | include_examples 'common behavior', 'raise', 'RuntimeError'
|
59 | 59 | include_examples 'common behavior', 'raise', '::RuntimeError'
|
60 | 60 | include_examples 'common behavior', 'fail', 'RuntimeError'
|
61 | 61 | include_examples 'common behavior', 'fail', '::RuntimeError'
|
| 62 | + |
| 63 | + it 'registers an offense for raise with RuntimeError, "#{message}"' do |
| 64 | + expect_offense(<<~'RUBY') |
| 65 | + raise RuntimeError, "#{message}" |
| 66 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed. |
| 67 | + RUBY |
| 68 | + |
| 69 | + expect_correction(<<~'RUBY') |
| 70 | + raise "#{message}" |
| 71 | + RUBY |
| 72 | + end |
| 73 | + |
| 74 | + it 'registers an offense for raise with RuntimeError, `command`' do |
| 75 | + expect_offense(<<~RUBY) |
| 76 | + raise RuntimeError, `command` |
| 77 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed. |
| 78 | + RUBY |
| 79 | + |
| 80 | + expect_correction(<<~RUBY) |
| 81 | + raise `command` |
| 82 | + RUBY |
| 83 | + end |
| 84 | + |
| 85 | + it 'registers an offense for raise with RuntimeError, Object.new' do |
| 86 | + expect_offense(<<~RUBY) |
| 87 | + raise RuntimeError, Object.new |
| 88 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed. |
| 89 | + RUBY |
| 90 | + |
| 91 | + expect_correction(<<~RUBY) |
| 92 | + raise Object.new.to_s |
| 93 | + RUBY |
| 94 | + end |
| 95 | + |
| 96 | + it 'registers an offense for raise with RuntimeError.new, Object.new and parans' do |
| 97 | + expect_offense(<<~RUBY) |
| 98 | + raise RuntimeError.new(Object.new) |
| 99 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError.new` call can be replaced with just the message. |
| 100 | + RUBY |
| 101 | + |
| 102 | + expect_correction(<<~RUBY) |
| 103 | + raise Object.new.to_s |
| 104 | + RUBY |
| 105 | + end |
| 106 | + |
| 107 | + it 'registers an offense for raise with RuntimeError.new, Object.new no parens' do |
| 108 | + expect_offense(<<~RUBY) |
| 109 | + raise RuntimeError.new Object.new |
| 110 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError.new` call can be replaced with just the message. |
| 111 | + RUBY |
| 112 | + |
| 113 | + expect_correction(<<~RUBY) |
| 114 | + raise Object.new.to_s |
| 115 | + RUBY |
| 116 | + end |
| 117 | + |
| 118 | + it 'registers an offense for raise with RuntimeError, valiable' do |
| 119 | + expect_offense(<<~RUBY) |
| 120 | + raise RuntimeError, valiable |
| 121 | + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Redundant `RuntimeError` argument can be removed. |
| 122 | + RUBY |
| 123 | + |
| 124 | + expect_correction(<<~RUBY) |
| 125 | + raise valiable.to_s |
| 126 | + RUBY |
| 127 | + end |
62 | 128 | end
|
0 commit comments