Skip to content

Commit b86ff40

Browse files
committed
Initial implementation
1 parent 08ab033 commit b86ff40

38 files changed

+2498
-1
lines changed

.github/workflows/pr.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- '*.md'
7+
workflow_dispatch:
8+
inputs:
9+
reason:
10+
description: 'Reason for manual run'
11+
required: false
12+
13+
concurrency:
14+
group: build-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
gradle:
19+
strategy:
20+
matrix:
21+
os: [ ubuntu-latest ]
22+
runs-on: ${{ matrix.os }}
23+
steps:
24+
- name: Checkout the repo
25+
uses: actions/checkout@v4
26+
27+
- name: Setup java
28+
uses: actions/setup-java@v4
29+
with:
30+
distribution: 'zulu'
31+
java-version: 17
32+
33+
- name: Validate Gradle Wrapper
34+
uses: gradle/actions/wrapper-validation@v3
35+
36+
- name: Setup Gradle
37+
uses: gradle/actions/setup-gradle@v3
38+
39+
- name: Execute check
40+
run: './gradlew check -s'
41+
42+
- name: Execute buildHealth for main project
43+
run: './gradlew buildHealth -s'

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
reason:
7+
description: 'Reason for manual run'
8+
required: false
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
publish:
15+
env:
16+
SIGN_KEY_PASS: ${{ secrets.GPG_SECRET_PASSPHRASE }}
17+
SIGN_KEY: ${{ secrets.GPG_SECRET_KEY }}
18+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME_XYZ_BLOCK }}
19+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD_XYZ_BLOCK }}
20+
runs-on: ubuntu-latest
21+
if: github.repository == 'block/kotlin-formatter' && github.ref == 'refs/heads/main'
22+
23+
steps:
24+
- name: Checkout the repo
25+
uses: actions/checkout@v4
26+
27+
- name: Setup java
28+
uses: actions/setup-java@v4
29+
with:
30+
distribution: 'zulu'
31+
java-version: 17
32+
33+
- name: Validate Gradle Wrapper
34+
uses: gradle/actions/wrapper-validation@v3
35+
36+
- name: Setup Gradle
37+
uses: gradle/actions/setup-gradle@v3
38+
39+
- name: Execute check
40+
run: './gradlew check -s'
41+
42+
- name: Execute buildHealth
43+
run: './gradlew buildHealth -s'
44+
45+
- name: Publish artifacts
46+
run: './gradlew publishToMavenCentral -s --no-configuration-cache'

.github/workflows/push.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '*.md'
9+
workflow_dispatch:
10+
inputs:
11+
reason:
12+
description: 'Reason for manual run'
13+
required: false
14+
15+
concurrency:
16+
group: build-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
gradle:
21+
strategy:
22+
matrix:
23+
os: [ ubuntu-latest ]
24+
runs-on: ${{ matrix.os }}
25+
steps:
26+
- name: Checkout the repo
27+
uses: actions/checkout@v4
28+
29+
- name: Setup java
30+
uses: actions/setup-java@v4
31+
with:
32+
distribution: 'zulu'
33+
java-version: 17
34+
35+
- name: Validate Gradle Wrapper
36+
uses: gradle/actions/wrapper-validation@v3
37+
38+
- name: Setup Gradle
39+
uses: gradle/actions/setup-gradle@v3
40+
41+
- name: Execute check
42+
run: './gradlew check -s'
43+
44+
- name: Execute buildHealth
45+
run: './gradlew buildHealth -s'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Ignore Gradle project-specific cache directory
22
.gradle
3+
local.properties
34

45
# Ignore Gradle build output directory
56
build

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Kotlin Formatter
2+
3+
## Version 0.1
4+
5+
First OSS release.

CODEOWNERS

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This CODEOWNERS file denotes the project leads
2+
# and encodes their responsibilities for code review.
3+
4+
# Instructions: At a minimum, replace the '@GITHUB_USER_NAME_GOES_HERE'
5+
# here with at least one project lead.
6+
7+
# Lines starting with '#' are comments.
8+
# Each line is a file pattern followed by one or more owners.
9+
# The format is described: https://github.blog/2017-07-06-introducing-code-owners/
10+
11+
# These owners will be the default owners for everything in the repo.
12+
* @wsutina @staktrace
13+
14+
15+
# -----------------------------------------------
16+
# BELOW THIS LINE ARE TEMPLATES, UNUSED
17+
# -----------------------------------------------
18+
# Order is important. The last matching pattern has the most precedence.
19+
# So if a pull request only touches javascript files, only these owners
20+
# will be requested to review.
21+
# *.js @octocat @github/js
22+
23+
# You can also use email addresses if you prefer.
24+

CONTRIBUTING.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Contribution Guide
2+
3+
There are many ways to be an open source contributor, and we're here to help you on your way! You may:
4+
5+
* Raise an issue or feature request in our [issue tracker](#issues)
6+
* Help another contributor with one of their questions, or a code review
7+
* Suggest improvements to our Getting Started documentation by supplying a Pull Request
8+
* Evangelize our work together in conferences, podcasts, and social media spaces.
9+
10+
This guide is for you.
11+
12+
## Build
13+
14+
### macOS / Linux
15+
```shell
16+
$> ./gradlew build
17+
```
18+
19+
### Windows
20+
```shell
21+
$> gradlew.bat build
22+
```
23+
24+
## Build the CLI Tool
25+
To build and install the CLI tool:
26+
27+
```shell
28+
$> ./gradlew :kotlin-format:installShadowDist
29+
```
30+
This will install the CLI to `kotlin-format/build/install/kotlin-format-shadow/`
31+
32+
## Test
33+
34+
### macOS / Linux
35+
```shell
36+
$> ./gradlew test
37+
```
38+
39+
### Windows
40+
```shell
41+
$> gradlew.bat test
42+
```
43+
44+
### Gradle build scans
45+
46+
This project is configured to publish build scans to the public
47+
[build scan service](https://scans.gradle.com/). Publication is disabled by default but can be
48+
enabled by creating a `local.properties` file with the following contents:
49+
50+
```properties
51+
kotlin.editor.build.scans.enable=true
52+
```
53+
54+
This file should not be checked into version control.
55+
56+
---
57+
58+
## Communications
59+
60+
### Issues
61+
62+
Anyone from the community is welcome (and encouraged!) to raise issues via
63+
[GitHub Issues](https://github.com/block/kotlin-formatter/issues)
64+
65+
### Continuous Integration
66+
67+
Build and Test cycles are run on every commit to every branch on [GitHub Actions](https://github.com/block/kotlin-formatter/actions).
68+
69+
## Contribution
70+
71+
We review contributions to the codebase via GitHub's Pull Request mechanism. We have
72+
the following guidelines to ease your experience and help our leads respond quickly
73+
to your valuable work:
74+
75+
* Start by proposing a change either in Issues (most appropriate for small
76+
change requests or bug fixes) or in Discussions (most appropriate for design
77+
and architecture considerations, proposing a new feature, or where you'd
78+
like insight and feedback)
79+
* Cultivate consensus around your ideas; the project leads will help you
80+
pre-flight how beneficial the proposal might be to the project. Developing early
81+
buy-in will help others understand what you're looking to do, and give you a
82+
greater chance of your contributions making it into the codebase! No one wants to
83+
see work done in an area that's unlikely to be incorporated into the codebase.
84+
* Fork the repo into your own namespace/remote
85+
* Work in a dedicated feature branch. Atlassian wrote a great
86+
[description of this workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow)
87+
* When you're ready to offer your work to the project, first:
88+
* Squash your commits into a single one (or an appropriate small number of commits), and
89+
rebase atop the upstream `main` branch. This will limit the potential for merge
90+
conflicts during review, and helps keep the audit trail clean. A good writeup for
91+
how this is done is
92+
[here](https://medium.com/@slamflipstrom/a-beginners-guide-to-squashing-commits-with-git-rebase-8185cf6e62ec), and if you're
93+
having trouble - feel free to ask a member or the community for help or leave the commits as-is, and flag that you'd like
94+
rebasing assistance in your PR! We're here to support you.
95+
* Open a PR in the project to bring in the code from your feature branch.
96+
* The maintainers noted in the `CODEOWNERS` file will review your PR and optionally
97+
open a discussion about its contents before moving forward.
98+
* Remain responsive to follow-up questions, be open to making requested changes, and...
99+
You're a contributor!
100+
* And remember to respect everyone in our global development community. Guidelines
101+
are established in our `CODE_OF_CONDUCT.md`.

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
11
# Kotlin Formatter
22

3-
**A command-line tool for formatting Kotlin source code files**. It ensures consistent code style across projects and integrates seamlessly into development workflows.
3+
**A command-line tool for formatting Kotlin source code files**, implemented as a wrapper around [ktfmt](https://github.com/facebook/ktfmt/tree/main).
4+
5+
It can be used to automate code formatting, ensuring a clean and consistent codebase, while integrating seamlessly into development workflows.
6+
7+
The tool can:
8+
9+
- **Format files and directories**: Apply consistent formatting to files, directories, or standard input.
10+
- **Integrate with Git workflows**:
11+
- **Pre-commit**: Format staged files before committing.
12+
- **Pre-push**: Check committed files before pushing.
13+
14+
15+
## Usage
16+
17+
```bash
18+
kotlin-format [OPTIONS] [FILES...]
19+
```
20+
### Options
21+
22+
| Option | Description |
23+
|-------------------------|-------------------------------------------------------------------------------------------|
24+
| `--set-exit-if-changed` | Exit with a non-zero code if any files needed changes. |
25+
| `--dry-run` | Display the changes that would be made without writing them to disk. |
26+
| `--pre-commit` | Format staged files as part of the pre-commit process. *Mutually exclusive with `--pre-push`.* |
27+
| `--pre-push` | Check committed files as part of the pre-push process. *Mutually exclusive with `--pre-commit`.* |
28+
| `--push-commit=<text>` | The SHA of the commit to use for pre-push. Defaults to `HEAD`. |
29+
| `--print-stats` | Emit performance-related statistics to help diagnose performance issues. |
30+
| `-h, --help` | Show help message and exit. |
31+
32+
### Arguments
33+
34+
| Argument | Description |
35+
|---------------|--------------------------------------------|
36+
| `<files>` | Files or directories to format. Use `-` for standard input. |
37+

RELEASING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Releasing Guide
2+
Release procedure for Kotlin Formatter
3+
4+
1. Update CHANGELOG
5+
1. Update README if needed
6+
1. Bump version number in `gradle.properties` to next stable version (removing the `-SNAPSHOT`
7+
suffix).
8+
1. `git commit -am "chore: prepare for release x.y." && git push`
9+
1. Publish the snapshot to Maven Central by invoking the `publish` action on github.
10+
1. `git tag -a vx.y -m "Version x.y."`
11+
1. Update version number `gradle.properties` to next snapshot version (x.y-SNAPSHOT)
12+
1. `git commit -am "chore: prepare next development version."`
13+
1. `git push && git push --tags`

build-logic/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugins {
2+
alias(libs.plugins.kotlin) apply false
3+
alias(libs.plugins.dependencyAnalysis)
4+
}

0 commit comments

Comments
 (0)