build: strict Kotlin + Rust auto-formatting with ktlint and rustfmt
- Commit
c21c5924acd09eecbed4d8162698d35988f62726- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 01:51 UTC (5 days ago)
- Parents
e310584
Kotlin gets ktlint via org.jlleitschuh.gradle.ktlint 14.2.0 (engine 1.5.0), wired exactly like detekt before it: version in the catalog, classpath jar in build-logic, versionless id in the app/library conventions — no new repositories. ktlint reads the repo's existing .editorconfig as the single style source (4-space indent, 120 columns, LF, final newline); the only rule knob is one line letting Composable-annotated functions keep PascalCase, matching the repo rule that a composable is named as its file. One wiring subtlety is documented inline: AGP 9 registers the unit-test source set after ktlint builds its aggregate, so ktlintFormat is explicitly chained to the test source-set format task by name (a live tasks.matching collection broke graph calculation on the Compose Preview variant tasks). The new ./format script mirrors ./check's module notation (slash==colon, games shorthand, all): default mode runs ktlintFormat + cargo fmt, --check runs ktlintCheck + cargo fmt --check. ./check now runs :mod:ktlintCheck beside detekt/lint, and cargo fmt --check flips from advisory to blocking (the promotion its comment always promised); rustfmt is installed for the 1.97 toolchain. Root AGENTS.md documents the tool, commands and enforcement in current-state terms. Rollout is per module: run ./format, fix the small non-autocorrectable residue, then the module's ./check gate is green; baseline violation counts (camera 12,039 in 312 files, library/ui 9,953 in 230) size the remaining rollout, with ~450 likely-manual residues in each giant.
Diff
.editorconfig
diff --git a/.editorconfig b/.editorconfigindex 61ab964d4b..4625e246df 100644--- a/.editorconfig+++ b/.editorconfig@@ -10,6 +10,10 @@ insert_final_newline = true indent_style = space indent_size = 4 max_line_length = 120+# Repo convention: one public @Composable per file, named as the file —+# composables are PascalCase, so ktlint's function-naming rule must not+# demand camelCase for them. (No ktlint rule is disabled repo-wide.)+ktlint_function_naming_ignore_when_annotated_with = Composable [*.{rs,toml}] indent_style = space
AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 51b36bc663..f617c8cc17 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -44,7 +44,7 @@ Monorepo: ~100 Gradle modules + Rust workspace. Do scoped work only. | aosp-stubs | `library/aosp-stubs/` | compile-only hidden-API stubs | | sdk:games/cast/openassistant | `sdk/games/`, `sdk/cast/`, `sdk/openassistant/` | achievements / casting / assistant tools | | build-logic | `build-logic/` | `common-conventions-app`, `launcherIcon`, `rustNativeLib` |-| lint-rules | `lint-rules/` | ToastUsage + DirectComposeAnimation + FileLength + DirectAndroidLog (fatal) + 9 advisory |+| lint-rules | `lint-rules/` | ToastUsage + DirectComposeAnimation + FileLength + DirectAndroidLog + DialogAsRoute + RouteScreenshotCoverage + FixtureDeterminism + NoDeadClick (fatal) + others | ### Apps (Gradle key → dir) Reference: `backup/` satisfies every rule; `notes/` second + `intents/` demo. `camera` + `games/voxels` hand-commit screenshots.@@ -77,7 +77,9 @@ The backend (relay server for findfamily/everysync/office/voxels) lives outside - Every native library has exactly one guarded wrapper in `platform/` named `<Feature>Native`; it is the only `System.loadLibrary` caller for that library and exposes availability instead of letting initialization fail. JNI-frozen FQNs are the only package exceptions and must carry the verbatim JNI marker. - Every app has exactly one preferences owner in `data/` named `<App>Prefs`; only it opens the app’s DataStore/SharedPreferences, and it recovers from corruption with documented defaults. Persisted/external decoding goes through non-throwing helpers in `data/` or `domain/`; Room converters never throw. - Every exported entry point has one validated contract in `intents/`; entry points consume validated values only. Regexes must be Android-ICU-valid (escape literal braces outside quantifiers/character classes). Widgets render from one immutable snapshot and use fallbacks for missing keys/items. One widget, one file: every file in `widget/` declares a `MaWidget` subclass at top level together with its receiver; no helper-only files in `widget/` (helpers nest inside the widget; non-Glance app helpers belong to their own root).-- Escape hatches verbatim: `// PACKAGE STRUCTURE EXCEPTION (JNI)`, `// RAW SCAFFOLD EXCEPTION: <reason>`, `// TOAST EXCEPTION: <reason>`, `// RAW ANIMATION EXCEPTION: <reason>`, `// SCAFFOLD LOADING EXCEPTION: <reason>`, `// SCAFFOLD SEARCH EXCEPTION: <reason>`.+- Escape hatches verbatim: `// PACKAGE STRUCTURE EXCEPTION (JNI)`, `// RAW SCAFFOLD EXCEPTION: <reason>`, `// TOAST EXCEPTION: <reason>`, `// RAW ANIMATION EXCEPTION: <reason>`, `// SCAFFOLD LOADING EXCEPTION: <reason>`, `// SCAFFOLD SEARCH EXCEPTION: <reason>`, `// DIALOG LOCAL EXCEPTION: <reason>`, `// FIXTURE RELATIVE-TIME EXCEPTION: <reason>`, `// DEAD CLICK EXCEPTION: <reason>`.+- Test/screenshot fixtures are deterministic (fatal `FixtureDeterminism` lint): no `Clock.System.now()`/`LocalDate.now()`/`LocalDateTime.now()`/`Instant.now()`/`System.currentTimeMillis()` or unseeded `Random()`/`UUID.randomUUID()` in `src/test`/`src/screenshotTest` — use named fixed constants or a seeded `Random(seed)`; deadline-polling/elapsed/freshness-assert idioms in unit tests are not fixtures. Code that must seed relative to the SUT's real clock uses `// FIXTURE RELATIVE-TIME EXCEPTION: <reason>`.+- No dead clicks (fatal `NoDeadClick` lint): a Button/IconButton/FAB/MenuItem/ListItem-clickable in `src/main` with an empty/comment-only `onClick` and no `enabled = false` is an error — wire it, disable it honestly, or demote it to a non-button container. Display-only label chips are excluded by widget type; drag-handle grips use `// DEAD CLICK EXCEPTION: <reason>`. - detekt rules live in `detekt.yml` (ui/domain/odf/service scoping rationale inline). Fix code, not config, to green a module. ## 3. Verify (slice touched, never whole repo)@@ -122,7 +124,7 @@ Rules: `release` default (dev is almost never the right install), `dev` only whe ``` Never grep repo-wide when a filter will do. Always excluded: `target/ build/ .gradle/ .kotlin/ .git/ .llms/ analysis/ *.log *.onnx metadata_data/photos/`. -`./check` — static verification without building: `:<module>:detekt` (rules in `detekt.yml`) + `:<module>:lint` + `cargo check/clippy/fmt/doc --locked` for Rust modules (workspace members via `-p`, standalone crates in-dir; fmt is advisory-only until the tree is fmt-clean) + structure ratchets (`tools/structure_check.py`, manifests in `docs/structure/` — Wear protocol-pair drift, generated-source guard, exception-marker inventory; runs on every invocation):+`./check` — static verification without building: `:<module>:detekt` (rules in `detekt.yml`) + `:<module>:lint` + `:<module>:ktlintCheck` + `cargo check/clippy/fmt/doc --locked` for Rust modules (workspace members via `-p`, standalone crates in-dir; `cargo fmt --check` is blocking — drift fails the script) + structure ratchets (`tools/structure_check.py`, manifests in `docs/structure/` — Wear protocol-pair drift, generated-source guard, exception-marker inventory; runs on every invocation): ``` ./check <module> [...] # e.g. ./check notes backup; ./check voxels ./check all # every app + library module (pure-JVM modules excluded)@@ -130,6 +132,14 @@ Never grep repo-wide when a filter will do. Always excluded: `target/ build/ .gr ``` Findings fail the task. Only `notes/`, `backup/`, `library/ui/`, `games/voxels/` are detekt-clean today; other modules carry incremental backlog — fixing a module means `./check <module>` goes green, not config relaxation. +`./format` — auto-formatting (same module notation as `./check`):+```+./format <module> [...] # ktlintFormat + cargo fmt (writes changes)+./format --check <module> # ktlintCheck + cargo fmt --check only+./format all # every app + library module+```+Formatting (current state): Kotlin uses ktlint's standard rule set via the `org.jlleitschuh.gradle.ktlint` Gradle plugin (version pinned in `gradle/libs.versions.toml`; engine 1.5.0), applied by `common-conventions-app`/`common-conventions-library` so every app/library module has `ktlintFormat`/`ktlintCheck`. Style is the root `.editorconfig` (indent 4, max line 120, LF, final newline), which ktlint reads natively. Generated sources and `*.kts` build scripts are excluded (scope is `src/**`). `./check` enforces formatting per module (`:ktlintCheck` beside detekt/lint; `cargo fmt --check` blocking for Rust — style in the root `rustfmt.toml`, max_width 100; the rustfmt component is required: `rustup component add rustfmt`). Rule exceptions: no ktlint rule is disabled. The one configured knob is `ktlint_function_naming_ignore_when_annotated_with = Composable` in `.editorconfig` — composables are PascalCase by repo convention (one public `@Composable` per file, named as the file), so the rule must not demand camelCase for them. Roll out module by module: `./format <module>` plus manual fixes for non-autocorrectable findings, then `./check <module>` green.+ ### On-device file map (per-module `AGENTS.md` carries concrete names) - Room (`RoomRepository`, `DB_NAME` in `data/`): `/data/data/<pkg>/databases/<DB_NAME>` (+ `-wal`/`-shm` sidecars). SQLCipher-encrypted. `getDatabasePath`/`deleteDatabase`/`LEGACY_*` names are the same dir. - DataStore: `preferencesDataStore(name=X)` → `/data/data/<pkg>/files/datastore/X.preferences_pb`; shared `DataStoreUtils` → `/data/data/<pkg>/files/datastore_default.preferences_pb`.
build-logic/build.gradle.kts
diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.ktsindex 3ee96ee6f7..ad6b26e890 100644--- a/build-logic/build.gradle.kts+++ b/build-logic/build.gradle.kts@@ -7,6 +7,7 @@ dependencies { implementation(libs.kotlin.serialization.gradle) implementation(libs.symbol.processing.gradle.plugin) implementation(libs.detekt.gradle.plugin)+ implementation(libs.ktlint.gradle.plugin) implementation(libs.gradle) implementation(libs.compose.screenshot.gradle) implementation(libs.kotlin.gradle.plugin)
build-logic/src/main/kotlin/common-conventions-app.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts b/build-logic/src/main/kotlin/common-conventions-app.gradle.ktsindex 1c119d748e..ee0777b2fc 100644--- a/build-logic/src/main/kotlin/common-conventions-app.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-app.gradle.kts@@ -7,6 +7,7 @@ plugins { id("org.jetbrains.kotlin.plugin.serialization") id("com.google.devtools.ksp") id("dev.detekt")+ id("org.jlleitschuh.gradle.ktlint") } // Static analysis (./check runs `:module:detekt`). Rules live in the committed@@ -16,6 +17,33 @@ detekt { config.setFrom(files(rootDir.resolve("detekt.yml"))) } +// Formatting (./format runs `:module:ktlintFormat`; ./check runs+// `:module:ktlintCheck`). ktlint's standard rule set, driven by the committed+// root .editorconfig (indent 4, max line 120, LF, final newline) — the plugin+// reads it natively, so style lives in exactly one file. Rule exceptions are+// `ktlint_standard_<rule> = disabled` lines in .editorconfig, each with its+// reason inline; keep that list empty unless a rule conflicts with a+// documented repo convention. Generated sources (KSP/AGP output under+// build/) are excluded — they are not hand-written style — and so are+// build scripts: rollout covers src/** only.+ktlint {+ // Pinned tool version (the Gradle plugin's default tracks this today;+ // pinning keeps every module on one rule set across plugin bumps).+ version.set("1.5.0")+ filter {+ exclude("**/generated/**", "**/*.kts")+ }+}++// AGP 9 registers the unit-test Kotlin source set after the ktlint plugin+// builds its aggregate, so plain `ktlintFormat` misses+// ktlintTestSourceSetFormat (check's aggregate is unaffected). Wire it in+// by name (lazy: a tasks.matching live collection here forces eager task+// realization, which breaks on the Compose Preview release-variant tasks).+tasks.named("ktlintFormat") {+ dependsOn("ktlintTestSourceSetFormat")+}+ val libs = the<org.gradle.accessors.dm.LibrariesForLibs>() // JVM unit tests load Rust cdylibs from build/rustHostLibs (see RustNative.kt):@@ -303,6 +331,10 @@ configure<com.android.build.api.dsl.ApplicationExtension> { "ExceptionMarkerFormat", "TodoEvasion", "CommentedOutCode",+ "RouteScreenshotCoverage",+ "DialogAsRoute",+ "FixtureDeterminism",+ "NoDeadClick", ) } @@ -657,7 +689,7 @@ providers.environmentVariable("SOURCE_DATE_EPOCH").orNull?.let { extensions.configure<com.android.build.api.variant.ApplicationAndroidComponentsExtension> { onVariants { variant -> variant.hostTests.forEach { (name, hostTest) ->- if (name == "unitTest") {+ if (name.equals("unitTest", ignoreCase = true)) { hostTest.sources.kotlin?.addStaticSourceDirectory( rootDir.resolve("build-logic/shared-test/java").absolutePath, )
build-logic/src/main/kotlin/common-conventions-library.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts b/build-logic/src/main/kotlin/common-conventions-library.gradle.ktsindex a3ad0f8ed4..61fc39aa3c 100644--- a/build-logic/src/main/kotlin/common-conventions-library.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-library.gradle.kts@@ -7,6 +7,7 @@ plugins { id("org.jetbrains.kotlin.plugin.compose") id("org.jetbrains.kotlin.plugin.serialization") id("dev.detekt")+ id("org.jlleitschuh.gradle.ktlint") } // Static analysis (./check runs `:module:detekt`). Rules live in the committed@@ -16,6 +17,33 @@ detekt { config.setFrom(files(rootDir.resolve("detekt.yml"))) } +// Formatting (./format runs `:module:ktlintFormat`; ./check runs+// `:module:ktlintCheck`). ktlint's standard rule set, driven by the committed+// root .editorconfig (indent 4, max line 120, LF, final newline) — the plugin+// reads it natively, so style lives in exactly one file. Rule exceptions are+// `ktlint_standard_<rule> = disabled` lines in .editorconfig, each with its+// reason inline; keep that list empty unless a rule conflicts with a+// documented repo convention. Generated sources (KSP/AGP output under+// build/) are excluded — they are not hand-written style — and so are+// build scripts: rollout covers src/** only.+ktlint {+ // Pinned tool version (the Gradle plugin's default tracks this today;+ // pinning keeps every module on one rule set across plugin bumps).+ version.set("1.5.0")+ filter {+ exclude("**/generated/**", "**/*.kts")+ }+}++// AGP 9 registers the unit-test Kotlin source set after the ktlint plugin+// builds its aggregate, so plain `ktlintFormat` misses+// ktlintTestSourceSetFormat (check's aggregate is unaffected). Wire it in+// by name (lazy: a tasks.matching live collection here forces eager task+// realization, which breaks on the Compose Preview release-variant tasks).+tasks.named("ktlintFormat") {+ dependsOn("ktlintTestSourceSetFormat")+}+ val libs = the<org.gradle.accessors.dm.LibrariesForLibs>() // JVM unit tests load Rust cdylibs from build/rustHostLibs (see RustNative.kt):@@ -93,6 +121,10 @@ configure<com.android.build.api.dsl.LibraryExtension> { "ExceptionMarkerFormat", "TodoEvasion", "CommentedOutCode",+ "RouteScreenshotCoverage",+ "DialogAsRoute",+ "FixtureDeterminism",+ "NoDeadClick", ) } }
check
diff --git a/check b/checkindex 6a67a4b04f..5bf136e880 100755--- a/check+++ b/check@@ -1,9 +1,9 @@ #!/usr/bin/env bash # Static verification without building or installing:-# ./gradlew :<mod>:detekt :<mod>:lint [...] + cargo check/clippy/fmt/doc (rust modules only)+# ./gradlew :<mod>:detekt :<mod>:lint :<mod>:ktlintCheck [...] + cargo check/clippy/fmt/doc (rust modules only) # # Usage:-# ./check <module> [module...] # detekt (detekt.yml) + lint + cargo check/clippy/fmt/doc+# ./check <module> [module...] # detekt (detekt.yml) + lint + ktlintCheck + cargo check/clippy/fmt/doc # ./check games/voxels maps # multi-module, one gradlew invocation # ./check voxels # shorthand -> games:voxels (same as ./install) # ./check all # every app + library module@@ -24,9 +24,11 @@ # check; the real aarch64 cross-build runs inside the Gradle build via # cargoNdkBuild). Lint-sweep Phase 4 adds, per in-scope crate: `cargo clippy # --locked --all-targets` (blocking on deny/error lints; warnings never fail),-# `cargo fmt --check` (advisory report only until the tree is fmt-clean, then-# it promotes to blocking), and `cargo doc --locked --no-deps` (blocking on-# rustdoc errors). No rust modules -> cargo steps skipped.+# `cargo fmt --check` (blocking: this script fails on rustfmt drift; fix+# with `./format <module>`), and `cargo doc --locked --no-deps` (blocking on+# rustdoc errors). Kotlin formatting is enforced the same way: every module+# runs `:ktlintCheck` next to detekt/lint; fix with `./format <module>`.+# No rust modules -> cargo steps skipped. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"@@ -45,7 +47,8 @@ normalize_module() { echo "$m" | tr '[:upper:]' '[:lower:]' } -# all = app + library convention modules (both apply dev.detekt; pure-JVM+# all = app + library convention modules (both apply dev.detekt and+# org.jlleitschuh.gradle.ktlint; pure-JVM # modules like youpipe:extractor do not, so they are excluded here but still # accepted when named explicitly and left for Gradle to report on). all_module_dirs() {@@ -100,7 +103,7 @@ done TASKS=() for mod in "${MODS[@]}"; do gmod="$(echo "$mod" | tr '/' ':')"- TASKS+=(":$gmod:detekt" ":$gmod:lint")+ TASKS+=(":$gmod:detekt" ":$gmod:lint" ":$gmod:ktlintCheck") # cargo include_bytes!s the SPIR-V this task writes to build/spirv. [[ -d "$ROOT/$mod/src/main/rust/shaders" ]] && TASKS+=(":$gmod:compileShaders") done@@ -185,29 +188,30 @@ for rdir in ${STANDALONE_DIRS[@]:-}; do ( cd "$rdir" && "$CARGO_BIN" clippy --locked --all-targets ) || CLIPPY_RC=$? [[ $CLIPPY_RC -ne 0 ]] && echo "Warning: cargo clippy ($rdir) reported failures (exit $CLIPPY_RC)." done-# --- cargo fmt (advisory only, lint-sweep Phase 4) ----# The tree carries fmt drift today, so this step reports but never fails.-# Promotes to blocking once `cargo fmt --check` is clean on the owning slice.+# --- cargo fmt (blocking) ---+# `cargo fmt --check` fails this script on drift. Fix with+# `./format <module>` (or `cargo fmt -p <crate>`); style is rustfmt.toml.+FMT_RC=0 if [[ ${#ROOT_CRATES[@]} -gt 0 ]]; then echo "" FMT_ARGS=() for c in "${ROOT_CRATES[@]}"; do FMT_ARGS+=(-p "$c"); done- echo "Running: cargo fmt --check ${FMT_ARGS[*]} (advisory)"- FMT_OUT="$(cd "$ROOT" && "$CARGO_BIN" fmt --check "${FMT_ARGS[@]}" 2>&1)" || true- FMT_COUNT="$(echo "$FMT_OUT" | grep -c '^Diff in' || true)"- if [[ "$FMT_COUNT" -gt 0 ]]; then- echo "rustfmt drift: $FMT_COUNT hunks in scope (advisory; run cargo fmt -p <crate> to clean)."+ echo "Running: cargo fmt --check ${FMT_ARGS[*]}"+ FMT_OUT="$(cd "$ROOT" && "$CARGO_BIN" fmt --check "${FMT_ARGS[@]}" 2>&1)" || FMT_RC=$?+ if [[ $FMT_RC -ne 0 ]]; then+ FMT_COUNT="$(echo "$FMT_OUT" | grep -c '^Diff in' || true)"+ echo "Error: rustfmt drift: $FMT_COUNT hunks in scope (run ./format <module> to fix)." else echo "rustfmt: clean." fi fi for rdir in ${STANDALONE_DIRS[@]:-}; do echo ""- echo "Running: cargo fmt --check (in $rdir, advisory)"- FMT_OUT="$(cd "$rdir" && "$CARGO_BIN" fmt --check 2>&1)" || true- FMT_COUNT="$(echo "$FMT_OUT" | grep -c '^Diff in' || true)"- if [[ "$FMT_COUNT" -gt 0 ]]; then- echo "rustfmt drift: $FMT_COUNT hunks in $rdir (advisory)."+ echo "Running: cargo fmt --check (in $rdir)"+ FMT_OUT="$(cd "$rdir" && "$CARGO_BIN" fmt --check 2>&1)" || FMT_RC=$?+ if [[ $FMT_RC -ne 0 ]]; then+ FMT_COUNT="$(echo "$FMT_OUT" | grep -c '^Diff in' || true)"+ echo "Error: rustfmt drift: $FMT_COUNT hunks in $rdir (run ./format <module> to fix)." else echo "rustfmt: clean ($rdir)." fi@@ -234,5 +238,5 @@ if [[ ${#ROOT_CRATES[@]} -eq 0 && ${#STANDALONE_DIRS[@]} -eq 0 ]]; then echo "No Rust crates in scope; cargo steps skipped." fi -if [[ $STRUCTURE_RC -ne 0 || $DETEKT_RC -ne 0 || $CARGO_RC -ne 0 || $CLIPPY_RC -ne 0 || $DOC_RC -ne 0 ]]; then exit 1; fi+if [[ $STRUCTURE_RC -ne 0 || $DETEKT_RC -ne 0 || $CARGO_RC -ne 0 || $CLIPPY_RC -ne 0 || $FMT_RC -ne 0 || $DOC_RC -ne 0 ]]; then exit 1; fi exit 0
format
diff --git a/format b/formatnew file mode 100755index 0000000000..d63d58a0d2--- /dev/null+++ b/format@@ -0,0 +1,165 @@+#!/usr/bin/env bash+# Auto-formatting for Kotlin (ktlint) and Rust (rustfmt):+# ./format <module> [...] # ktlintFormat + cargo fmt (writes changes)+# ./format --check <module> [...] # ktlintCheck + cargo fmt --check (fails on drift)+#+# Usage:+# ./format notes backup # multi-module, one gradlew invocation+# ./format voxels # shorthand -> games:voxels (same as ./install)+# ./format games/voxels maps # slash == colon+# ./format all # every app + library module+# ./format --check games/pipes # verify only, no writes+#+# Module notation mirrors ./check and ./install: slash == colon,+# games:/personal: shorthand, 'all' keyword, deduped. Gradle tasks run+# with --continue so one broken module does not block the rest; exit+# code is nonzero if anything failed. Configuration cache stays on+# (repo gradle.properties), so repeat runs are cheap.+#+# Kotlin style lives in the root .editorconfig (indent 4, max line 120,+# LF, final newline); ktlint runs its standard rule set against it.+# Rust style lives in the root rustfmt.toml (max_width 100). A module+# with no Rust sources simply skips the cargo step.+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+ROOT="$SCRIPT_DIR"++print_help() {+ sed -n '2,/^set -euo/p' "$SCRIPT_DIR/format" | sed 's/^# \{0,1\}//' | head -n -1+}++normalize_module() {+ local m="$1"+ m="$(echo "$m" | xargs)"+ m="$(echo "$m" | sed -e 's|^[/:]*||' -e 's|[/:]*$||')"+ m="$(echo "$m" | tr '/' ':')"+ while echo "$m" | grep -q "::"; do m="$(echo "$m" | sed 's/::/:/g')"; done+ echo "$m" | tr '[:upper:]' '[:lower:]'+}++# Same set as ./check's 'all': app + library convention modules (the ones+# that apply the ktlint convention). Pure-JVM modules are excluded here+# but still accepted when named explicitly.+all_module_dirs() {+ grep -E 'include\(":[^"]+"\)' "$ROOT/settings.gradle.kts" 2>/dev/null \+ | sed -E 's/.*include\(":([^"]+)"\).*/\1/' \+ | tr ':' '/' \+ | while IFS= read -r p; do+ case "$p" in "" ) continue;; esac+ if [[ -f "$ROOT/$p/build.gradle.kts" ]] \+ && grep -qE 'common-conventions-(app|library)' "$ROOT/$p/build.gradle.kts" 2>/dev/null; then+ echo "$p"+ fi+ done | sort -u+}++CHECK_ONLY=0+ARGS=()+for arg in "$@"; do+ case "$arg" in+ --check) CHECK_ONLY=1;;+ --help|-h|help) print_help; exit 0;;+ *) ARGS+=("$arg");;+ esac+done+if [[ ${#ARGS[@]} -eq 0 ]]; then print_help; echo ""; echo "Error: no modules specified."; exit 1; fi++MODS=(); ALL_EXP=0+for raw in "${ARGS[@]}"; do+ norm="$(normalize_module "$raw")"+ [[ -z "$norm" ]] && continue+ if [[ "$norm" == "all" ]]; then+ if [[ $ALL_EXP -eq 0 ]]; then+ while IFS= read -r sm; do+ case "$sm" in "" ) continue;; esac+ MODS+=("$sm")+ done < <(all_module_dirs)+ ALL_EXP=1+ fi+ continue+ fi+ if [[ "$norm" != *":"* ]]; then+ for pfx in games personal; do+ [[ -f "$ROOT/$pfx/$norm/build.gradle.kts" ]] && { norm="$pfx:$norm"; break; }+ done+ fi+ fs="$(echo "$norm" | tr ':' '/')"+ if [[ ! -f "$ROOT/$fs/build.gradle.kts" ]]; then+ echo "Error: unknown module '$raw' (-> $fs/, no build.gradle.kts)." >&2; exit 1+ fi+ dup=0; for m in ${MODS[@]:-}; do [[ "$m" == "$fs" ]] && dup=1; done+ [[ $dup -eq 0 ]] && MODS+=("$fs")+done+[[ ${#MODS[@]} -gt 0 ]] || { echo "Error: no valid modules." >&2; exit 1; }++KT_TASK="ktlintFormat"; FMT_LABEL="cargo fmt"+if [[ $CHECK_ONLY -eq 1 ]]; then KT_TASK="ktlintCheck"; FMT_LABEL="cargo fmt --check"; fi++TASKS=()+for mod in "${MODS[@]}"; do+ gmod="$(echo "$mod" | tr '/' ':')"+ TASKS+=(":$gmod:$KT_TASK")+done+echo "Modules (${#MODS[@]}): ${MODS[*]}"+echo "Mode: $([[ $CHECK_ONLY -eq 1 ]] && echo check || echo format)"+echo "Gradle tasks: ${TASKS[*]}"+echo ""++GRADLE_RC=0+"$SCRIPT_DIR/gradlew" "${TASKS[@]}" --continue --console=plain || GRADLE_RC=$?+echo ""+[[ $GRADLE_RC -ne 0 ]] && echo "Warning: $KT_TASK reported failures (exit $GRADLE_RC)."++# --- cargo fmt (rust modules only; same crate scoping as ./check) ---+# Workspace members share one root invocation via -p; standalone crates+# (own [workspace] table) are handled individually in their own dir.+ROOT_CRATES=()+STANDALONE_DIRS=()+for mod in "${MODS[@]}"; do+ rdir="$ROOT/$mod/src/main/rust"+ ct="$rdir/Cargo.toml"+ if [[ -f "$ct" ]]; then+ if grep -qE '^\[workspace\][[:space:]]*$' "$ct"; then+ STANDALONE_DIRS+=("$rdir")+ echo "Rust: $mod -> standalone crate ($rdir)"+ else+ name="$(sed -nE 's/^name *= *"([^"]+)".*/\1/p' "$ct" | head -1)"+ [[ -n "$name" ]] && ROOT_CRATES+=("$name") && echo "Rust: $mod -> workspace crate $name"+ fi+ fi+done+CARGO_RC=0+if [[ ${#ROOT_CRATES[@]} -gt 0 || ${#STANDALONE_DIRS[@]} -gt 0 ]]; then+ if command -v cargo >/dev/null 2>&1; then+ CARGO_BIN="cargo"+ else+ CARGO_BIN="${CARGO_HOME:-$HOME/.cargo}/bin/cargo"+ [[ -x "$CARGO_BIN" ]] || { echo "Error: cargo not found ($CARGO_BIN)." >&2; exit 1; }+ fi+fi+if [[ ${#ROOT_CRATES[@]} -gt 0 ]]; then+ echo ""+ FMT_ARGS=()+ for c in "${ROOT_CRATES[@]}"; do FMT_ARGS+=(-p "$c"); done+ if [[ $CHECK_ONLY -eq 1 ]]; then FMT_ARGS=(--check "${FMT_ARGS[@]}"); fi+ echo "Running: $FMT_LABEL ${FMT_ARGS[*]}"+ ( cd "$ROOT" && "$CARGO_BIN" fmt "${FMT_ARGS[@]}" ) || CARGO_RC=$?+ [[ $CARGO_RC -ne 0 ]] && echo "Warning: $FMT_LABEL (workspace) reported failures (exit $CARGO_RC)."+fi+for rdir in ${STANDALONE_DIRS[@]:-}; do+ echo ""+ echo "Running: $FMT_LABEL (in $rdir)"+ if [[ $CHECK_ONLY -eq 1 ]]; then+ ( cd "$rdir" && "$CARGO_BIN" fmt --check ) || CARGO_RC=$?+ else+ ( cd "$rdir" && "$CARGO_BIN" fmt ) || CARGO_RC=$?+ fi+ [[ $CARGO_RC -ne 0 ]] && echo "Warning: $FMT_LABEL ($rdir) reported failures (exit $CARGO_RC)."+done+if [[ ${#ROOT_CRATES[@]} -eq 0 && ${#STANDALONE_DIRS[@]} -eq 0 ]]; then+ echo "No Rust crates in scope; cargo steps skipped."+fi++if [[ $GRADLE_RC -ne 0 || $CARGO_RC -ne 0 ]]; then exit 1; fi+exit 0
gradle/libs.versions.toml
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 7346d32e6e..e86505a25d 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -21,6 +21,11 @@ desugarJdkLibs = "2.1.5" # Alpha because no stable detekt supports Kotlin 2.4 yet; revisit on 2.0.0 stable. detekt = "2.0.0-alpha.6" +# Kotlin formatting: ktlint (standard rule set) via the Gradle plugin.+# The plugin reads the committed root .editorconfig (indent 4, max line 120,+# LF, final newline) and exposes ktlintFormat/ktlintCheck per module.+ktlint = "14.2.0"+ # Kotlin stdlib ecosystem (JetBrains) kotlinxCoroutines = "1.11.0" kotlinxSerializationJson = "1.13.0"@@ -193,6 +198,10 @@ symbol-processing-gradle-plugin = { module = "com.google.devtools.ksp:symbol-pro # NB: 2.x lives under the dev.detekt group; the old # io.gitlab.arturbosch.detekt marker has no 2.x alpha on Maven Central. detekt-gradle-plugin = { module = "dev.detekt:detekt-gradle-plugin", version.ref = "detekt" }+# Plugin jar so build-logic can put ktlint on its classpath; convention plugins+# then apply it versionless as id("org.jlleitschuh.gradle.ktlint") (same pattern+# as detekt-gradle-plugin above).+ktlint-gradle-plugin = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" } desugar-jdk-libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugarJdkLibs" } # Kotlin stdlib ecosystem (JetBrains)@@ -413,5 +422,8 @@ protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" } # Static code analysis for Kotlin (applied in common-conventions-app/library; # 2.x plugin id is dev.detekt). detekt = { id = "dev.detekt", version.ref = "detekt" }+# Kotlin formatter (applied in common-conventions-app/library; rules in the+# root .editorconfig, tasks ktlintFormat/ktlintCheck).+ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" } # Dependency-update report (applied in the root build file; ./gradlew dependencyUpdates). versions = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" }
rustfmt.toml
diff --git a/rustfmt.toml b/rustfmt.tomlindex ad3c550c35..0ca3a0e73c 100644--- a/rustfmt.toml+++ b/rustfmt.toml@@ -1,5 +1,5 @@-# Rust formatting foundations (Phase 1 — advisory, no bulk reformat yet).-# `cargo fmt --check` is the warning inventory; bulk reformat deferred to Phase 4.+# Rust formatting. `./format <module>` writes it (cargo fmt);+# `./check <module>` fails on drift (cargo fmt --check). edition = "2021" max_width = 100 hard_tabs = false