Skip to content

Add Kotlin language support#10

Merged
daniel-munoz merged 14 commits into
mainfrom
kotlin
Jul 26, 2026
Merged

Add Kotlin language support#10
daniel-munoz merged 14 commits into
mainfrom
kotlin

Conversation

@daniel-munoz

Copy link
Copy Markdown
Owner

Summary

  • Adds Kotlin as a fourth supported language via a new internal/language/kotlin/ provider, following the established tree-sitter pattern (grammar: tree-sitter-grammars/tree-sitter-kotlin v1.1.0)
  • Parser extracts metrics for top-level functions, class/object/interface/companion/enum methods, package names, imports, and cyclomatic complexity (including when branches, &&/||, and the elvis operator)
  • Generic anti-pattern detectors (parameters, nesting, returns, magic numbers with const val/UPPER_CASE exemption) plus two Kotlin-specific detectors: !! non-null assertions and runBlocking usage (exempting only top-level fun main), both config-gated via detect_non_null_assertions / detect_run_blocking
  • Auto-detects Kotlin projects from Gradle manifests (settings.gradle.kts, build.gradle.kts, settings.gradle, build.gradle); detection caveats (Java-only Gradle repos, package.json precedence) documented in README troubleshooting
  • Coverage and dependency analysis intentionally return "not supported" in this first iteration (Kover/JaCoCo and Gradle manifest parsing are natural follow-ups)

Design spec and implementation plan are included under docs/superpowers/.

Test Plan

  • go test -short ./... — full suite green (19 packages)
  • go run . analyze testdata/kotlin --language kotlin --verbose — 3 files, 17 functions, expected issues found (incl. !!, runBlocking outside main, magic numbers with UPPER_CASE exemption)
  • Auto-detection from a build.gradle.kts fixture project without --language
  • Go self-analysis regression unchanged; JSON/markdown/HTML outputs valid; storage + --compare round-trip works
  • Smoke run against a real inherited Kotlin service repo

🤖 Generated with Claude Code

@daniel-munoz
daniel-munoz force-pushed the kotlin branch 4 times, most recently from f157137 to 1541eb2 Compare July 25, 2026 21:37
@daniel-munoz
daniel-munoz force-pushed the kotlin branch 3 times, most recently from 36cb619 to 3d34bb8 Compare July 26, 2026 05:57
@claude

claude Bot commented Jul 26, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

daniel-munoz and others added 13 commits July 25, 2026 23:19
Mirrors the Python provider's structure: sequential/parallel directory
walking via internal/parallel, per-package glob helpers, and cyclomatic
complexity calculation over verified tree-sitter-kotlin v1.1.0 node kinds.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
extractDeclarations only recursed into class_body, so functions declared
directly in an enum class body (kind enum_class_body) were silently
dropped. Fall back to enum_class_body when class_body is absent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Implements config wiring for two new Kotlin-specific anti-pattern detectors:
- detect_non_null_assertions: Flag !! non-null assertion usage
- detect_run_blocking: Flag runBlocking usage outside fun main

Follows the existing pattern for detect_magic_numbers and detect_duplicate_errors,
adding defaults to constants.go, struct fields to AnalysisConfig, and merge logic
to LoadConfig() and mergeAntiPatternSettings(). All detectors default to enabled.

Includes TDD-driven test coverage validating defaults and merge behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds YAML fixture entries for detect_non_null_assertions and detect_run_blocking
to the TestLoadConfig_ValidConfigFile test, exercising the mapstructure tags and
viper unmarshaling round-trip behavior.

Also extends the TestMerge "merge Phase 2.2 anti-pattern overrides" test case to
validate merge logic for both new Kotlin detector flags, ensuring consistency with
existing anti-pattern detector tests (detect_magic_numbers, detect_duplicate_errors).

This completes the round-trip test coverage pattern established by the codebase,
covering defaults, viper unmarshaling, and merge behavior for the new options.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Mirrors the Python tree-sitter detector runner structure: re-parses the
file, locates each function's body by name/start line, and runs the
generic detectors (too many parameters, deep nesting, too many returns,
magic numbers) plus Kotlin-specific detectors for non-null assertions
(!!) and runBlocking (excluding fun main, where it's the legitimate
coroutine bridge idiom).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The previous guard (fn.Name != "main") exempted any function named
main from run_blocking detection, including class methods that are
not JVM entry points (e.g. class Runner { fun main() { runBlocking {} } }).
Now only a top-level fun main (ReceiverType == "") is exempt.

Also documents two accepted detector limitations: else-if chains count
toward nesting depth (inherent to the AST), and fully-qualified
kotlinx.coroutines.runBlocking calls are not matched by the
plain-identifier check.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Implements language.Language interface for Kotlin code analysis:
- Provider mirrors Python provider pattern exactly
- Registers parser and detector runner
- Adds Kotlin-specific exclude patterns (build/, .gradle/, test sources)
- Coverage and dependency analysis stubbed for future phases
- Registers Kotlin in orchestrator with alphabetical ordering

All 15 Kotlin tests pass (12 existing + 3 new provider tests).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Extend language.DetectLanguage to recognize Kotlin projects by scanning for
Gradle manifest files (build.gradle.kts, settings.gradle.kts, build.gradle,
settings.gradle). Kotlin detection is prioritized after existing languages
(Go, Python, JavaScript) to preserve existing manifest precedence.

- Added blank import of kotlin language provider to registry_test.go
- Added four new test cases for Kotlin detection (Gradle Kotlin DSL and Groovy)
- Added priority test to ensure Go takes precedence over Kotlin
- Extended manifestChecks slice in registry.go to include Gradle files
- Updated error message to list Kotlin as a supported language
- Updated doc comment to list all supported manifest types

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Fix gofmt formatting: change double space to single space before comments
- Add subtest for settings.gradle.kts priority among Gradle manifest variants
- Verifies multiple Gradle manifests coexisting resolve cleanly

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Add Kotlin to language options in analyze command (--language flag and Long description)
- Add Kotlin example to analyze command usage
- Add Kotlin to init command default config template
- Add detect_non_null_assertions and detect_run_blocking options to all configs
- Update README with Kotlin in supported languages table
- Add Kotlin to auto-detection manifest list (build.gradle, build.gradle.kts)
- Add Kotlin examples to Quick Start section
- Add comprehensive Kotlin language-specific features section
- Update configuration reference blocks with Kotlin-specific detectors
- Update CLI reference language flag documentation
- Add Gradle projects troubleshooting section
- Update project structure tree with kotlin directories
- Add Kotlin provider to architecture components

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@daniel-munoz daniel-munoz reopened this Jul 26, 2026
@daniel-munoz
daniel-munoz merged commit 9357b3c into main Jul 26, 2026
4 checks passed
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.

1 participant