Skip to content

Commit 4c92fa6

Browse files
authored
Merge branch 'main' into renovate/kotlin-monorepo
2 parents 760e20b + c7f4e3b commit 4c92fa6

39 files changed

Lines changed: 1779 additions & 198 deletions
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Preview documentation
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, closed]
6+
paths:
7+
- 'docs/**'
8+
- 'mkdocs.yml'
9+
- 'requirements.txt'
10+
- 'pyproject.toml'
11+
12+
concurrency:
13+
group: gh-pages-deploy
14+
cancel-in-progress: false
15+
16+
jobs:
17+
preview_docs:
18+
if: github.event.pull_request.head.repo.full_name == github.repository
19+
runs-on: ubuntu-latest
20+
env:
21+
TERM: dumb
22+
23+
steps:
24+
- uses: actions/checkout@v6
25+
26+
- name: Setup uv
27+
if: github.event.action != 'closed'
28+
uses: astral-sh/setup-uv@v7
29+
30+
- name: Install dependencies
31+
if: github.event.action != 'closed'
32+
run: uv sync --frozen
33+
34+
- name: Build documentation
35+
if: github.event.action != 'closed'
36+
run: uv run mkdocs build
37+
38+
- name: Deploy PR preview
39+
uses: rossjrw/pr-preview-action@v1
40+
with:
41+
source-dir: ./site/

.github/workflows/publish-docs.yaml

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
tags:
88
- v*
99

10+
concurrency:
11+
group: gh-pages-deploy
12+
cancel-in-progress: false
13+
1014
jobs:
1115
deploy_docs:
1216
if: github.repository == 'mrmans0n/compose-rules'
@@ -16,24 +20,46 @@ jobs:
1620

1721
steps:
1822
- uses: actions/checkout@v6
19-
20-
- name: Setup Python
21-
uses: actions/setup-python@v6
2223
with:
23-
python-version: '3.x'
24+
fetch-depth: 0
25+
26+
- name: Setup uv
27+
uses: astral-sh/setup-uv@v7
2428

2529
- name: Install dependencies
30+
run: uv sync --frozen
31+
32+
- name: Configure Git
2633
run: |
27-
python3 -m pip install --upgrade pip
28-
python3 -m pip install mkdocs
29-
python3 -m pip install mkdocs-material
30-
python3 -m pip install mdx_truly_sane_lists
34+
git config user.name "github-actions[bot]"
35+
git config user.email "github-actions[bot]@users.noreply.github.com"
3136
32-
- name: Build site
33-
run: mkdocs build
37+
- name: Fetch gh-pages branch
38+
run: git fetch origin gh-pages:gh-pages || true
3439

35-
- name: Deploy docs
36-
uses: peaceiris/actions-gh-pages@v4
37-
with:
38-
github_token: ${{ secrets.GITHUB_TOKEN }}
39-
publish_dir: ./site
40+
- name: Determine version
41+
id: version
42+
run: |
43+
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
44+
# Extract version from tag (remove 'v' prefix)
45+
VERSION="${GITHUB_REF#refs/tags/v}"
46+
echo "version=$VERSION" >> $GITHUB_OUTPUT
47+
echo "alias=latest" >> $GITHUB_OUTPUT
48+
echo "is_stable=true" >> $GITHUB_OUTPUT
49+
else
50+
# Main branch = next/development version
51+
echo "version=next" >> $GITHUB_OUTPUT
52+
echo "alias=" >> $GITHUB_OUTPUT
53+
echo "is_stable=false" >> $GITHUB_OUTPUT
54+
fi
55+
56+
- name: Deploy documentation (stable version)
57+
if: steps.version.outputs.is_stable == 'true'
58+
run: |
59+
uv run mike deploy --push --update-aliases ${{ steps.version.outputs.version }} ${{ steps.version.outputs.alias }}
60+
uv run mike set-default --push latest
61+
62+
- name: Deploy documentation (development version)
63+
if: steps.version.outputs.is_stable == 'false'
64+
run: |
65+
uv run mike deploy --push ${{ steps.version.outputs.version }}

.github/workflows/update-release.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,40 @@ jobs:
5353
tag: v${{ env.VERSION }}
5454
asset_name: detekt-compose-${{ env.VERSION }}-all.jar
5555
overwrite: true
56+
57+
- name: Extract dependency versions and update release notes
58+
if: success() && !endsWith(env.VERSION, '-SNAPSHOT')
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
run: |
62+
# Parse versions from libs.versions.toml (match only version strings, not plugin definitions)
63+
DETEKT_VERSION=$(grep '^detekt = "' gradle/libs.versions.toml | sed 's/detekt = "\([^"]*\)".*/\1/')
64+
KOTLIN_DETEKT_VERSION=$(grep '^kotlin-detekt = "' gradle/libs.versions.toml | sed 's/kotlin-detekt = "\([^"]*\)".*/\1/')
65+
KTLINT_VERSION=$(grep '^ktlint = "' gradle/libs.versions.toml | sed 's/ktlint = "\([^"]*\)".*/\1/')
66+
KOTLIN_KTLINT_VERSION=$(grep '^kotlin-ktlint = "' gradle/libs.versions.toml | sed 's/kotlin-ktlint = "\([^"]*\)".*/\1/')
67+
68+
echo "Detekt: $DETEKT_VERSION (Kotlin $KOTLIN_DETEKT_VERSION)"
69+
echo "Ktlint: $KTLINT_VERSION (Kotlin $KOTLIN_KTLINT_VERSION)"
70+
71+
# Get current release body
72+
RELEASE_ID=$(gh api repos/${{ github.repository }}/releases/tags/v${{ env.VERSION }} --jq '.id')
73+
CURRENT_BODY=$(gh api repos/${{ github.repository }}/releases/$RELEASE_ID --jq '.body')
74+
75+
# Check if dependency matrix already exists in the body
76+
if echo "$CURRENT_BODY" | grep -q "## Dependency Matrix"; then
77+
echo "Dependency matrix already exists, skipping update"
78+
exit 0
79+
fi
80+
81+
# Create the dependency matrix table (using printf for proper newlines)
82+
DEPENDENCY_TABLE=$(printf "## Dependency Matrix\n\n| version | kotlin version |\n| ------- | -------------- |\n| detekt %s | %s |\n| ktlint %s | %s |" "$DETEKT_VERSION" "$KOTLIN_DETEKT_VERSION" "$KTLINT_VERSION" "$KOTLIN_KTLINT_VERSION")
83+
84+
# Append the dependency matrix to the release body
85+
NEW_BODY=$(printf "%s\n\n%s" "$CURRENT_BODY" "$DEPENDENCY_TABLE")
86+
87+
# Update the release
88+
gh api repos/${{ github.repository }}/releases/$RELEASE_ID \
89+
-X PATCH \
90+
-f body="$NEW_BODY"
91+
92+
echo "Release notes updated with dependency matrix"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ google-services.json
3838
# MkDocs site
3939
site/
4040

41+
# Python virtual environment
42+
.venv/
43+
4144
# Fleet
4245
**/.fleet/settings.json

RELEASING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
1. Make sure the release name and the tags associated to it match. If not, you make them match.
1414
2. Publish the draft of the release.
1515

16+
This will trigger a GitHub Action workflow that will publish the versioned documentation for this release.
17+
1618
4. Update the `VERSION_NAME` in `gradle.properties` to the next SNAPSHOT version by adding `-SNAPSHOT` to the version.
1719
5. Commit and push to main
1820

@@ -21,3 +23,29 @@
2123
$ git push
2224
```
2325
6. You're done! 🎉
26+
27+
## Documentation Versioning
28+
29+
The documentation is automatically versioned using [mike](https://github.com/jimporter/mike):
30+
31+
- **Stable versions**: When a release tag (e.g., `v0.5.0`) is pushed, the documentation is deployed as a versioned site
32+
and the `latest` alias is updated to point to this version.
33+
- **Development version**: Commits to `main` branch update the `next` version, which represents the unreleased
34+
development documentation.
35+
- **Default version**: The documentation site defaults to `latest`, which always points to the most recent stable
36+
release.
37+
38+
### Working with documentation locally
39+
40+
To preview the documentation with versioning locally:
41+
42+
```bash
43+
# Install dependencies (first time only)
44+
uv sync
45+
46+
# Serve the current docs (without versioning)
47+
uv run mkdocs serve
48+
49+
# Or use mike to preview versioned docs
50+
uv run mike serve
51+
```

docs/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Compose Rules Documentation
2+
3+
This directory contains the source documentation for Compose Rules, which is built
4+
using [MkDocs](https://www.mkdocs.org/) with the [Material theme](https://squidfunk.github.io/mkdocs-material/).
5+
6+
## Documentation Structure
7+
8+
- `index.md` - Overview and introduction
9+
- `ktlint.md` - Guide for using Compose Rules with ktlint
10+
- `detekt.md` - Guide for using Compose Rules with detekt
11+
- `rules.md` - Comprehensive list of all rules with examples
12+
13+
## Versioning
14+
15+
The documentation is **versioned** using [mike](https://github.com/jimporter/mike):
16+
17+
- **Stable versions** (e.g., `0.5.0`, `0.4.0`) - Created automatically when a release tag is pushed
18+
- **Development version** (`next`) - Updated automatically on every push to `main` branch
19+
- **Default version** (`latest`) - Always points to the most recent stable release
20+
21+
### Viewing Different Versions
22+
23+
Visit the [documentation site](https://mrmans0n.github.io/compose-rules/) and use the version selector in the header to
24+
switch between:
25+
26+
- Latest stable version (default)
27+
- Specific release versions
28+
- Next (development) version
29+
30+
## Local Development
31+
32+
### Quick Preview (Recommended)
33+
34+
For fast iteration when writing documentation:
35+
36+
```bash
37+
# Install dependencies (first time only)
38+
uv sync
39+
40+
# Serve the docs locally
41+
uv run mkdocs serve
42+
```
43+
44+
Visit `http://localhost:8000` to see your changes live. This serves the current docs without versioning.
45+
46+
### Preview with Versioning
47+
48+
To see how the documentation will look with the version selector:
49+
50+
```bash
51+
# Deploy a test version locally (won't push to GitHub)
52+
uv run mike deploy dev --no-push
53+
54+
# Serve with version selector
55+
uv run mike serve
56+
```
57+
58+
Visit `http://localhost:8000` to see the versioned site.
59+
60+
## Making Changes
61+
62+
1. Edit the relevant `.md` files in this directory
63+
2. Preview your changes locally with `mkdocs serve`
64+
3. Commit and push to a feature branch
65+
4. Create a pull request
66+
67+
When your PR is merged to `main`:
68+
69+
- The `next` version of the docs will be automatically updated
70+
- Changes will be visible at `https://mrmans0n.github.io/compose-rules/next/`
71+
72+
When a new release is created:
73+
74+
- A new versioned documentation site is created automatically
75+
- The `latest` version is updated to point to the new release
76+
77+
## Documentation Guidelines
78+
79+
- Use clear, concise language
80+
- Include code examples where relevant
81+
- Link to related rules or sections when applicable
82+
- Test all code examples to ensure they work
83+
- Follow the existing documentation structure and style
84+
85+
## Useful Commands
86+
87+
```bash
88+
# Serve docs locally (fast, no versioning)
89+
uv run mkdocs serve
90+
91+
# Build the docs (output in site/ directory)
92+
uv run mkdocs build
93+
94+
# List all deployed versions
95+
uv run mike list
96+
97+
# Preview versioned docs locally
98+
uv run mike serve
99+
```
100+
101+
## Resources
102+
103+
- [MkDocs Documentation](https://www.mkdocs.org/)
104+
- [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
105+
- [mike Documentation](https://github.com/jimporter/mike)
106+
- [Markdown Guide](https://www.markdownguide.org/)
107+
108+
## Questions?
109+
110+
If you have questions about the documentation:
111+
112+
- Open an issue on GitHub
113+
- Reach out to the maintainers

docs/detekt.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
When using the [detekt Gradle Plugin](https://detekt.dev/docs/gettingstarted/gradle), you can specify the dependency on this set of rules by using `detektPlugins`.
1+
Add the dependency using `detektPlugins` in your [detekt Gradle Plugin](https://detekt.dev/docs/gettingstarted/gradle) configuration:
22

33
```groovy
44
dependencies {
@@ -21,17 +21,17 @@ Older version support can be found in the [release notes](https://github.com/mrm
2121

2222
## Using with detekt CLI / detekt IDE plugin
2323

24-
The [releases](https://github.com/mrmans0n/compose-rules/releases) page contains an [uber jar](https://stackoverflow.com/questions/11947037/what-is-an-uber-jar) for each version release that can be used to run with the [CLI version of detekt](https://detekt.dev/docs/gettingstarted/cli).
24+
The [releases](https://github.com/mrmans0n/compose-rules/releases) page contains an [uber jar](https://stackoverflow.com/questions/11947037/what-is-an-uber-jar) for each version that can be used with the [detekt CLI](https://detekt.dev/docs/gettingstarted/cli):
2525

2626
```shell
2727
detekt -p detekt-compose-<VERSION>-all.jar -c your/config/detekt.yml
2828
```
2929

30-
For the IDE plugin, you'll need to add the uber jar to the list of custom plugins in its configuration, and don't forget to also enable the rules in the yml config provided to the plugin for it to work.
30+
For the IDE plugin, add the uber jar to the custom plugins list and enable the rules in the yml config.
3131

3232
## Enabling rules
3333

34-
For the rules to be picked up, you will need to enable them in your `detekt.yml` configuration file.
34+
Enable the rules in your `detekt.yml` configuration file:
3535

3636
```yaml
3737
Compose:
@@ -166,9 +166,7 @@ Compose:
166166

167167
## Disabling a specific rule
168168

169-
To disable a rule you have to follow the [instructions from the detekt documentation](https://detekt.dev/docs/introduction/suppressing-rules), and use the id of the rule you want to disable.
170-
171-
For example, to disable `ComposableNaming` in a particular method, you can suppress it.
169+
Follow the [detekt documentation](https://detekt.dev/docs/introduction/suppressing-rules) to suppress specific rules. For example:
172170

173171
```kotlin
174172
@Suppress("ComposableNaming")

docs/index.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1-
The Compose Rules is a set of custom Ktlint / Detekt rules to ensure that your composables don't fall into common pitfalls, that might be easy to miss in code reviews.
1+
Compose Rules is a set of custom ktlint / detekt rules to ensure that your composables don't fall into common pitfalls that might be easy to miss in code reviews.
22

33
## Why
4-
It can be challenging for big teams to start adopting Compose, particularly because not everyone will start at same time or with the same patterns. We tried to ease the pain by creating a set of Compose static checks.
54

6-
Compose has lots of superpowers but also has a bunch of footguns to be aware of [as seen in this Twitter Thread](https://twitter.com/mrmans0n/status/1507390768796909571).
5+
It can be challenging for big teams to adopt Compose, particularly because not everyone starts at the same time or with the same patterns. We created these static checks to ease that pain.
76

8-
This is where our static checks come in. We want to detect as many potential issues as we can, as quickly as we can. In this case we want an error to show prior to engineers having to review code. Similar to other static check libraries we hope this leads to a "don't shoot the messengers" philosphy which will foster healthy Compose adoption.
7+
Compose has lots of superpowers but also has a bunch of footguns to be aware of, [as seen in this Twitter thread](https://twitter.com/mrmans0n/status/1507390768796909571).
8+
9+
This is where static checks come in. We want to detect as many potential issues as possible, as early as possible—ideally before code review. Similar to other static analysis libraries, we hope this fosters a "don't shoot the messenger" philosophy and healthy Compose adoption.
910

1011
## Using with ktlint
1112

1213
You can refer to the [Using with ktlint](https://mrmans0n.github.io/compose-rules/ktlint) documentation.
1314

1415
## Using with detekt
1516

16-
You can refer to the [Using with detekt](https://mrmans0n.github.io/compose-rules/detekt) documentation.
17-
18-
## Migrating from Twitter Compose Rules
19-
20-
The process to migrate to these rules coming from the Twitter ones is simple.
21-
22-
1. Change the project coordinates in your gradle build scripts
23-
2. For detekt, `com.twitter.compose.rules:detekt:$version` becomes `io.nlopez.compose.rules:detekt:$version`
24-
3. For ktlint, `com.twitter.compose.rules:ktlint:$version` becomes `io.nlopez.compose.rules:ktlint:$version`
25-
4. Update `$version` to the latest: ![Latest version](https://img.shields.io/maven-central/v/io.nlopez.compose.rules/ktlint) - see the project [releases page](https://github.com/mrmans0n/compose-rules/releases).
26-
5. **If you are using Detekt**: update the config file (e.g. `detekt.yml`) so that the rule set name `TwitterCompose` becomes `Compose`. Keep in mind that there are a lot of new rules in this repo that weren't in Twitter's, so you'd be better copying over from the [example configuration](https://mrmans0n.github.io/compose-rules/detekt).
27-
6. Done!
17+
You can refer to the [Using with detekt](https://mrmans0n.github.io/compose-rules/detekt) documentation.

0 commit comments

Comments
 (0)