-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom ktlint rules to prevent Java interop issues #1414
Conversation
920f702
to
f52f525
Compare
Conformance comparison report
Number passing in both: 5384 Number failing in both: 434 Number passing in Base (ab65143) but now fail: 0 Number failing in Base (ab65143) but now pass: 0 |
f52f525
to
15f6bfc
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
4004c77
to
0336d9d
Compare
// Custom ktlint rules are added by adding to the `dependencies` block: https://github.com/JLLeitschuh/ktlint-gradle/tree/v10.2.0?tab=readme-ov-file#configuration | ||
// Currently, we only run the rules when the `custom-ktlint-rules` property is set. | ||
// Once we enable the custom rules to run by default, this conditional can be removed. | ||
if (hasProperty("custom-ktlint-rules")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After the internal
top-level and public
top-level code issues are resolved, we can remove this property logic such that the custom ktlint rules will run by default.
# End state after existing code issues detected by custom ktlint rules are resolved
> ./gradlew ktlintCheck # will run standard and custom rules
Any detected issues in gradle and GH Actions will also fail the build.
const val pig = "0.6.2" | ||
const val kotlinxCoroutines = "1.6.0" | ||
const val kotlinxCoroutinesJdk8 = "1.6.0" | ||
const val ktlint = "0.42.1" // we're on an old version of ktlint. TODO upgrade https://github.com/partiql/partiql-lang-kotlin/issues/1418 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did we go back from 11.6.0 to 0.42.1? Was the original one for the the gradle plugin, and this is for the custom rule dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were a couple confusing things here previously.
- The
ktlint
dependency defined previously actually referred to the ktlint gradle plugin -- https://github.com/JLLeitschuh/ktlint-gradle and not the actualktlint
Maven dependency -- https://github.com/pinterest/ktlint - The 11.6.0 dependency (defined in
buildSrc/src/main/kotlin/partiql.versions.kt
) was actually unused. We were actually using the 10.2.1 ktlint gradle plugin defined inbuildSrc/build.gradle.kts
The v0.42.1 refers to the default ktlint
version that the 10.2.1 kotlin gradle plugin uses (see their source). I chose to use the same ktlint
version for the custom rules that we were using for the default ktlintCheck
/ktlintFormat
runs. I didn't upgrade the default ktlint
version from v0.42.1 to a newer one since there are some additional rules that our code is not compliant with. We can perform this ktlint
version upgrade in a future PR (tracked in #1418).
Hope that makes things clearer.
custom-ktlint-rules/src/main/kotlin/org/partiql/ktlint/rule/TopLevelInternalRule.kt
Show resolved
Hide resolved
custom-ktlint-rules/src/main/kotlin/org/partiql/ktlint/rule/TopLevelPublicRule.kt
Show resolved
Hide resolved
const val pig = "0.6.2" | ||
const val kotlinxCoroutines = "1.6.0" | ||
const val kotlinxCoroutinesJdk8 = "1.6.0" | ||
const val ktlint = "0.42.1" // we're on an old version of ktlint. TODO upgrade https://github.com/partiql/partiql-lang-kotlin/issues/1418 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were a couple confusing things here previously.
- The
ktlint
dependency defined previously actually referred to the ktlint gradle plugin -- https://github.com/JLLeitschuh/ktlint-gradle and not the actualktlint
Maven dependency -- https://github.com/pinterest/ktlint - The 11.6.0 dependency (defined in
buildSrc/src/main/kotlin/partiql.versions.kt
) was actually unused. We were actually using the 10.2.1 ktlint gradle plugin defined inbuildSrc/build.gradle.kts
The v0.42.1 refers to the default ktlint
version that the 10.2.1 kotlin gradle plugin uses (see their source). I chose to use the same ktlint
version for the custom rules that we were using for the default ktlintCheck
/ktlintFormat
runs. I didn't upgrade the default ktlint
version from v0.42.1 to a newer one since there are some additional rules that our code is not compliant with. We can perform this ktlint
version upgrade in a future PR (tracked in #1418).
Hope that makes things clearer.
custom-ktlint-rules/src/main/kotlin/org/partiql/ktlint/rule/TopLevelPublicRule.kt
Show resolved
Hide resolved
custom-ktlint-rules/src/main/kotlin/org/partiql/ktlint/rule/TopLevelInternalRule.kt
Show resolved
Hide resolved
@@ -26,23 +26,23 @@ object Versions { | |||
const val detekt = "1.20.0-RC1" | |||
const val dokka = "1.6.10" | |||
const val kotlin = "1.6.20" | |||
const val ktlint = "10.2.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, we were actually using this version, 10.2.1
of the ktlint gradle plugin -- https://github.com/JLLeitschuh/ktlint-gradle/tree/v10.2.1.
(cherry picked from commit 4851cac)
Relevant Issues
Description
Adds custom ktlint rules to report on Java interop issues mentioned in #1387:
internal
functions and valuespublic
functions and values without a@file:JvmName
annotationThis 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:
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
Updated Unreleased Section in CHANGELOG: [NO]
Any backward-incompatible changes? [NO]
Any new external dependencies? [YES]
com.pinterest.ktlint:ktlint-core:0.42.1
com.pinterest.ktlint:ktlint-test:0.42.1
Do your changes comply with the Contributing Guidelines
and Code Style Guidelines? [YES]
License Information
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.