-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress
function-naming
based on annotations (#2275)
Add `.editorconfig` property `ktlint_function_naming_ignore_when_annotated_with` When using Compose, set property `ktlint_function_naming_ignore_when_annotated_with=Composable` to suppress the `function-naming` rule for functions annotated with `@Composable`. A dedicated ktlint ruleset like [Compose Rules](https://mrmans0n.github.io/compose-rules/ktlint/) can be used for checking naming conventions for such Composable functions. Closes #2259
- Loading branch information
1 parent
fac432f
commit cdd5904
Showing
8 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...n/com/pinterest/ktlint/rule/engine/core/api/editorconfig/CommaSeparatedListValueParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.pinterest.ktlint.rule.engine.core.api.editorconfig | ||
|
||
import org.ec4j.core.model.PropertyType | ||
import org.ec4j.core.model.PropertyType.PropertyValueParser | ||
|
||
/** | ||
* A [PropertyValueParser] implementation that allows a comma separate list of strings. | ||
*/ | ||
public class CommaSeparatedListValueParser : PropertyValueParser<Set<String>> { | ||
override fun parse( | ||
name: String?, | ||
value: String?, | ||
): PropertyType.PropertyValue<Set<String>> = | ||
if (value == "unset") { | ||
PropertyType.PropertyValue.valid(value, emptySet()) | ||
} else { | ||
PropertyType.PropertyValue.valid( | ||
value, | ||
value | ||
.orEmpty() | ||
.split(",") | ||
.map { it.trim() } | ||
.toSet(), | ||
) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...m/pinterest/ktlint/rule/engine/core/api/editorconfig/CommaSeparatedListValueParserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.pinterest.ktlint.rule.engine.core.api.editorconfig | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.ec4j.core.model.PropertyType | ||
import org.junit.jupiter.api.Test | ||
|
||
class CommaSeparatedListValueParserTest { | ||
private val propertyType = | ||
PropertyType.LowerCasingPropertyType( | ||
"some-property-type", | ||
null, | ||
CommaSeparatedListValueParser(), | ||
) | ||
|
||
@Test | ||
fun `Given a comma separated list property with value unset`() { | ||
val actual = propertyType.parse("unset") | ||
|
||
assertThat(actual.isUnset).isTrue() | ||
} | ||
|
||
@Test | ||
fun `Given a comma separated list property with a single value`() { | ||
val actual = propertyType.parse(SOME_VALUE_1) | ||
|
||
assertThat(actual.parsed).containsExactlyInAnyOrder(SOME_VALUE_1) | ||
} | ||
|
||
@Test | ||
fun `Given a comma separated list property with a multiple values`() { | ||
val actual = propertyType.parse("$SOME_VALUE_1,$SOME_VALUE_2") | ||
|
||
assertThat(actual.parsed).containsExactlyInAnyOrder(SOME_VALUE_1, SOME_VALUE_2) | ||
} | ||
|
||
@Test | ||
fun `Given a comma separated list property with a multiple values and redundant space before or after value`() { | ||
val actual = propertyType.parse(" $SOME_VALUE_1 , $SOME_VALUE_2 ") | ||
|
||
assertThat(actual.parsed).containsExactlyInAnyOrder(SOME_VALUE_1, SOME_VALUE_2) | ||
} | ||
|
||
private companion object { | ||
const val SOME_VALUE_1 = "some-value-1" | ||
const val SOME_VALUE_2 = "some-value-2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The URL points to 1.0.1 which leads to an error