Skip to content

Commit

Permalink
Add support for Gradle assignment operator (#479)
Browse files Browse the repository at this point in the history
Summary:
Fixes #411.

Gradle added support for a [Kotlin assignment operator](https://blog.gradle.org/simpler-kotlin-dsl-property-assignment) to simplify property assignment.

This is done via a compiler plugin and this import: `import org.gradle.kotlin.dsl.assign` - which ktfmt detects as unused and removes.

This PR adds an `assign` operator to the operators in `com.facebook.ktfmt.format.RedundantImportDetector` and a corresponding test to ensure the import remains.

Pull Request resolved: #479

Reviewed By: cortinico

Differential Revision: D58440177

Pulled By: hick209

fbshipit-source-id: 89490d8542d38fa652824569417ef7be8dc66e63
  • Loading branch information
cloudshiftchris authored and facebook-github-bot committed Jun 12, 2024
1 parent 520706e commit 587a232
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ internal class RedundantImportDetector(val enabled: Boolean) {
// Property delegation operators
"getValue",
"setValue",
"provideDelegate")
"provideDelegate",
// assign operator - Gradle compiler plugin
// https://blog.gradle.org/simpler-kotlin-dsl-property-assignment
"assign",
)

private val COMPONENT_OPERATOR_REGEX = Regex("component\\d+")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@ class FormatterTest {
|import com.example.timesAssign
|import com.example.unaryMinus
|import com.example.unaryPlus
|import org.gradle.kotlin.dsl.assign
|"""
.trimMargin())

Expand Down

0 comments on commit 587a232

Please sign in to comment.