-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Document LinterResult::has_syntax_error
and add Parsed::has_no_errors
#16443
Conversation
|
…ors` Summary -- This is a follow up addressing the comments on #16425. As @dhruvmanila pointed out, the naming is a bit tricky. I went with `has_no_errors` to try to differentiate it from `is_valid`. It actually ends up negated in most uses, so it would be more convenient to have `has_any_errors` or `has_errors`, but I thought it would sound too much like the opposite of `is_valid` in that case. I'm definitely open to suggestions here. Test Plan -- Existing tests.
b8a7569
to
fe3bcbd
Compare
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.
Thanks for doing this.
Regardless of the name choice, I think it might be useful to keep it consistent throughout the code base i.e., keep the method name same as variable name and field name on LinterResult
crates/ruff_python_parser/src/lib.rs
Outdated
@@ -346,10 +346,20 @@ impl<T> Parsed<T> { | |||
/// | |||
/// Note that this does not include version-related | |||
/// [`unsupported_syntax_errors`](Parsed::unsupported_syntax_errors). | |||
/// | |||
/// See [`has_no_errors`](Parsed::has_no_errors) for a version that takes these into account. | |||
pub fn is_valid(&self) -> bool { |
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.
Not specifically related to this PR but it seems a good opportunity. How about:
- Add a method
has_invalid_syntax
oris_invalid_syntax
as the opposite ofis_valid
(we could also renameis_valid
tohas_valid_syntax
oris_valid_syntax
. It's still somewhat ambigious by what it mean but I think it works well with unsupported syntax (which technically is valid, it's just unsupported) - Rename the new method to
has_syntax_errors
andhas_no_syntax_errors
?
Thanks for the suggestions! There are now four methods here:
and I checked the references for each of the original methods and replaced negations with the new, negated methods. I also inlined the |
crates/ruff_python_parser/src/lib.rs
Outdated
self.errors.is_empty() | ||
} | ||
|
||
/// Returns `true` if the parsed source code is invalid i.e., it has syntax errors. |
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 think i'd prefer to use the term parse errors or a more detailed description over using syntax errors. The description otherwise doesn't make it clear how it is different from has_syntax_erros
.
But it's tricky with all those being syntax errors.
Another option is to rename unsupported_syntax_errors
to has_unsupported_syntax
(which would match has_invalid_syntax
) or has_no_unsupported_syntax
.
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.
Oh good catch. I can even link to the ParseError
and UnsupportedSyntaxError
types like I did in the new methods.
Summary
This is a follow up addressing the comments on #16425. As @dhruvmanila pointed out, the naming is a bit tricky. I went with
has_no_errors
to try to differentiate it fromis_valid
. It actually ends up negated in most uses, so it would be more convenient to havehas_any_errors
orhas_errors
, but I thought it would sound too much like the opposite ofis_valid
in that case. I'm definitely open to suggestions here.Test Plan
Existing tests.