This repository contains pre-commit hooks by Extenda Retail.
See also: http://pre-commit.com for general usage instructions.
To install the pre-commit
module, Python 3 is required to be installed (tested OK with version 3.9.5). Make sure Python directory is placed in PATH. Python's Scripts directory also should be in PATH.
Run command to install pre-commit
:
$ pip install pre-commit
Navigate to the project you want to apply pre-commit hooks and run:
$ pre-commit install
Add this to your .pre-commit-config.yaml
in project's root.
default_stages: [commit]
- repo: git://github.com/extenda/pre-commit-hooks
rev: v0.12.0 # Use the ref you want to point at
hooks:
- id: google-java-formatter
- id: commitlint
stages: [commit-msg]
eclipse-formatter
(deprecated) - Runs Eclipse Java formatter with default formatting rules on all stagedjava
source files. The following arguments are available:--source
- set the Java compiler source version (default1.8
)--target
- set the Java compiler target version (default1.8
)
google-java-formatter
- Runs Google's Java formatter on all stagedjava
source files. Please note: Java 11 or newer is required in v0.5+ Use v0.4 if you need Java 8 support.pre-commitlint
- Runs commitlint to validate commit messages.vale
(deprecated) - Runs Extenda docker-vale wrapping Vale lint and Extenda's own lint style to validate natural language in files.
There's a Google Java Format plugin for both Eclipse and IntelliJ.
The current version used is 1.23.0
.
Download the formatter plugin and drop it into Eclipse's dropins
folder.
The plugin adds a google-java-format
formatter implementation that can be configured in Window > Preferences > Java > Code Style > Formatter > Formatter Implementation
for the whole workspace.
If you have multiple projects in one workspace, it is possible to apply the formatter only to selected projects.
- Navigate to
Window > Preferences > Java > Code Style > Formatter > Formatter Implementation
- Click on
Configure Project Specific Settings
- Select the project you want to apply the formatter
- In a newly appear window check the checkbox on
Enable project specific settings
- Select
google-java-format
in a drop-down menuFormatter implementation
- Save
You must also change Window > Preferences > Java > Code style > Organize Imports
and remove all the pre-defined groups. This can be done per the whole workspace or per selected project. Google Java Format expects imports to be sorted in alphabetical order and not grouped like the Eclipse default settings.
A Google Java Format IntelliJ plugin is available from the plugin repository. The plugin will not be enabled by default. To enable it in the current project, go to File > Settings... > google-java-format Settings
and check Enable
. To enable it by default in new projects, use File > Other Settings > Default Settings...
.
When enabled, it will replace the normal Reformat Code action, which can be triggered from the Code
menu or with the Ctrl-Alt-L (by default) keyboard shortcut.
This project is licensed under the MIT license.