Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better names for indentWithSpaces and indentWithTabs #794

Open
wheelerlaw opened this issue Feb 10, 2021 · 4 comments
Open

Better names for indentWithSpaces and indentWithTabs #794

wheelerlaw opened this issue Feb 10, 2021 · 4 comments

Comments

@wheelerlaw
Copy link

So I have this simple groovy formatter just to ensure that all files Groovy and Groovy related files end with newlines and are indented using 4 spaces. However, when I run ./gradlew spotlessApply, files that are indented with 2 spaces are not converted. Here is the block:

spotless {
    format 'groovy', {
        target '*.gradle', 'Jenkinsfile*', '*.groovy'
        indentWithSpaces()
        endWithNewline()
    }
}

I am not using the groovy formatter because I have Jenkins script files that are located outside of source sets. So according to the documentation, this should work, since I have defined the target file name matcher, and the rules I want applied.

Spotless version: 5.10.0
Gradle version: 6.7
Operating system: Fedora 33

@jbduncan
Copy link
Member

jbduncan commented Feb 10, 2021

Ah, that's something with indentWithSpaces() that people get confused about a lot. (I was confused about it in the past too!)

indentWithSpaces() doesn't translate stuff that already has spaces from e.g. 2 spaces per indent to 4 spaces; it only translates tabs to 4 spaces.

See @nedtwigg's rationale for this over at #58 (comment). tl;dr: it would clobber spaces in Javadoc comments otherwise.

@wheelerlaw
Copy link
Author

Ah, that's interesting. It should at the very least be renamed to remove the confusion, like tabsToSpaces() or something similar. I can create a PR for it.

@nedtwigg
Copy link
Member

leadingTabsToSpaces and leadingSpacesToTabs are better names, good call! Important checklist for the old methods:

  • should keep working
  • be marked as deprecated
  • emit a warning saying something like replace 'foo' with 'bar' in your gradle buildscript

@nedtwigg nedtwigg changed the title Simple custom Groovy linter not working Better names for indentWithSpaces and indentWithTabs Feb 11, 2021
@jbduncan
Copy link
Member

@wheelerlaw If you're still willing and able to create a PR for this issue, then please feel free to go ahead. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants