Improve Formatter API (#1505)

- pass `GrammarVersion` to constructor instead of passing it to each
`format` method
- replace `format(Path): String` with `format(Reader, Appendable)`
- instead of picking which overloads besides `format(String): String`
might be useful, offer a single generalized method that streams input
and output
- add `@Throws(IOException::class)` to ensure that Java callers can
catch this exception
- deprecate old methods
This commit is contained in:
odenix
2026-04-07 14:16:12 -07:00
committed by GitHub
parent 99cbd07518
commit 09435af54f
5 changed files with 68 additions and 34 deletions

View File

@@ -47,7 +47,7 @@ constructor(
private val errWriter: Writer = System.err.writer(),
) : CliCommand(CliBaseOptions()) {
private fun format(contents: String): String {
return Formatter().format(contents, grammarVersion)
return Formatter(grammarVersion).format(contents)
}
private fun writeErrLine(error: String) {