Skip to content

Commit

Permalink
Add exceptions to present tenses finishing in -ed (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmans0n authored May 28, 2024
1 parent bbeec96 commit 7ecede0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class ParameterNaming : ComposeKtVisitor {
}

private val String.isPastTense: Boolean
get() = endsWith("ed") || IrregularVerbsInPastTense.any { endsWith(it) }
get() = VerbsPresentTenseEndingInEd.none { endsWith(it) } &&
(endsWith("ed") || IrregularVerbsInPastTense.any { endsWith(it) })

companion object {
// A list of common irregular verbs in english, excluding those where present tense == past tense,
Expand Down Expand Up @@ -203,6 +204,28 @@ class ParameterNaming : ComposeKtVisitor {
)
}

// A list of verbs whose present tenses ends in -ed
private val VerbsPresentTenseEndingInEd by lazy {
setOf(
"Bed",
"Bleed",
"Embed",
"Exceed",
"Feed",
"Heed",
"Need",
"Proceed",
"Seed",
"Shed",
"Shred",
"Sled",
"Speed",
"Succeed",
"Wed",
"Weed",
)
}

val LambdaParametersInPresentTense = """
Lambda parameters in a composable function should be in present tense, not past tense.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ class ParameterNamingCheckTest {
val code =
"""
@Composable
fun A(onClick: () -> Unit, onValueChange: (Int) -> Unit, onWrite: () -> Unit, onPotato: Potato) {}
fun A(
onClick: () -> Unit,
onValueChange: (Int) -> Unit,
onWrite: () -> Unit,
onPotato: Potato,
onEmbed: () -> Unit,
) {}
""".trimIndent()

val errors = rule.lint(code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ class ParameterNamingCheckTest {
val code =
"""
@Composable
fun A(onClick: () -> Unit, onValueChange: (Int) -> Unit, onWrite: () -> Unit, onPotato: Potato) {}
fun A(
onClick: () -> Unit,
onValueChange: (Int) -> Unit,
onWrite: () -> Unit,
onPotato: Potato,
onEmbed: () -> Unit,
) {}
""".trimIndent()

ruleAssertThat(code)
Expand Down

0 comments on commit 7ecede0

Please sign in to comment.