question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

indentWithTabs removes leading single space

See original GitHub issue

Having standard Javadoc comments, like:

/**
 * <h3>Logging Configuration</h3>
 *
...

After running…

spotless {
	java {
		googleJavaFormat('1.3') // indents with 2 spaces
		indentWithTabs(2)
	}
}

All Javadoc stars are in the fly-on-the-left-wall position:

/**
* <h3>Logging Configuration</h3>
*
...

See https://github.com/junit-team/junit5/compare/google_java_format#diff-65f0a88c2a9307f19525f2d3c03dc8f3 for a complete example.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
nedtwiggcommented, Jan 6, 2022

conflating this issue with googleJavaFormat … the problem is much more general.

Most of the other formatters (or at least eclipse and greclipse) allow you to configure indentation to use tabs in the first place, so I did see this as a GJF-specific usecase.

But you raise a good point, C-style multiline comments are not unusual, we should “just work” for that case. I’m going to open another issue for that.

1reaction
nedtwiggcommented, Dec 30, 2021

Proposal 1 (bad idea, probably wouldn’t merge a PR)

We have a mechanism for implicitly modifying license steps based on context, e.g. this is how we keep the license step from messing up package-info.java

https://github.com/diffplug/spotless/blob/3a845e9c1d8992b12636d680c4aa2e3949d71436/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java#L219-L225

You could add something like:

if (steps.contains(::isGoogleJavaFormatStep) && steps.contains(::isIdentWithTabsStep)) {
  steps.add(replaceRegex 'class-level javadoc indentation fix', /^\*/, ' *')
  steps.add(replaceRegex 'method-level javadoc indentation fix', /\t\*/, '\t *')
}

I think that’s okay, but not great because it’s hard for users to opt out of.

Proposal 2 (okay idea, would happily merge a PR)

A better solution would be to support something like this: googleJavaFormat().indentWithTabs(), which I would add roughly here

https://github.com/diffplug/spotless/blob/3a845e9c1d8992b12636d680c4aa2e3949d71436/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java#L154-L156

and it would look something like this

public void indentWithTabs() {
  // needs to be terminal (returns void) because unlike the other methods in GoogleJavaFormatConfig, this is hard to undo. */
  indentWithTabs(2)
  replaceRegex 'class-level javadoc indentation fix', /^\*/, ' *'
  replaceRegex 'method-level javadoc indentation fix', /\t\*/, '\t *'
}


Read more comments on GitHub >

github_iconTop Results From Across the Web

Notepad++ convert leading spaces to tabs upon entry
Press [Tab] and [Shift]+[Tab] to add and remove a tab from each line. In the process, the leading spaces had been converted to...
Read more >
Indent with tabs, align with spaces - Dmitry Frank
Use tabs for indentation, spaces for alignment: the superior approach. Code is indented and aligned properly, and indentation is flexible. Use spaces for...
Read more >
Indent with tabs or spaces? I wish I didn't need to know.
But tabs and spaces are both invisible by default which leads to mistakes. That's the reason why hostility exists: it's not because one...
Read more >
Indent with tabs, align with spaces - Google Groups
Hi,. Is that possible? It solves the tab/space indentation debate, but how is this done in Vim? For example, the code: int main()...
Read more >
Indent with Tabs instead of Spaces? - Visual Studio Feedback
We may not be able to pursue this one immediately, but we will continue to ... We have added the feature to our...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found