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

Avoid caching files with unsupported syntax errors #16425

Merged
merged 3 commits into from
Feb 28, 2025

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Feb 27, 2025

Summary

This PR includes the new Parsed::unsupported_syntax_errors field when determining if a LinterResult has a syntax error. This prevents caching files with version-related syntax errors, which led to these errors only being reported on the first ruff run.

Fixes #16417 in combination with #16419, modulo the discussion split off into #16418.

Test Plan

New CLI test that reported no errors in the second case on main (see the first commit).

Verified

This commit was signed with the committer’s verified signature.
lunny Lunny Xiao

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@ntBre ntBre added bug Something isn't working preview Related to preview mode features labels Feb 27, 2025
Copy link
Contributor

github-actions bot commented Feb 27, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
has_syntax_error: !parsed.is_valid(),
has_syntax_error: !parsed.is_valid() || !parsed.unsupported_syntax_errors().is_empty(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have a separate version of is_valid method that checks both ParseError and UnsupportedSyntaxError which can then be used here. I'm not sure what to name the method though as both are syntax errors at the end 😅

@dhruvmanila dhruvmanila added the cache Related to Ruff cache label Feb 28, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I did a quick check that we aren't using the LintResult::has_syntax_errors for anything other than caching.

Can we update the documentation on LinterResult to make it explicit that this includes both syntax and unsupported syntax errors.

@MichaReiser MichaReiser merged commit 4a23756 into main Feb 28, 2025
21 checks passed
@MichaReiser MichaReiser deleted the brent/fix-syntax-error-caching branch February 28, 2025 08:58
dcreager added a commit that referenced this pull request Feb 28, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* main:
  [red-knot] Switch to a handwritten parser for mdtest error assertions (#16422)
  [red-knot] Disallow more invalid type expressions (#16427)
  Bump version to Ruff 0.9.9 (#16434)
  Check `LinterSettings::preview` for version-related syntax errors (#16429)
  Avoid caching files with unsupported syntax errors (#16425)
  Prioritize "bug" label for changelog sections (#16433)
  [`flake8-copyright`] Add links to applicable options (`CPY001`) (#16421)
  Fix string-length limit in documentation for PYI054 (#16432)
  Show version-related syntax errors in the playground (#16419)
  Allow passing `ParseOptions` to inline tests (#16357)
  Bump version to 0.9.8 (#16414)
  [red-knot] Ignore surrounding whitespace when looking for `<!-- snapshot-diagnostics -->` directives in mdtests (#16380)
  Notify users for invalid client settings (#16361)
  Avoid indexing the project if `configurationPreference` is `editorOnly` (#16381)
dcreager added a commit that referenced this pull request Feb 28, 2025

Verified

This commit was signed with the committer’s verified signature.
lunny Lunny Xiao
* dcreager/alist-type:
  Remove unneeded shear override
  Update property test CI
  Move alist into red_knot_python_semantic
  [red-knot] Switch to a handwritten parser for mdtest error assertions (#16422)
  [red-knot] Disallow more invalid type expressions (#16427)
  Bump version to Ruff 0.9.9 (#16434)
  Check `LinterSettings::preview` for version-related syntax errors (#16429)
  Avoid caching files with unsupported syntax errors (#16425)
  Prioritize "bug" label for changelog sections (#16433)
  [`flake8-copyright`] Add links to applicable options (`CPY001`) (#16421)
  Fix string-length limit in documentation for PYI054 (#16432)
  Show version-related syntax errors in the playground (#16419)
  Allow passing `ParseOptions` to inline tests (#16357)
  Bump version to 0.9.8 (#16414)
  [red-knot] Ignore surrounding whitespace when looking for `<!-- snapshot-diagnostics -->` directives in mdtests (#16380)
  Notify users for invalid client settings (#16361)
  Avoid indexing the project if `configurationPreference` is `editorOnly` (#16381)
ntBre added a commit that referenced this pull request Feb 28, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…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 added a commit that referenced this pull request Feb 28, 2025
…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 added a commit that referenced this pull request Mar 4, 2025
…tax_errors` (#16443)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cache Related to Ruff cache preview Related to preview mode features
Projects
None yet
3 participants