Package: groovy.org.codenarc.rule.unnecessary

## [Groovy] Class UnnecessaryTernaryExpressionRule

- groovy.org.codenarc.rule.unnecessary.UnnecessaryTernaryExpressionRule

- Rule that checks for ternary expressions where the conditional expression always evaluates to a boolean and the true and false expressions are merely returning `true` and `false` constants. These cases can be replaced by a simple boolean expression. Examples include:

  - `boolean result = x==99 ? true : false` - can be replaced by `boolean result = x==99`
  - `boolean result = x && y ? true : false` - can be replaced by `boolean result = x && y`
  - `def result = x||y ? false : true` - can be replaced by `def result = !(x||y)`
  - `boolean result = x >= 1 ? true: false` - can be replaced by `boolean result = x >= 1`
  - `boolean result = x < 99 ? Boolean.TRUE : Boolean.FALSE` - can be replaced by `boolean result = x < 99`
  - `def result = !x ? true : false` - can be replaced by `def result = !x`
  The rule also checks for ternary expressions where the true and false expressions are the same constant or variable expression. Examples include:
  - `def result = x ? '123' : '123'` - can be replaced by `def result = '123'`
  - `def result = x ? null : null` - can be replaced by `def result = null`
  - `def result = x ? 23 : 23` - can be replaced by `def result = 23`
  - `def result = x ? MAX_VALUE : MAX_VALUE` - can be replaced by `def result = MAX_VALUE`
  Authors:
    Chris Mair

- - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `Class` | `astVisitorClass`
    `String` | `name`
    `int` | `priority`

- - ### Property Detail

    - #### Class astVisitorClass

    - #### String name

    - #### int priority