-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow nominator for CI checks on banned calls #143
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
To prevent CI failing for approved instance of banned words, add a comment: #[allow_ci] | ||
''' | ||
|
||
import os | ||
|
||
banned = ["unwrap(", "panic!("] | ||
|
@@ -9,14 +13,12 @@ print("Files to check: %s" % srcs) | |
|
||
failed = False | ||
for f in srcs: | ||
print("Checking file %s" % f) | ||
contents = open("src/%s" % f, "r").read().split("#[cfg(test)]")[0] | ||
for b in banned: | ||
if b not in contents: | ||
continue | ||
|
||
failed = True | ||
print("File %s calls banned function: %s)" % (f, b)) | ||
pass | ||
|
||
with open("src/" + f) as src_file: | ||
for line_no, line in enumerate(src_file): | ||
for b in banned: | ||
if b not in line or "#[allow_ci]" in line: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would need to check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this seems to work well: https://github.com/keylime/rust-keylime/runs/1413393155?check_suite_focus=true The previous line is just to go over the banned dict , I think this could likely be optimized a bit better using regexp, but we don't need to worry about performance too much There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it looks like it was not even working before (it was allowing a load of unwraps). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yeah, that's a lot of unwraps - it's good to have this as an improvement. I am seeing the line numbers reported as one off from where the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My concern is more about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now, so I planned to have it on the same line as the instance of panic! / unwrap. This is how we do it on the bandit project
Here is an example of it working: (Note, this is before you're change to increment the line by +1 so it records the correct line number). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, this makes much more sense now. Thanks for the clarification! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no worries. what you would you like to do around the naming convention? I went with allow_ci rather than a mention of panics (as it also covers unwraps as well)? I am open to suggestions here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
continue | ||
failed = True | ||
print("File %s on line number %s calls banned function: %s)" % (f, line_no + 1, b)) | ||
pass | ||
exit(failed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the more I think about it, it may be more readable to call this something like
#[allow_panic]
.