New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Check: ConfusingConditionCheck #90

Closed
romani opened this Issue Nov 28, 2012 · 1 comment

Comments

Projects
None yet
3 participants
@romani
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;"

@ghost ghost assigned VadimPanasiuk Dec 22, 2012

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Dec 25, 2012

Member

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

Member

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

VadimPanasiuk added a commit to VadimPanasiuk/sevntu.checkstyle that referenced this issue Aug 28, 2013

VadimPanasiuk added a commit to VadimPanasiuk/sevntu.checkstyle that referenced this issue Aug 28, 2013

VadimPanasiuk added a commit to VadimPanasiuk/sevntu.checkstyle that referenced this issue Aug 28, 2013

VadimPanasiuk added a commit to VadimPanasiuk/sevntu.checkstyle that referenced this issue Sep 2, 2013

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

@isopov isopov closed this Sep 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment