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

Respect SyntaxVisitorContinueKind of rules when run in Pipeline #659

Merged
merged 2 commits into from
Oct 26, 2023

Conversation

thunderseethe
Copy link
Contributor

Pipelines+Generated.swift previously visited all enabled rules at all nodes regardless of what the rule returned for it's SyntaxVisitorContinueKind. However, some rules rely on returning .skipChildren to lint/format correctly.

To remedy this, modify the pipeline to track the the skip state of each rule. When a rule returns skip, our pipeline stops calling its visit methods until we leave the skipped node.

Alongside this change, modify tests to check both the rule in isolation and the pipeline. We were only testing the rule in isolation so our tests were respecting the SyntaxVisitorContinueKind, even though our pipeline was not.

Add a map `shouldSkipChildren` that tracks which rules are currently skipping children.
Install handlers in visitPost for each rule that determine when we should start visiting children again (when we leave the node we're skipping).
Previously we only tested the rule in isolation. This mean we weren't actually checking the pipeline respected the SyntaxVisitorContinueKind. Regardless of what the pipeline did, the tests would respect the continue kind because they run the rule itself.
Now we run the rule in isolation and the pipeline and assert that they have the same findings. This ensures the rule behaves as expected (or atleast as tested) when run in the pipeline.
Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

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

Thanks! This will help us avoid a bunch of silly errors in the future.

@allevato allevato merged commit 0e03915 into swiftlang:main Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants