Skip to content

Assert that formatted code doesn't introduce any new unsupported syntax errors #16549

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

Merged

Conversation

MichaReiser
Copy link
Member

Summary

This should give us better coverage for the unsupported syntax error features and
increases our confidence that the formatter doesn't accidentially introduce new unsupported
syntax errors.

A feature like this would have been very useful when working on f-string formatting
where it took a lot of iteration to find all Python 3.11 or older incompatibilities.

Test Plan

I applied my changes on top of #16523 and
removed the target version check in the with-statement formatting code. As expected,
the integration tests now failed

@MichaReiser MichaReiser requested a review from dhruvmanila as a code owner March 7, 2025 08:00
@MichaReiser MichaReiser requested a review from ntBre March 7, 2025 08:00
@MichaReiser MichaReiser added internal An internal refactor or improvement testing Related to testing Ruff itself and removed internal An internal refactor or improvement labels Mar 7, 2025
Comment on lines +547 to +556
match collected.entry(error_fingerprint) {
Entry::Occupied(_) => {
error_fingerprint =
fingerprint_unsupported_syntax_error(error, error_fingerprint);
}
Entry::Vacant(entry) => {
entry.insert(error.clone());
break;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is inspired by our gitlab reporter that uses the very same approach for lint errors.

Copy link
Contributor

github-actions bot commented Mar 7, 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.

@MichaReiser MichaReiser merged commit 9cd0cde into main Mar 7, 2025
21 checks passed
@MichaReiser MichaReiser deleted the micha/assert-unsupported-syntax-errors-in-formatter-tests branch March 7, 2025 08:12
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.

Nice!

@ntBre
Copy link
Contributor

ntBre commented Mar 7, 2025

Looks great, thanks for pinging me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Related to testing Ruff itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants