-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Use Rule
for FileNoqaDirective
s
#18966
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
Conversation
Summary -- See #18946 (comment). Test Plan -- Existing tests
CodSpeed Instrumentation Performance ReportMerging #18966 will not alter performanceComparing Summary
Benchmarks breakdown
|
|
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.
I've a small perf recommendation to reduce the number of Rule::parse
call
@@ -51,11 +51,16 @@ pub(crate) fn check_noqa( | |||
continue; | |||
}; | |||
|
|||
if *code == Rule::BlanketNOQA.noqa_code() { | |||
let Ok(rule) = Rule::from_code(code) else { |
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.
Do we have a short-circuit path somewhere that skips iterating over all diagnostics if there are no noqa
codes at all?
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.
I don't think so, but that's a good idea. I added
if file_noqa_directives.is_empty() && noqa_directives.is_empty() {
return Vec::new();
}
to the top of this function, along with those two is_empty
methods.
continue; | ||
} | ||
|
||
if exemption.contains(code) { | ||
if exemption.includes(rule) { |
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.
Should we add (or use) a method includes_code
that accepts a secondary code instead of the rule
. That would allow us to defer the rule parsing up to the point where we've found a suppression comment (which should be the exception).
To avoid calling Noqa::to_string
, we can add a method Noqa::matches_code(code: &str)
which can match the string without allocationg
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.
Ah yeah, I already added FileExemption::contains_secondary_code
but I can call it before this to bail out earlier without parsing the rule code.
Summary
See #18946 (comment).
Test Plan
Existing tests