Skip to content
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

Merged
merged 8 commits into from
Mar 4, 2025

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Feb 28, 2025

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.

@ntBre ntBre added internal An internal refactor or improvement parser Related to the parser labels Feb 28, 2025
Copy link
Contributor

github-actions bot commented Feb 28, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

…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.
@ntBre ntBre force-pushed the brent/caching-followup branch from b8a7569 to fe3bcbd Compare February 28, 2025 17:45
Copy link
Member

@dhruvmanila dhruvmanila left a 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

@@ -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 {
Copy link
Member

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 or is_invalid_syntax as the opposite of is_valid (we could also rename is_valid to has_valid_syntax or is_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 and has_no_syntax_errors?

@ntBre
Copy link
Contributor Author

ntBre commented Mar 3, 2025

Thanks for the suggestions! There are now four methods here:

  • has_valid_syntax
  • has_invalid_syntax
  • has_syntax_errors
  • has_no_syntax_errors

and I checked the references for each of the original methods and replaced negations with the new, negated methods.

I also inlined the is_valid variables that @dhruvmanila pointed out.

self.errors.is_empty()
}

/// Returns `true` if the parsed source code is invalid i.e., it has syntax errors.
Copy link
Member

@MichaReiser MichaReiser Mar 3, 2025

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.

Copy link
Contributor Author

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.

@ntBre ntBre merged commit 37fbe58 into main Mar 4, 2025
21 checks passed
@ntBre ntBre deleted the brent/caching-followup branch March 4, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement parser Related to the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants