Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Formatting config #24

Closed
wants to merge 5 commits into from
Closed

Conversation

LeafHacker
Copy link
Contributor

@LeafHacker LeafHacker commented Aug 21, 2017

Add Spotless build tasks to lint and format code. You can lint your code using spotlessCheck or format using spotlessApply.

I've added formatters for java, gradle, properties and some misc files like gitignore. The java and gradle formatters use eclipse's formatter which allows for a good amount of customisation.

Overview of style choices:

  • Use tabs for indentation and spaces for alignment
  • Most things (e.g. arguments and assignment) will try and align, up to a limit of 16 chars. I'm not sure if the number is max spaces to use in alignment or something else.
  • Open blocks with brace on same line instead of a new line (e.g. try {)
  • Allow short if statements to remain on a single line
    • Guard clauses like if (foo) return bar; can be single line (a guardian clause is a conditional return that guards against errors)
    • Other short if statements can too (configurable separately)
  • Keep follow up statements on the same line as the previous closing brace (e.g. } else or } catch)
  • Empty blocks contain no whitespace (instead of inserting spaces or newlines)
  • Newline after annotations (couldn't figure out how to not break after short/single annotations)

See the format.properties file for the exact configuration and feel free to checkout of browse this branch to see how the the code looks formatted.

This fixes #23


@ZeroMemes @0-x-2-2 Please leave feedback inline as part of your review, either commenting on the result of a setting or on the setting itself in format.properties. No rush to merge until all feedback has been addressed.

EditorConfig configures how the IDE displays and formats files. It is
mostly useful to configure tab width and prevent undue burden being
placed on our code formatting task.

Spotless is a cool gradle plugin to add code formatting to projects. It
enables custom string formatters and also integrates with some existing
formatting tools like groovy-eclipse and google-java-format.

You can lint your code using the spotlessCheck task, or format it using
spotlessApply. Added formatters for java, gradle, properties and some
misc files. Used eclipse formatter for a highly customisable format. See
the format.properties file.
Copy link
Contributor

@0-x-2-2 0-x-2-2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces over tabs but some stuff i would keep

@ZeroMemes ZeroMemes closed this Aug 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants