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

Reject invalid files & use the same DiagnosticEngine for all diagnostics #144

Merged
merged 1 commit into from
Feb 11, 2020

Conversation

dylansturg
Copy link
Contributor

After finding some "source" files that stretched the syntax parser to its limits, it looks like the formatter cannot trust any AST that contains any unknown/invalid nodes. It's possible for an unknown node to cause the parser to group tokens in ways that create known but incorrect nodes. Instead of potentially formatting those tokens as the wrong kind of node, which may be destructive, fail early on the file and refuse to format it. When that happens, the formatter raises a diagnostic (which goes to stderr by default).

Additionally, the formatter was using a new diagnostic engine for every file and was explicitly writing certain messages directly to stderr. I've reworked the format and lint operators to use the same diagnostic engine for every file and to use that diagnostic engine instead of stderr. By default, the diagnostic engine writes to stderr so it's a essentially a no-op change but can be helpful if anyone wants to add a diagnostic consumer later.

…ne for all diagnostics.

After finding some "source" files that stretched the syntax parser to its limits, it looks like the formatter cannot trust any AST that contains any unknown/invalid nodes. It's possible for an unknown node to cause the parser to group tokens in ways that create known but incorrect nodes. Instead of potentially formatting those tokens as the wrong kind of node, which may be destructive, fail early on the file and refuse to format it. When that happens, the formatter raises a diagnostic (which goes to stderr by default).

Additionally, the formatter was using a new diagnostic engine for every file and was explicitly writing certain messages directly to stderr. I've reworked the format and lint operators to use the same diagnostic engine for every file and to use that diagnostic engine instead of stderr. By default, the diagnostic engine writes to stderr so it's a essentially a no-op change but can be helpful if anyone wants to add a diagnostic consumer later.
@allevato allevato merged commit 7b64925 into swiftlang:master Feb 11, 2020
@dylansturg dylansturg deleted the safer_unknown_nodes branch February 11, 2020 18:31
aaditya-chandrasekhar pushed a commit to val-verde/swift-format that referenced this pull request May 20, 2021
* Use pre instead of pre-line for code whitespace.

* Add changelog entry for swiftlang#144

Co-authored-by: Mattt <mattt@me.com>
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