Skip to content

Detekt rule to prefer expressions over named functions for kotlin operators

License

Notifications You must be signed in to change notification settings

colematthew4/detekt-operator

Repository files navigation

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!

About

Detekt rule to prefer expressions over named functions for kotlin operators

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages