Groovy formatting is very limited - possible idea

Open
#2,513 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
groovy, java
Domain
tooling

Research direction

Start by reading the contribution guidelines and the existing Groovy formatter that uses the Eclipse formatter. Compare its single-file formatting contract with the proposed IntelliJ Community Edition command-line dry-run and format modes, including the temporary-file and external-process concerns. Done would mean an agreed, maintainable way to improve Groovy and Spock formatting in Spotless.

Written by the indexing model from the issue text.

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.)

Dominant language
Java
Stars
5.7k
Forks
560
Avg merge
1d 13h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.