/detekt-operator

Detekt rule to prefer expressions over named functions for kotlin operators

Primary LanguageKotlinApache License 2.0Apache-2.0

detekt-operator

Detekt style rules to prefer expressions over named functions for kotlin operators.

Build Status codecov

detekt-operator is a plugin for detekt that performs style checking for the use of named functions instead of their operator equivalents.

Currently Supported Operators

  • Unary Operators
    • a.unaryPlus() -> +a
    • a.unaryMinus() -> -a
    • a.not() -> !a
    • a.inc() -> a++
    • a.dec() -> a--
  • Arithmetic Operators
    • a.plus(b) -> a + b
    • a.minus(b) -> a - b
    • a.times(b) -> a * b
    • a.div(b) -> a / b
    • a.rem(b) -> a % b
    • a.rangeTo(b) -> a..b
  • a.contains(b) -> b in a
  • Index Accessor Operators
    • a.get(i) -> a[i]
    • a.set(i, j) -> a[i, j]
  • a.invoke() -> a()
  • Augmented Assignments
    • a.plusAssign(b) -> a += b
    • a.minusAssign(b) -> a -= b
    • a.timesAssign(b) -> a *= b
    • a.divAssign(b) -> a /= b
    • a.remAssign(b) -> a %= b
  • Equality and Inequality Operators
    • a.equals(b) -> a == b
    • !a.equals(b) -> a != b
  • Infix functions
  • Comparison Operators
    • a.compareTo(b) -> a > b
    • a.compareTo(b) -> a < b
    • a.compareTo(b) -> a >= b
    • a.compareTo(b) -> a <= b

Include in your project

Detekt CLI

detekt --input ... --plugins /path/to/detekt-operator/jar

Gradle

dependencies {
    detektPlugins "io.cole.matthew.detekt.operator:detekt-operator:0.0.1"
}

If you are encountering issues, visit detekt's documentation or raise an issue!