# New Check: ConfusingConditionCheck #90

Closed
opened this issue Nov 28, 2012 · 1 comment

Member

### romani commented Nov 28, 2012

 from PMD http://pmd.sourceforge.net/pmd-5.0.0/rules/index.html: ConfusingTernary: Avoid negation within an "if" expression with an "else" clause. For example, rephrase: if (x != y) diff(); else same();as: if (x == y) same(); else diff();Most "if (x != y)" cases without an "else" are often return cases, so consistent use of this rule makes the code easier to read. Also, this resolves trivial ordering problems, suchas "does the error case go first?" or "does the common case go first?". we just give idea from PMD, we have the constant problem in code - so we need to automate it a bit at least as in PMD. We need to check even short form of conditions "?(a != b)c=1:c=2;"

Member Author

### romani commented Dec 25, 2012

 Lets split task in two stages: simple Check for "!=" detection and advanced check to detect more complicated conditions. I am not 100% sure in success of second stage so lets finish+test first part and then try to do second in separate branch. In case it is ternary(http://en.wikipedia.org/wiki/%3F:), we could require modification (see "discrete math" for details, http://en.wikipedia.org/wiki/De_Morgan%27s_laws): !a ====> a !a && !b ====> a && b a != b ====> a ==b a != b && c != d ====> a ==b && c ==d !a || !b ====> a && b

``` Issue sevntu-checkstyle#90: Confusing Termary. fixed ```
``` 3045e29 ```

``` Issue sevntu-checkstyle#90: Confusing Termary. fixed ```
``` 74a8089 ```

``` Issue sevntu-checkstyle#90: Confusing Termary. fixed ```
``` e90acfa ```

``` Issue sevntu-checkstyle#90: Confusing Termary. fixed2 ```
``` dbec575 ```

### isopov added a commit that referenced this issue Sep 6, 2013

``` Merge pull request #130 from VadimPanasiuk/ConfusingTernaryCheck ```
`Issue #90: Confusing Termary. fixed`
``` f1f3858 ```