Skip to content

Commit 4a2750b

Browse files
committed
self review
1 parent 193be16 commit 4a2750b

File tree

8 files changed

+41
-21
lines changed

8 files changed

+41
-21
lines changed

ktlint/minor-version-rules/src/main/kotlin/software/aws/ktlint/rules/DeprecatedApiRule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal fun deprecatedUntilVersionRegex(major: Int, minor: Int): Regex =
2323
/**
2424
* Creates a ktlint rule that detects APIs annotated with @DeprecatedUntilVersion for the upcoming minor version.
2525
*/
26-
class DeprecatedApiRule : Rule(RuleId("$ruleSetId:deprecated-apis"), About()) {
26+
class DeprecatedApiRule : Rule(RuleId("$RULE_SET:deprecated-apis"), About()) {
2727
override fun beforeVisitChildNodes(
2828
node: ASTNode,
2929
autoCorrect: Boolean,

ktlint/minor-version-rules/src/main/kotlin/software/aws/ktlint/rules/MinorVersionRuleSetProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
88
import com.pinterest.ktlint.rule.engine.core.api.RuleProvider
99
import com.pinterest.ktlint.rule.engine.core.api.RuleSetId
1010

11-
internal const val ruleSetId = "aws-kotlin-repo-tools-rules"
11+
internal const val RULE_SET = "aws-kotlin-repo-tools-rules"
1212

13-
class MinorVersionRuleSetProvider : RuleSetProviderV3(RuleSetId(ruleSetId)) {
13+
class MinorVersionRuleSetProvider : RuleSetProviderV3(RuleSetId(RULE_SET)) {
1414
override fun getRuleProviders() = setOf(
1515
RuleProvider { DeprecatedApiRule() },
1616
)

ktlint/style-rules/src/main/kotlin/software/aws/ktlint/rules/CopyrightHeaderRule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.PsiCommentImpl
1111
import org.jetbrains.kotlin.lexer.KtTokens
1212
import org.jetbrains.kotlin.psi.stubs.elements.KtFileElementType
1313

14-
class CopyrightHeaderRule : Rule(RuleId("$ruleSetId:copyright-header"), About()) {
14+
class CopyrightHeaderRule : Rule(RuleId("$RULE_SET:copyright-header"), About()) {
1515
companion object {
1616
private val header = """
1717
/*

ktlint/style-rules/src/main/kotlin/software/aws/ktlint/rules/DeprecatedUntilVersionRule.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package software.aws.ktlint.rules
27

38
import com.pinterest.ktlint.rule.engine.core.api.ElementType
@@ -8,15 +13,15 @@ import org.jetbrains.kotlin.com.intellij.lang.ASTNode
813
/**
914
* Creates a ktlint rule that forces APIs annotated with @DeprecatedUntilVersion to also be annotated with @Deprecated.
1015
*/
11-
class DeprecatedUntilVersionRule : Rule(RuleId("$ruleSetId:deprecated-until-version"), About()) {
16+
class DeprecatedUntilVersionRule : Rule(RuleId("$RULE_SET:deprecated-until-version"), About()) {
1217
override fun beforeVisitChildNodes(
1318
node: ASTNode,
1419
autoCorrect: Boolean,
1520
emit: (offset: Int, errorMessage: String, canBeAutoCorrected: Boolean) -> Unit,
1621
) {
1722
if (node.elementType == ElementType.MODIFIER_LIST) {
1823
val annotations = node.getChildren(null).filter { it.elementType == ElementType.ANNOTATION_ENTRY }
19-
val deprecated = annotations.any { it.text == "@Deprecated" }
24+
val deprecated = annotations.any { it.text.startsWith("@Deprecated") }
2025
val deprecatedUntilVersion = annotations.any { it.text.startsWith("@DeprecatedUntilVersion") }
2126

2227
if (deprecatedUntilVersion && !deprecated) {

ktlint/style-rules/src/main/kotlin/software/aws/ktlint/rules/ExpressionBodyRule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.psi.KtBlockExpression
1111
import org.jetbrains.kotlin.psi.KtNamedFunction
1212
import org.jetbrains.kotlin.psi.KtReturnExpression
1313

14-
class ExpressionBodyRule : Rule(RuleId("$ruleSetId:expression-body"), About()) {
14+
class ExpressionBodyRule : Rule(RuleId("$RULE_SET:expression-body"), About()) {
1515
override fun beforeVisitChildNodes(
1616
node: ASTNode,
1717
autoCorrect: Boolean,

ktlint/style-rules/src/main/kotlin/software/aws/ktlint/rules/MultilineIfElseBlockRule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.pinterest.ktlint.rule.engine.core.api.Rule
99
import com.pinterest.ktlint.rule.engine.core.api.RuleId
1010
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
1111

12-
class MultilineIfElseBlockRule : Rule(RuleId("$ruleSetId:multiline-if-else-block"), About()) {
12+
class MultilineIfElseBlockRule : Rule(RuleId("$RULE_SET:multiline-if-else-block"), About()) {
1313
override fun beforeVisitChildNodes(
1414
node: ASTNode,
1515
autoCorrect: Boolean,

ktlint/style-rules/src/main/kotlin/software/aws/ktlint/rules/StyleRuleSetProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
88
import com.pinterest.ktlint.rule.engine.core.api.RuleProvider
99
import com.pinterest.ktlint.rule.engine.core.api.RuleSetId
1010

11-
internal const val ruleSetId = "aws-kotlin-repo-tools-rules"
11+
internal const val RULE_SET = "aws-kotlin-repo-tools-rules"
1212

13-
class StyleRuleSetProvider : RuleSetProviderV3(RuleSetId(ruleSetId)) {
13+
class StyleRuleSetProvider : RuleSetProviderV3(RuleSetId(RULE_SET)) {
1414
override fun getRuleProviders() = setOf(
1515
RuleProvider { CopyrightHeaderRule() },
1616
RuleProvider { ExpressionBodyRule() },

ktlint/style-rules/src/test/kotlin/software/aws/ktlint/rules/DeprecatedUntilVersionRuleTest.kt

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package software.aws.ktlint.rules
27

38
import com.pinterest.ktlint.rule.engine.api.Code
@@ -32,8 +37,8 @@ class DeprecatedUntilVersionRuleTest {
3237
@DeprecatedUntilVersion(1, 2)
3338
@Deprecated
3439
class Foo {}
35-
""".trimIndent(),
36-
)
40+
""".trimIndent(),
41+
),
3742
)
3843

3944
assertEquals(
@@ -43,8 +48,18 @@ class DeprecatedUntilVersionRuleTest {
4348
@Deprecated
4449
@DeprecatedUntilVersion(1, 2)
4550
class Foo {}
46-
""".trimIndent(),
47-
)
51+
""".trimIndent(),
52+
),
53+
)
54+
55+
assertEquals(
56+
false,
57+
hasLintingErrors(
58+
"""
59+
@Deprecated
60+
class Foo {}
61+
""".trimIndent(),
62+
),
4863
)
4964

5065
assertEquals(
@@ -53,8 +68,8 @@ class DeprecatedUntilVersionRuleTest {
5368
"""
5469
@DeprecatedUntilVersion(1, 2)
5570
class Foo {}
56-
""".trimIndent(),
57-
)
71+
""".trimIndent(),
72+
),
5873
)
5974

6075
assertEquals(
@@ -66,8 +81,8 @@ class DeprecatedUntilVersionRuleTest {
6681
6782
@Deprecated
6883
class Bar {}
69-
""".trimIndent(),
70-
)
84+
""".trimIndent(),
85+
),
7186
)
7287

7388
assertEquals(
@@ -79,8 +94,8 @@ class DeprecatedUntilVersionRuleTest {
7994
8095
@DeprecatedUntilVersion(1, 2)
8196
class Bar {}
82-
""".trimIndent(),
83-
)
97+
""".trimIndent(),
98+
),
8499
)
85100
}
86-
}
101+
}

0 commit comments

Comments
 (0)