-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rule for
rand(Bool)
instead of rand() < 0.5
- Loading branch information
1 parent
9322f67
commit 43137c8
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ruleid: rand-bool | ||
rand() < 0.5 | ||
|
||
function some_rand_function(x) | ||
#ruleid: rand-bool | ||
if rand() < 0.5 | ||
println("Random") | ||
end | ||
end | ||
|
||
#ok: rand-bool | ||
rand() < 0.7 # this is fine | ||
|
||
#ok: rand-bool | ||
flag = rand(Bool) | ||
|
||
#ruleid: rand-bool | ||
if some_flag && rand() < 0.5 || other_flag | ||
println("Random") | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
rules: | ||
- id: rand-bool | ||
pattern-either: | ||
- pattern: rand() < 0.5 | ||
- pattern: Base.rand() < 0.5 | ||
fix: rand(Bool) | ||
message: To get a random Boolean, use `rand(Bool)`. | ||
languages: | ||
- julia | ||
severity: WARNING | ||
metadata: | ||
category: best-practice | ||
license: LGPL | ||
|