Skip to content

fix(rules): route Kotlin script files to Kotlin review rules - #1091

Open
Qiyuanqiii wants to merge 2 commits into
alibaba:mainfrom
Qiyuanqiii:codex/issue-1090-kts-kotlin-rules
Open

fix(rules): route Kotlin script files to Kotlin review rules#1091
Qiyuanqiii wants to merge 2 commits into
alibaba:mainfrom
Qiyuanqiii:codex/issue-1090-kts-kotlin-rules

Conversation

@Qiyuanqiii

@Qiyuanqiii Qiyuanqiii commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

Summary

  • Route review-eligible .kt and .kts files to the existing built-in kotlin.md review rules.
  • Align the default Kotlin test-path exclusion so .kts files under src/test/** are excluded in the same way as .kt files.
  • Add deterministic resolver, extension, and exclusion regression coverage.
  • Keep the rule mapping documentation synchronized across the English, Chinese, Japanese, Korean, and Russian locales.
  • Integrate the follow-up contribution from @wu21-web in Qiyuanqiii/open-code-review#13.

Root Cause and Integrated Fix

OpenCodeReview uses separate configuration layers for file reviewability, default exclusions, and built-in rule selection:

  1. supported_file_types.json already allows both .kt and .kts.
  2. default_exclude_patterns.json previously excluded **/src/test/**/*.kt, but not the corresponding .kts files.
  3. system_rules.json previously mapped only **/*.{kt} to kotlin.md.

That produced two inconsistencies:

  • A review-eligible Kotlin script outside the default test exclusion passed the extension filter but fell back to default.md.
  • A Kotlin script under src/test/** remained reviewable even though the equivalent .kt test source was excluded by default.
Path Behavior before this change Behavior after this change
app.kt Reviewed with kotlin.md Reviewed with kotlin.md
scripts/setup.kts Reviewed with default.md Reviewed with kotlin.md
src/test/kotlin/FooTest.kt Excluded by default Excluded by default
src/test/kotlin/scripts/FooTest.kts Reviewed with default.md Excluded by default

Rule Routing

The built-in Kotlin mapping now covers both extensions:

- "**/*.{kt}": "kotlin.md"
+ "**/*.{kt,kts}": "kotlin.md"

TestResolve_DefaultRules resolves scripts/setup.kts and requires the Kotlin-specific Null Safety guidance. The existing .kt case remains in place.

Default Exclusion Parity

The existing Kotlin test-source exclusion now covers Kotlin scripts as well:

- "**/src/test/**/*.kt"
+ "**/src/test/**/*.{kt,kts}"

The allowlist regression table explicitly covers .kt, .KT, .kts, and .KTS. Exclusion cases verify that a nested .kts file under src/test/** is excluded while a .kts file under src/main/** remains eligible.

Collaboration

  • @wu21-web identified the default-exclusion inconsistency and contributed the allowlist and exclusion regression coverage through Qiyuanqiii/open-code-review#13.
  • Integration commit ca6052117224978853d56f1194dcbb3d3f970f8b preserves their GitHub authorship and includes Co-authored-by: wu21-web <wu2196674@icloud.com>.

Compatibility and Scope

  • Existing .kt rule resolution and default test exclusion are unchanged.
  • Review-eligible .kts files now receive the already-shipped Kotlin rules instead of the generic default rules.
  • .kts files under src/test/** are now excluded by default, matching the existing .kt behavior.
  • Custom, project, and global rules retain their existing precedence for files that enter review.
  • The contents of kotlin.md are unchanged.
  • No public API, CLI, configuration schema, parser, supported-extension allowlist, or production Go implementation changes are introduced.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

Validation Environment

  • Host: Windows 11 Pro, build 26200, amd64
  • Go: go1.26.5 windows/amd64
  • Node.js: v24.14.0
  • Baseline: eda25482c74dff2f03bed2648497f23c512effe9 (origin/main)
  • Original routing commit: b69402f9b0be7ae0ad916a61c259f14a5c75305b
  • Integrated head: ca6052117224978853d56f1194dcbb3d3f970f8b

GNU Make is exposed as mingw32-make on this host. The unchanged Makefile targets were run with Git Bash and its Unix tools on PATH.

Regression Coverage

  • The resolver test fails on the baseline because scripts/setup.kts falls through to default.md, which lacks the asserted Null Safety guidance.
  • The updated mapping resolves both .kt and .kts paths to kotlin.md.
  • Extension tests cover lowercase and uppercase .kt and .kts inputs.
  • Exclusion tests distinguish src/test/kotlin/scripts/FooTest.kts from src/main/kotlin/scripts/Foo.kts.

Final Validation

  • make check passed on the integrated patch: license headers, English-only validation, go mod tidy, gofmt -s -w ., and go vet
  • Full make test passed with the race detector across every non-extension Go package
  • make coverage passed at 90.9% overall; internal/config/allowlist was 88.9% and internal/config/rules was 91.7%
  • git add --renormalize . introduced no unrelated line-ending changes
  • git diff --check passed
  • Required OCR self-review completed with 0 findings (session f512adf9-0dd5-46fa-8825-42a09f94c0dc)
  • Current-head GitHub checks passed: CI, Windows, all cross-compilation targets, CodeQL, Pages, translation sync, and CLA

OCR Coverage

OCR selected default_exclude_patterns.json and reported 0 findings. allowed_ext_test.go was skipped by the repository's default test-path filter, so the OCR result is not presented as coverage of both contributed files; the test change was reviewed directly and exercised by the full race-test and coverage runs.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of the integrated change
  • I have added tests that prove the routing and exclusion behavior
  • New and existing unit tests pass locally with the integrated change
  • I have updated the rule mapping documentation across all maintained locales
  • Contributor authorship is preserved
  • I have signed the CLA

Known Limitations

  • Review-eligible .kts files reuse the existing Kotlin rules; this change does not add separate Gradle Kotlin DSL guidance.
  • The default exclusion expansion is limited to the existing src/test/** Kotlin convention and does not introduce new test-directory patterns.
  • This does not change rule precedence or the general rule-resolution mechanism.

Related Issues and Contributions

Closes #1090.

Includes Qiyuanqiii/open-code-review#13 by @wu21-web.

@github-actions

Copy link
Copy Markdown
Contributor

OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@wu21-web

Copy link
Copy Markdown
Contributor

Can I review this?

@Qiyuanqiii

Copy link
Copy Markdown
Contributor Author

我可以复习一下吗?

sure

@wu21-web

Copy link
Copy Markdown
Contributor

Some suggestion are out of range and cannot be put in the diff, I have submitted a pull request instead:
Qiyuanqiii#13

@Qiyuanqiii

Copy link
Copy Markdown
Contributor Author

有些建议超出范围,无法放入差异,我已提交了拉取请求:启源qiii#13

Thanks for the follow‑up. I see that this PR addresses default exclusion parity for Kotlin test scripts, while #1091 is narrowly scoped to routing .kts files to the existing Kotlin rules. Since this changes file‑selection behavior, I think it would be better to keep it separate for independent review. What are your thoughts?

@wu21-web

Copy link
Copy Markdown
Contributor

Actually I thought about routing .kts to kotlin.md few days ago, but I think it is unnesscary.
Since you restarted this idea, I won't oppose it.
Changes are minimal, and in my opinion both ways are OK.
It is fine you want to split this into 2 jobs. Up to you.

@Qiyuanqiii

Copy link
Copy Markdown
Contributor Author

其实我几天前也想过把 .kts 路由到那个地方,但我觉得这不太必要。既然你重新提起了这个想法,我就不反对了。变化很小,我认为两种方式都可以。你想把这份工作分成两个工作没问题。随你决定。kotlin.md

我是想分两个,你觉得麻烦的话我也可以合并了然后修改一下pr描述()

@wu21-web

Copy link
Copy Markdown
Contributor

我肯定觉得麻烦的,我自己的pr他还一个都没处理
还有我的修改如果有漏洞,你自己修改一下我的分支谢谢

Extend the default Kotlin test-path exclusion to `.kts` and add focused extension and exclusion regression coverage.

Validated on the alibaba#1091 branch with `make check`, `make test`, `make coverage`, and the required OCR self-review.

Co-authored-by: wu21-web <wu2196674@icloud.com>
@Qiyuanqiii

Copy link
Copy Markdown
Contributor Author

@wu21-web Thanks for the follow-up contribution. I merged #13 into this branch, updated the PR description to cover both rule routing and default exclusion parity, and preserved your authorship and co-author credit in commit ca60521. I also reran make check, make test, make coverage, and the required OCR self-review on the integrated patch; all current-head GitHub checks are passing.

@wu21-web wu21-web left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note sure if the rule docs need an update, but we might skip it for now.

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.

Kotlin script (.kts) files do not load the built-in Kotlin review rules

2 participants