New Check: Nested Ternary #98

Closed
daniilyar opened this Issue Jan 14, 2013 · 0 comments

Projects

None yet

2 participants

@daniilyar
Member

We need a check that forbids nested ternary operators. Example:

int smth = (a == b) ? -1 : (c == d) ? 0 : 1; 

This is really a bad practice.. This line should be refactored to:

int k;
if (a == b) {
    k = -1;
} else {
    if (c == d) {
    k = 0;
    }
    else {
        k = 1;
    }
}

Check should have a single option named 'ignore final' which allows to ignore statements such as:

final int smth = (a == b) ? -1 : (c == d) ? 0 : 1; 

in ctors, because in c-tors there is only one way to deal with such kind of logical operations on final variable.

@daniilyar daniilyar was assigned Jan 16, 2013
@daniilyar daniilyar pushed a commit to daniilyar/sevntu.checkstyle that referenced this issue Jan 19, 2013
Daniil Yaroslavtsev Fixes #98. NestedTernary done edb62ec
@romani romani pushed a commit that closed this issue Feb 6, 2013
Daniil Yaroslavtsev Fixes #98. NestedTernary done b2cae4e
@romani romani closed this in b2cae4e Feb 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment