diffplug / diffplug/spotless

Groovy formatting is very limited - possible idea

Open
#2,513 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5.6k
Forks
559
Avg merge
1d 13h
Merged PRs (30d)
34

Description

The current Groovy formatting using the Eclipse formatter is very limited. It can't even format `apply({println it })` into something stringent. Let alone Spock tests written in Groovy.

The ways to format Groovy code are very limited. There is a npm-groovy-lint. That works better as the Eclipse formatter but has it own flaws (multi-line strings, ...). And fails on Spock tests, too.

My idea would be to use the IntelliJ formatter of the freely available community edition.

Here's the catch.
That's a command line tool that has the necessary two working options.
`dry-run` - just like `spotless:check` - checks a file or the files in a folder if they conform the expected formatting. If not, the files are reported.
`format` - just like `spotless:apply` - formats a file or the files in a folder.

After reading the contribution guideline I think this IntelliJ approach fits hardly into the Spotless Formatter approach, where one single file is given into the method and the formatted result is returned.

Of course it's possible to write the file content into a temporary file, call IntelliJ format on that temporary file, read the file again and return it's result.
I believe that's very cumbersome - especially on Windows with limited NTFS.

The necessary IntelliJ files could be packaged and provided as Maven dependency and then started as external process.

Is there a way to achieve better Groovy formation with Spotless?

(Of course, IntelliJ could format many other file types, too, but I'm mainly interested in Groovy.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.