Reject invalid files & use the same DiagnosticEngine for all diagnostics #144
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.