Skip to content

Expose tab indentation via --use-tabs CLI flag - #1468

Closed
mkurz wants to merge 1 commit into
google:masterfrom
mkurz:cli-use-tabs
Closed

mkurz wants to merge 1 commit into
google:masterfrom
mkurz:cli-use-tabs

Conversation

@mkurz

@mkurz mkurz commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

The pull request

added programmatic tab support through JavaFormatterOptions.Style.Builder.useTabs(boolean), following

This PR exposes that existing functionality through a --use-tabs CLI flag.

This lets CLI-based integrations, such as sbt-java-formatter, enable tabs without calling the formatter API directly.

The implementation only connects the parser to the existing style builder; it does not change the formatting algorithm or add another public API. Spaces remain the default. With --use-tabs, tab stops are 2 columns for Google style and 4 columns for AOSP, with spaces retained where needed for alignment.

Connect the CLI to existing Style.Builder.useTabs support without changing the default space-based indentation or formatting algorithms.

Document style-dependent tab stops and add parser, argument-file, stdin, line-wrapping, dry-run/replace, and imports-only regression tests.
@mkurz

mkurz commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@cushon Since this is missing in 1.37.0 it would be great to get this merged soon and maybe even a new release ... ;)
Thanks!

@cushon

cushon commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

I hadn't completely decided if we were going to add the CLI counterpart for this one.

I have no intention of trying to convince anyone to switch, I know some codebases use tabs, and I think this configuration is closer to --max-line-length than options for configuring code layout.

#425 had a lot of votes, it was more clear it was a blocker to adoption of the formatter. I think the only request for tab support was in #1320, which only needed support in the API. In general it seems like there may be less usage of tabs for Java.

Another potential difference from max line length is that it's easier to do this as a post-processing step, to replace leading spaces with tabs.

For sbt-java-formatter would it be possible to use the API instead of the CLI, or maybe even post-process the output to replace leading spaces with tabs?

@mkurz

mkurz commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

I was just under the impression the CLI counterpart was just missed - didn't know that it was intentionally not implemented, thats why I came up with the PR.
We did not have requests to add tab support to sbt-java-formatter so far. So there is not urgency.

I guess its fine how it is - maybe lets just wait in both projects (google-java-format and sbt-java-formatter) if more requests come in.

And yes, actually just doing post processing in sbt-java-formatter is definitely an options since that should really just be replacing leading white spaces.

Anyway, I leave this PR option, maybe it will be considered in the future.

Thanks!

@cushon

cushon commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks, that makes sense!

maybe lets just wait in both projects (google-java-format and sbt-java-formatter) if more requests come in

SGTM. I'm going to go ahead and close the PR for now, I filed #1470 to track demand for this.

@cushon cushon closed this Oct 2, 2026
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