Skip to content

Commit 57a5f19

Browse files
committed
Initial implementation
1 parent 08ab033 commit 57a5f19

37 files changed

+2436
-0
lines changed

.github/workflows/pr.yml

+43
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/push.yml

+45
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

+1
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

+5
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

+24
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

+101
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/cashapp/kotlin-editor/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

+33
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
11
# Kotlin Formatter
22

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

RELEASING.md

+13
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

+4
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+
}
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
id("java-gradle-plugin")
5+
alias(libs.plugins.kotlin)
6+
alias(libs.plugins.dependencyAnalysis)
7+
}
8+
9+
gradlePlugin {
10+
plugins {
11+
create("settings") {
12+
id = "block.settings"
13+
implementationClass = "xyz.block.gradle.SettingsPlugin"
14+
}
15+
}
16+
}
17+
18+
kotlin {
19+
explicitApi()
20+
}
21+
22+
dependencies {
23+
implementation(libs.dependencyAnalysisPlugin)
24+
implementation(libs.develocityPlugin)
25+
implementation(libs.kotlinGradlePlugin)
26+
}
27+
28+
val javaTarget = JavaLanguageVersion.of(libs.versions.java.get())
29+
30+
java {
31+
toolchain {
32+
languageVersion = javaTarget
33+
}
34+
}
35+
36+
tasks.withType<JavaCompile> {
37+
options.release.set(javaTarget.asInt())
38+
}
39+
40+
tasks.withType<KotlinCompile> {
41+
kotlinOptions {
42+
jvmTarget = javaTarget.toString()
43+
}
44+
}
45+
46+
tasks.named<Test>("test") {
47+
useJUnitPlatform()
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package xyz.block.gradle
2+
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.initialization.Settings
5+
import org.gradle.kotlin.dsl.develocity
6+
import java.util.Properties
7+
8+
@Suppress("UnstableApiUsage")
9+
public abstract class SettingsPlugin : Plugin<Settings> {
10+
11+
override fun apply(target: Settings): Unit = target.run {
12+
pluginManager.apply("com.gradle.develocity")
13+
14+
val shouldPublish = shouldPublishBuildScans()
15+
16+
develocity {
17+
buildScan {
18+
it.termsOfUseUrl.set("https://gradle.com/help/legal-terms-of-use")
19+
it.termsOfUseAgree.set("yes")
20+
it.publishing.onlyIf { shouldPublish }
21+
}
22+
}
23+
}
24+
25+
private fun Settings.shouldPublishBuildScans(): Boolean {
26+
val localProperties = Properties()
27+
var publishBuildScans = false
28+
29+
val localPropertiesFile = layout.settingsDirectory.file("local.properties").asFile
30+
if (localPropertiesFile.exists()) {
31+
localPropertiesFile.inputStream().use {
32+
localProperties.load(it)
33+
}
34+
35+
publishBuildScans = localProperties.getProperty("kotlin.editor.build.scans.enable")
36+
?.toBoolean()
37+
?: false
38+
}
39+
40+
return publishBuildScans
41+
}
42+
}

build-logic/gradle.properties

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
org.gradle.caching=true
2+
org.gradle.parallel=true
3+
org.gradle.configuration-cache=true
4+
5+
dependency.analysis.print.build.health=true

0 commit comments

Comments
 (0)