-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Combine lint and syntax error handling #18471
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
|
dhruvmanila
left a comment
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.
This looks pretty straightforward!
crates/ruff_server/src/lint.rs
Outdated
| code: rule.noqa_code().to_string(), | ||
| code: code?.to_string(), |
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.
nit: we could short-circuit if code is None and avoid generating the edits although I think currently it's only the syntax errors that doesn't have code and those doesn't have fixes, so maybe this isn't that useful
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.
Yeah, I think the fix.is_some() || noqa_edit.is_some() condition should virtually guarantee this is never None, but I can move it to the top of the closure just in case. Thanks!
MichaReiser
left a comment
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.
Sweet
Summary
This is a spin-off from #18447 (comment) to avoid using
Message::noqa_codeto differentiate between lints and syntax errors. I went through all of the calls onmainand on the branch from #18447, and the instance inruff_servernoted in the linked comment was actually the primary place where this was being done. Other calls tonoqa_codeare typically some variation ofmessage.noqa_code().map_or(String::new, format!(...)), with the major exception of the gitlab output format:ruff/crates/ruff_linter/src/message/gitlab.rs
Lines 93 to 105 in a120610
which obviously assumes that
Nonemeans syntax error. A simple fix here would be to usemessage.name()forcheck_nameinstead of the noqa code, but I'm not sure how breaking that would be. This could just be:In that case. This sounds reasonable based on the Code Quality report format docs:
Test Plan
Existing tests