-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcode.rb
75 lines (58 loc) · 1.47 KB
/
code.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true
# Raises "bad ordering of magic comments"
# frozen_string_literal: true
# encoding: ascii
# Raises "use of deprecated BigDecimal.new"
a = { 'hello' => 'world', 'testing' => BigDecimal.new(123.456, 3) }
# Raises "`while`/`until` detected in `begin` block"
begin
do_something
end while a == b
# Raises "multiple comparison detected"
x < y < z
10 <= x <= 20
# Raises "empty rescue block detected"
begin
bar
rescue
end
# Raises "redundant `else`-clause detected"
if bar
else
end
# Raises "unused method arguments detected"
def some_method(bar)
puts 'Hello'
end
# Raises "unreachable code detected"
def some_method
return
do_something
end
# Raises "top level return with argument detected"
return 1
# Raises "duplicate elsif block detected"
if x == 1
do_something
elsif x == 1
do_something_else
end
# Raises "Deprecated way of initializing OpenSSL::Cipher and OpenSSL::Digest"
OpenSSL::Cipher::AES.new(128, :GCM)
# Raises "put empty method definitions on a single line"
# Also raises "multiple methods with same name in the same scope" as we have a
# method with same name above
def some_method
end
# Raises "Invalid annotation keyword format detected"
def foo
# TODO Replace this with bar
do_something
end
# Raises "Use `Range#cover?` instead of `Range#include?`"
(1..9).include?(5)
my_hash = {}
# Raises "Hash merging can be replaced by hash key assignment"
my_hash.merge!('key': value)
# Raises "Use `size` instead of `count`"
[1, 2, 3].count