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

Document spotless formatting (including plugin and git hook setup) #320

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/Coding-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

We mainly follow the standard Java coding conventions and most of the conventions from the books _Effective Java_ [1] and _Clean Code_ [4]. Some exceptions and additional rules are listed below. Each rule starts with _DO_, _CONSIDER_, _AVOID_ or _DO NOT_, according to [2].

## Automatic Formatting and Copyright Headers

See [Build.md](Build.md). For the formatting rules, check [java-common.gradle.kts](https://github.com/ftsrg/theta/blob/master/buildSrc/src/main/kotlin/java-common.gradle.kts)

## Source files
* **DO** encode files in UTF-8. **DO NOT** use any other format.

Expand Down
25 changes: 24 additions & 1 deletion doc/Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,30 @@ See [Build.md](Build.md).

- Theta can be imported into [IntelliJ IDEA](https://www.jetbrains.com/idea/) as an existing Gradle project by selecting the _build.gradle.kts_ file in the root of the repository.
- If you want to build the whole project (and not just run a single test for example), make sure to run the _build task of the whole project_. This can be done by opening the Gradle tab, and then selecting _theta / theta / Tasks / build / build_, right clicking and selecting _Run_.
- Code styling and copyright noticing should be automatically set up for the ones accepted by the Github CI. It is not recommended to change them.
- For code formatting and copyright header generation we use **spotless**.
- Locally, formatting can be done manually by `gradlew spotlessApply`
- Reformatting when saving a file can be set up by installing the `Spotless Applier` plugin (`Ctrl+Alt+s > Plugins`) and enabling it when saving (`Ctrl+Alt+s > Actions on Save`, enable `Run spotless`)
- On Linux, the following pre-commit hook can be used to disable commits without formatting:
```
#!/bin/bash

# Run Spotless Check without interfering with uncommitted files
./gradlew spotlessCheck 2>/dev/null 1>&2

# Capture the exit status of spotlessCheck
SPOTLESS_STATUS=$?

# If spotlessCheck fails, prevent the commit
if [ $SPOTLESS_STATUS -ne 0 ]; then
echo "Code format check failed. Please run './gradlew spotlessApply' to fix formatting issues."
exit 1
fi

# If spotlessCheck passes, proceed with the commit
echo "Spotless check passed."
exit 0
```
*(write the above into `.git/hooks/pre-commit` and enable execution rights on the file)*

## Coding conventions

Expand Down
Loading