Skip to content

Commit

Permalink
Automate formatter and checker
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Lamparelli <[email protected]>
  • Loading branch information
lampajr authored and johnaohara committed Sep 2, 2024
1 parent b3af2d9 commit 285ec51
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ yarn.lock*

react-app-env.d.ts

#docs
# docs
docs/site/.hugo_build.lock
docs/site/public/
docs/site/resources/

# code format
.cache
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,40 @@ git remote add upstream https://github.com/Hyperfoil/Horreum.git
```
git checkout -b myfeature master
```

### Code Style

Horreum has a strictly enforced code style. Code formatting is done by the Eclipse code formatter, using the config files found in the `config/` directory. By default, when you run `mvn install`, the code will
be formatted automatically. When submitting a pull request the CI build will fail if running the formatter results in any code changes, so it is recommended that you always run a full Maven build before submitting a pull request.

If you want to run the formatting without doing a full build, you can run `mvn process-sources`.

#### Eclipse Formatting Setup

Open the *Preferences* window, and then navigate to _Java_ -> _Code Style_ -> _Formatter_. Click _Import_ and then
select the `eclipse-formatting.xml` file in the `config/` directory.

Next navigate to _Java_ -> _Code Style_ -> _Organize Imports_. Click _Import_ and select the `eclipse.importorder` file.

#### IDEA Formatting Setup

Open the _Preferences_ window (or _Settings_ depending on your edition), navigate to _Plugins_ and install
the [Adapter for Eclipse Code Formatter](https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter) from the
Marketplace.

Restart your IDE, open the *Preferences* (or *Settings*) window again and navigate to _Adapter for Eclipse Code
Formatter_ section on the left pane.

Select _Use Eclipse's Code Formatter_, then change the _Eclipse workspace/project folder or config file_ to point to the
`eclipse-formatting.xml` file in the `config/` directory. Make sure the _Optimize Imports_ box is
ticked. Then, select _Import Order from file_ and make it point to the `eclipse.importorder` file in the `config/`
directory.

Next, disable wildcard imports:
navigate to _Editor_ -> _Code Style_ -> _Java_ -> _Imports_
and set _Class count to use import with '\*'_ to `999`. Do the same with _Names count to use static import with '\*'_.

#### Git Formatting Setup

If you want to be sure that the _formatting_ is properly executed before committing, you can make use of the git hooks, in particular the `pre-commit` one.
Simply override the `.git/hooks/pre-commit` script with a custom logic that runs `mvn formatter:format impsort:sort` to format the source code and the remember to `git add` all changed files such that they are included in the ongoing commit.
Loading

0 comments on commit 285ec51

Please sign in to comment.