partiql / partiql-lang-kotlin

PartiQL libraries and tools in Kotlin.
https://partiql.org/
Apache License 2.0
536 stars 60 forks source link

Add custom ktlint rules to prevent Java interop issues #1414

Closed alancai98 closed 2 months ago

alancai98 commented 3 months ago

Relevant Issues

Description

Adds custom ktlint rules to report on Java interop issues mentioned in https://github.com/partiql/partiql-lang-kotlin/issues/1387:

This PR integrates the checks into gradle and GH Actions. By default, the custom rules will not be run since there are quite a few usages of the above patterns throughout our code. These usages should be fixed in upcoming PRs. The following outlines how the custom rules can be run:

# No option -- runs the standard ktlint checks as before
❯ ./gradlew ktlintCheck

# `custom-ktlint-rules` parameter included -- runs the standard ktlint checks along with the custom ktlint rules
# Note: run on just the `main` sources; `test` sources are excluded
# Note: any detected issues won't fail-fast so that all detected issues can be reported
❯ ./gradlew ktlintCheck -Pcustom-ktlint-rules

# Run on a given subproject
❯ ./gradlew :partiql-ast:ktlintCheck -Pcustom-ktlint-rules

> Task :partiql-ast:ktlintMainSourceSetCheck
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToBinder.kt:21:17 Top-level public declaration found without `@file:JvmName` annotation: toBinder (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToBinder.kt:35:17 Top-level public declaration found without `@file:JvmName` annotation: toBinder (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToLegacyAst.kt:58:20 Top-level public declaration found without `@file:JvmName` annotation: toLegacyAst (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/normalize/Normalize.kt:22:22 Top-level public declaration found without `@file:JvmName` annotation: normalize (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:10:20 Top-level public declaration found without `@file:JvmName` annotation: sql (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:19:20 Top-level public declaration found without `@file:JvmName` annotation: sql (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:27:20 Top-level public declaration found without `@file:JvmName` annotation: sql (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:35:20 Top-level public declaration found without `@file:JvmName` annotation: sql (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:42:29 Top-level internal declaration found: concat (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:44:29 Top-level internal declaration found: concat (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:46:38 Top-level internal declaration found: plus (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:48:38 Top-level internal declaration found: plus (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:52:14 Top-level internal declaration found: NIL (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:54:14 Top-level internal declaration found: NL (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:56:14 Top-level internal declaration found: text (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:58:14 Top-level internal declaration found: link (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:60:14 Top-level internal declaration found: nest (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/Sql.kt:62:14 Top-level internal declaration found: list (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlBlock.kt:10:21 Top-level public declaration found without `@file:JvmName` annotation: sql (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/lang/ast/meta.kt:63:20 Top-level public declaration found without `@file:JvmName` annotation: to (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/lang/ast/meta.kt:65:19 Top-level public declaration found without `@file:JvmName` annotation: find (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/lang/ast/meta.kt:67:19 Top-level public declaration found without `@file:JvmName` annotation: hasMeta (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/lang/ast/meta.kt:69:19 Top-level public declaration found without `@file:JvmName` annotation: add (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/lang/ast/SourceLocationMeta.kt:78:5 Top-level public declaration found without `@file:JvmName` annotation: UNKNOWN_SOURCE_LOCATION (cannot be auto-corrected)
./partiql-lang-kotlin/partiql-ast/src/main/kotlin/org/partiql/lang/ast/SourceLocationMeta.kt:80:19 Top-level public declaration found without `@file:JvmName` annotation: sourceLocation (cannot be auto-corrected)

Output of the GH Action step running the custom ktlint rules can be seen here: https://github.com/partiql/partiql-lang-kotlin/actions/runs/8639028556/job/23684585083?pr=1414.

Other Information

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

github-actions[bot] commented 3 months ago

Conformance comparison report

Base (ab65143c9f4c6058a648894a5d576ae7153387ef) 363d943569bb2c02854ceb5b7e16a782bb63f154 +/-
% Passing 92.54% 92.54% 0.00%
:white_check_mark: Passing 5384 5384 0
:x: Failing 434 434 0
:large_orange_diamond: Ignored 0 0 0
Total Tests 5818 5818 0

Number passing in both: 5384

Number failing in both: 434

Number passing in Base (ab65143c9f4c6058a648894a5d576ae7153387ef) but now fail: 0

Number failing in Base (ab65143c9f4c6058a648894a5d576ae7153387ef) but now pass: 0

codecov-commenter commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 73.16%. Comparing base (d059c81) to head (15f6bfc). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1414 +/- ## ========================================= Coverage 73.16% 73.16% Complexity 2393 2393 ========================================= Files 247 247 Lines 17627 17627 Branches 3178 3178 ========================================= Hits 12896 12896 Misses 3854 3854 Partials 877 877 ``` | [Flag](https://app.codecov.io/gh/partiql/partiql-lang-kotlin/pull/1414/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=partiql) | Coverage Δ | | |---|---|---| | [CLI](https://app.codecov.io/gh/partiql/partiql-lang-kotlin/pull/1414/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=partiql) | `11.82% <ø> (ø)` | | | [EXAMPLES](https://app.codecov.io/gh/partiql/partiql-lang-kotlin/pull/1414/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=partiql) | `80.07% <ø> (ø)` | | | [LANG](https://app.codecov.io/gh/partiql/partiql-lang-kotlin/pull/1414/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=partiql) | `81.06% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=partiql#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.