Skip to content
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

AvoidConstantAsFirstOperandInConditionCheck: doesn't validate comparisons other then equals and not equals #672

Closed
rnveach opened this issue Jun 6, 2018 · 1 comment

Comments

@rnveach
Copy link
Contributor

@rnveach rnveach commented Jun 6, 2018

$ cat TestClass.java
public class TestClass {
    void method() {
int a = -1;

if (0 == a) {}
if (0 > a) {}
if (0 < a) {}
    }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
<module name="com.github.sevntu.checkstyle.checks.coding.AvoidConstantAsFirstOperandInConditionCheck" />
    </module>
</module>

$ java -jar checkstyle-8.9-sevntu-1.29.0-all.jar -c TestConfig.xml TestClass.java
Starting audit...
[ERROR] TestClass.java:5: Constant have to be second operand of '=='. [AvoidConstantAsFirstOperandInCondition]
Audit done.
Checkstyle ends with 1 errors.

I am expecting a violation on 6 and 7 similar to 5.

@romani romani added the approved label Jun 6, 2018
rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 6, 2018
rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 7, 2018
rnveach added a commit to rnveach/sevntu.checkstyle that referenced this issue Jun 7, 2018
romani added a commit that referenced this issue Jun 7, 2018
@romani romani added this to the 1.30.0 milestone Jun 7, 2018
@romani
Copy link
Member

@romani romani commented Jun 7, 2018

fix is merged.

@romani romani closed this Jun 7, 2018
kariem added a commit to kariem/sevntu.checkstyle that referenced this issue Jul 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants