Skip to content
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

Fixes/2017/ignore serial version UI d #2045

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

* Do not flag a (potential) mutable extension property in case the getter is annotated or prefixed with a modifier `property-naming` ([#2024](https://github.com/pinterest/ktlint/issues/2024))
* Do not merge an annotated expression body with the function signature even if it fits on a single line ([#2043](https://github.com/pinterest/ktlint/issues/2043))
* Ignore property with name `serialVersionUID` in `property-naming` ([#2045](https://github.com/pinterest/ktlint/issues/2045))

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ public class PropertyNamingRule :
) {
identifier
.text
.takeUnless { it.matches(SCREAMING_SNAKE_CASE_REGEXP) }
.takeUnless {
// Allow
// object Foo {
// private const val serialVersionUID: Long = 123
// }
it == SERIAL_VERSION_UID_PROPERTY_NAME
}?.takeUnless { it.matches(SCREAMING_SNAKE_CASE_REGEXP) }
?.let {
emit(
identifier.startOffset,
Expand Down Expand Up @@ -143,6 +149,7 @@ public class PropertyNamingRule :
val LOWER_CAMEL_CASE_REGEXP = "[a-z][a-zA-Z0-9]*".regExIgnoringDiacriticsAndStrokesOnLetters()
val SCREAMING_SNAKE_CASE_REGEXP = "[A-Z][_A-Z0-9]*".regExIgnoringDiacriticsAndStrokesOnLetters()
val BACKING_PROPERTY_LOWER_CAMEL_CASE_REGEXP = "_[a-z][a-zA-Z0-9]*".regExIgnoringDiacriticsAndStrokesOnLetters()
const val SERIAL_VERSION_UID_PROPERTY_NAME = "serialVersionUID"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pinterest.ktlint.ruleset.standard.rules

import com.pinterest.ktlint.test.KtLintAssertThat
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
Expand Down Expand Up @@ -172,4 +173,39 @@ class PropertyNamingRuleTest {
""".trimIndent()
propertyNamingRuleAssertThat(code).hasNoLintViolations()
}

@Nested
inner class `Issue 2017 - Given property is serialVersionUID` {
@Test
fun `Given property is present in companion object`() {
val code =
"""
class Foo1 {
companion object {
private const val serialVersionUID: Long = 123
}
}
class Foo2 {
companion object {
private const val serialVersionUID = 123L
}
}
""".trimIndent()
propertyNamingRuleAssertThat(code).hasNoLintViolations()
}

@Test
fun `Given property defined object is private const`() {
val code =
"""
object Foo1 {
private const val serialVersionUID: Long = 123
}
object Foo2 {
private const val serialVersionUID = 123L
}
""".trimIndent()
propertyNamingRuleAssertThat(code).hasNoLintViolations()
}
}
}