Skip to content

chore: AI-coding ruleset, only-new lint/checkstyle gate and API check - #68

Merged
TobiasDuelli merged 1 commit into
masterfrom
chore-ai-ruleset
Nov 19, 2026
Merged

TobiasDuelli merged 1 commit into
masterfrom
chore-ai-ruleset

Conversation

@TobiasDuelli

@TobiasDuelli TobiasDuelli commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Brings the AI-coding ruleset and quality setup of the other Gleap repos to the Android SDK, translated to Java and Android: Android Lint, Checkstyle and japicmp through the Gradle wrapper, with the same principle that a branch is judged only on what it adds. No SDK code, no build file, gradle.properties, wrapper, ProGuard file or release.yml changes: the tools are added by a Gradle init script for the quality runs only, and the published artifacts build byte-identical (below).

The kit

File What it does Adapted
AGENTS.md, CLAUDE.md (@AGENTS.md) What ships where, commands, definition of done, public API, security, traps, tests, stop and ask, production Every command run. Public API = Gleap, io.gleap.callbacks.* and what the Flutter and React Native SDKs import; technically public internals (GleapSessionController, GleapIdentifyService, …) are named as not API. Traps found while reading: Java 8 + min SDK 21 without desugaring, returnDefaultValues in unit tests, the test org.json, VERSION_NAME in BuildConfig, no consumer R8 rules, resources merging into apps, the publish plugin pinning Gradle/AGP
.claude/rules/code-conventions.md Java rules for new and changed code, one job one system, examples GleapLog, GleapHttp/GleapExecutor, GleapMainThread, GleapErrors.guard, org.json, KeyValueStore; null annotations and Javadoc on public API (Kotlin interop guide)
.claude/rules/host-app.md (new) Code that runs in the customer's app: main thread, leaks, the app's look, manifest/resources/R8, every Android version, WebViews and the Messenger protocol, the user's data Written against this code (GleapWidgetBridge, GleapExternalLinks, GleapProtectedFiles, GleapNetworkLogSanitizer, usesKeyboardPaddingOnly)
.claude/rules/testing.md Test first, never weaken a test, what needs what JUnit 4 through SdkTestEnvironment/FakeGleapServer and the *ForTesting seams; on-device tests on E2ETestBase with the network guard; no Mockito/Robolectric without asking
.claude/settings.json, .claude/hooks/*.sh After each edit of a Java or resource file of the SDK: compile its source set (≈1 s warm). Before a turn ends, once the branch changes the SDK, the app or the checks: quality/lint-new.sh, the unit tests and a compile of the sample app (≈6 s warm) Shell + jq; blocks once per unchanged tree. Runs in the worktree the file or session is in. Denies local.properties, keystores, ~/.gradle/gradle.properties, any publish*/*MavenCentral* task, git tag, tag pushes, gh release
.claude/agents/test-writer.md, .claude/commands/review.md Failing tests first; strict review Review topics: public API, Messenger protocol, main thread, lifecycle and leaks, Android versions, never crash the app, WebView and links, credentials and privacy, manifest/resources/R8
.githooks/pre-push, .githooks/install.sh git push runs quality/lint-new.sh; installed once with sh .githooks/install.sh Gradle has no install hook, so the script replaces pnpm install's prepare
quality/quality.init.gradle Adds the checks to :gleap only for runs that pass it with -I: lint config (in finalizeDsl, else gleap/build.gradle's lint { abortOnError false } wins), a Checkstyle task, two japicmp tasks A normal build, the release included, never sees it (:gleap:tasks --all without -I lists no quality* task)
quality/lint-new.sh Judges only what the branch adds compared with origin/master; exit 0 nothing new, 1 findings, 2 could not run See "Only new" below
quality/lint.xml, quality/lint-baseline.xml Android Lint (AGP 8.8.0's) with Kotlin interop enabled; the 291 findings of today's code Checks whose findings change with time (new library versions, target SDK) are off
quality/checkstyle.xml Checkstyle 12.3.1: file 700 / method 80 lines, 4 parameters, android.util.Log/AsyncTask imports, printStackTrace/System.out, Javadoc on public types and methods, empty catch, equals/hashCode, string ==, switch default, fall-through 12.3.1 is the last Checkstyle that runs on JDK 17 (13+ needs JDK 21)
quality/public-api.txt The classes japicmp fails on The wrappers' imports, Gleap and the types in its signatures
.github/workflows/ci.yml Unit tests, assembleRelease, :app:assembleDebug (new), and a new on-device job: connectedDebugAndroidTest on an API 34 emulator Actions pinned by SHA; setup-gradle stays on v5 as the existing comment says
.github/workflows/quality.yml quality/lint-new.sh --api on PRs with the base branch's quality/ So a PR cannot switch a check off or grow the baseline with its own edits; warns when a PR changes the checks or the build files

Only new

  • Android Lint writes every finding to its report; lint-new.sh counts each (issue, message, file) against quality/lint-baseline.xml and fails on any finding beyond those counts. Of several findings with the same message in a file, the ones on lines the branch added or changed are reported as the new ones. Lint's own baseline matches by issue, message and file only (checked in LintBaseline): with 264 identical "Unknown nullability" findings, a new one was reported at an old method, which would have sent an agent to annotate old public API.
  • Checkstyle runs on the changed Java files; only findings on added or changed lines count (git diff -U0 against the merge base, uncommitted and untracked files included).
  • japicmp 0.27.0 (--api) builds the merge base from git archive and compares the two classes.jar: a binary or source incompatible change to quality/public-api.txt fails, one to another public class is listed. Adding a method to a callback interface is source incompatible and fails.
  • The baseline is regenerated only with an AGP upgrade, in that PR (command in AGENTS.md, Traps); regenerating it reproduces the committed file byte for byte.

Checks run

On this branch, JDK 17 (/usr/libexec/java_home -v 17), warm Gradle:

Check Clean branch With planted violations
sh quality/lint-new.sh exit 0, ≈4 s exit 1: 2× UnknownNullness and DefaultLocale at the new method in Gleap.java, UnknownNullness at a new callback method; Checkstyle ParameterNumber, EmptyCatchBlock, IllegalImport (android.util.Log), printStackTrace, MissingJavadocMethod on the added lines
… old code A line added at the top of GleapMainActivity.java (1069 lines, 14 empty catches): nothing reported. 291 old lint findings: nothing reported
sh quality/lint-new.sh --api exit 0, ≈10 s exit 1: METHOD_ADDED_TO_INTERFACE on WidgetOpenedCallback; GleapSessionController.executePendingUpdates made package-private is listed, not failed; the new Gleap method is listed as compatible
.githooks/pre-push (stdin as git sends it) exit 0 exit 1 with the same findings; a tag push and a ref that is not checked out are skipped
Stop hook ({"stop_hook_active": …, "cwd": …}) exit 0, ≈6 s exit 2 with the findings and, because of the planted interface method, the sample app's compile error (MainApplication.java:66); with stop_hook_active and an unchanged tree: exit 0
Edit hook ({"tool_input": {"file_path": …}}) exit 0, ≈1 s exit 2 with javac's error for a main and a test file, with the resource merger's error for a broken strings.xml; a Gradle that cannot start (bad JAVA_HOME) only adds a note
.githooks/install.sh installs once, leaves an existing hook alone
./gradlew :gleap:testDebugUnitTest :gleap:assembleRelease :app:assembleDebug :gleap:assembleDebugAndroidTest green, 271 unit tests a planted behaviour change fails GleapRegionTest, named in the stop hook's output

The scripts run under dash too (Ubuntu's sh).

CI on this PR, all green: Quality 1m05s (this PR brings quality/, so it ran its own copy; --api built the base: nothing new, plus the expected warning that the PR changes the checks), Unit tests and release build 1m22s (271 unit tests, assembleRelease, :app:assembleDebug), On-device tests (emulator) 3m14s: the emulator booted in 33 s and all 8 on-device tests passed in 26 s, so the job needs no continue-on-error.

Published artifacts: byte-identical

Built from clean git archive copies with JDK 17: origin/master (bc94d85) twice to measure noise, this branch once.

for side in base1:origin/master base2:origin/master head:chore-ai-ruleset; do
  d=$T/${side%%:*}; mkdir -p $d; git archive ${side#*:} | tar -x -C $d
  (cd $d && ./gradlew -q :gleap:assembleRelease :gleap:sourceReleaseJar \
     :gleap:generatePomFileForMavenPublication :gleap:generateMetadataFileForMavenPublication)
done
# then shasum -a 256 and cmp of the four files below between the sides
Artifact SHA-256 (first 16) base1 = base2 (noise) base = branch
outputs/aar/gleap-release.aar db60225373ab2bba = =
intermediates/source_jar/release/release-sources.jar b77555b51d6dbc8e = =
publications/maven/pom-default.xml 967738fd41b49a57 = =
publications/maven/module.json a9dd52613669960d = =

Noise is zero: AGP writes the AAR's entries with a fixed date (1980-02-01) and a fixed order; a rebuild with JDK 18 gave the same bytes too. The .asc signatures differ on every release by design and are not compared.

Research: adopted and rejected

Topic Decision Why Source
Android Lint with a baseline Adopted, counted per (issue, message, file) by the script Native, catches findings off the changed lines; lint's own matching ignores lines lint baseline
Kotlin interop checks (UnknownNullness, LambdaLast, …) Adopted for new code Kotlin apps and the wrappers see platform types without annotations Kotlin-Java interop
Checkstyle Adopted, 12.3.1, diff-filtered No baseline mode; 13+ needs JDK 21 Checkstyle 13.0.0
PMD, SpotBugs, Error Prone Rejected for now No only-new mode; Error Prone also changes the compile PMD discussion
spotless / google-java-format Rejected Ratcheting reformats whole touched files: old code would be rewritten
ktlint, detekt Not applicable No Kotlin sources
API check: japicmp Adopted (0.27.0, CLI through a Gradle configuration) Works on Java bytecode, no build change, compares with the merge base japicmp CLI
metalava (metalava-gradle) Rejected for now 0.5.x needs Gradle 9 metalava-gradle
Kotlin binary-compatibility-validator Rejected Needs a Kotlin plugin, in maintenance RevenueCat on BCV
On-device tests in CI Adopted: android-emulator-runner, API 34 google_apis (has a WebView) Gradle-managed devices would need a build file change emulator runner, managed devices
Robolectric, Mockito, JUnit 5 Not added The suite uses its own seams and fakes; JUnit 5 on Android needs a third-party plugin
Configuration cache, version catalog, Gradle 9 / AGP Follow-ups Each is a build change of its own configuration cache
Claude Code hooks Per-edit compile + stop gate Exit 2 feeds the agent; stop_hook_active stops loops hooks

Dev tools added

All through Gradle, nothing in a build file or gradle.properties: Checkstyle 12.3.1, japicmp 0.27.0 (jar-with-dependencies). Android Lint is AGP 8.8.0's. Actions pinned by SHA: actions/checkout v7.0.1, actions/setup-java v6.3.0, gradle/actions/setup-gradle v5.0.2, reactivecircus/android-emulator-runner v2.38.0, actions/upload-artifact v7.0.2. Needs jq for the hooks (CI runners and macOS ship it).

Found while setting up (not fixed here)

  • Lint's only error on today's code, NewApi in GleapMainActivity.java:295 (setOnScrollChangeListener, API 23), is guarded indirectly: usesKeyboardPaddingOnly() is true only from API 35. In the baseline.
  • 27 lint findings in old code besides the 264 missing null annotations: SetJavaScriptEnabled (3), RtlHardcoded (4), ObsoleteSdkInt (3), PrivateApi/DiscouragedPrivateApi (4), StaticFieldLeak (HttpHelper.context), InlinedApi, DefaultLocale (GleapConfig), and others. Full list in quality/lint-baseline.xml.
  • :app compiles against SDK 34 but targets 36, and uses okhttp 4.2.2 and android.support.test as its runner name.

Not in this PR

  • Gradle 9 / AGP upgrade (with the publish plugin), a version catalog, the configuration cache.
  • No branch protection, required checks or other repo settings changed. After merge, CI and Quality could become required checks.

🤖 Generated with Claude Code

AGENTS.md (with CLAUDE.md importing it), rules for code conventions, tests and code
that runs in the customer's app, Claude Code settings with a per-edit compile hook
and a stop hook, a test-writer agent and a review command.

quality/lint-new.sh judges only what a branch adds: Android Lint findings beyond
quality/lint-baseline.xml (291 for the code today), Checkstyle findings on added
lines, and with --api japicmp against the base's build (fails on an incompatible
change to quality/public-api.txt, lists the rest). The tools are added through
quality/quality.init.gradle for these runs only: no build file changes.

CI pins actions by SHA, builds the sample app and runs the on-device tests on an
emulator; quality.yml runs the gate on PRs with the base branch's quality/.
git push runs the gate (.githooks/pre-push, installed with .githooks/install.sh).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TobiasDuelli
TobiasDuelli marked this pull request as ready for review November 19, 2026 09:26
@TobiasDuelli
TobiasDuelli merged commit 6bffcf4 into master Nov 19, 2026
3 checks passed
@TobiasDuelli
TobiasDuelli deleted the chore-ai-ruleset branch November 19, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants