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

Formatting stream API methods on multiple lines. #87

Closed
gaganis opened this issue Mar 11, 2017 · 5 comments
Closed

Formatting stream API methods on multiple lines. #87

gaganis opened this issue Mar 11, 2017 · 5 comments
Labels

Comments

@gaganis
Copy link

gaganis commented Mar 11, 2017

Hello all!

Firstly I would like to let you know that I really liked your project! I have found it out by working on JUnit5 and I love spotlessApply! No more hassle over formatting :)

Thanks and kudos for the great work!


One of the things that I would have liked to be better would be if we could also automate formatting of the stream API differently from other methods. In JUnit5 currently the formatter:off and on directives are used to achieve the format manually.

This how it looks now manually:

                // @formatter:off
		return findRepeatableAnnotations(this.testClass, Tag.class).stream()
				.map(Tag::value)
				.filter(StringUtils::isNotBlank)
				.map(TestTag::create)
				.collect(toCollection(LinkedHashSet::new));
		// @formatter:on

Ideally it would be really cool to get this automatically with spotless but I imagine this could be pretty difficult to implement.

Has this been discussed before?

I am willing to help with this but currently have no idea where to start.

Thanks
Giorgos

@jbduncan
Copy link
Member

Hi @gaganis, welcome! As it turns out, I'm a committer for Spotless.

The only formatter we support yet that formats streams similarly to how JUnit 5's maintainers do it is google-java-format. I believe @sormuras is looking into migrating JUnit 5 from the Eclipse formatter to google-java-format, but I can't seem to his branch ATM.

I do wonder perhaps if the Eclipse formatter has a setting that allows streams and fluent constructs to be formatted like this. @nedtwigg, do you know of any such setting?

If such a setting doesn't exist, I'd be happy to see this feature implemented. But as I know of no library which could do it, and neither do I know the technical details on formatting Java code, I've no idea where to start either.

@sormuras
Copy link
Contributor

...deleted the proof-of-concept branch, as we don't want to touch the entire JUnit 5 code base just for re-formatting. May be later, if/when google/google-java-format#19 is fixed, I might reconsider putting that topic on the table, again.

@gaganis
Copy link
Author

gaganis commented Mar 11, 2017

Well I was thinking more about using spotless for some of my own projects and I do prefer the one-per-line indented formatting.

So I could get close to that formatting using spotless along with google-java-format?

@jbduncan
Copy link
Member

Yes, I think so @gaganis.

@nedtwigg
Copy link
Member

google-java-format is a good way to go. If you're not happy with it, the eclipse formatter has a bazillion settings. Dunno if there's a combination of checkboxes that does exactly what you want, but I bet there is. Here are the docs.

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

No branches or pull requests

4 participants