Reject invalid files & use the same DiagnosticEngine for all diagnostics#144
Merged
Merged
Conversation
…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
approved these changes
Feb 11, 2020
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.