forked from spring-io/spring-javaformat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide more configuration options for `SpringTernaryCheck` and change the default to only ban `==` when comparing to `null`. Closes spring-iogh-46
- Loading branch information
Showing
8 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...vaformat/spring-javaformat-checkstyle/src/test/resources/check/TernaryEqualsEqualsAny.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
+0 errors |
2 changes: 2 additions & 0 deletions
2
...format/spring-javaformat-checkstyle/src/test/resources/check/TernaryEqualsEqualsNever.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
+TernaryEqualsEqualsNever.java:27:33: Ternary operation should use != when testing. [SpringTernary] | ||
+1 error |
9 changes: 9 additions & 0 deletions
9
...aformat/spring-javaformat-checkstyle/src/test/resources/config/TernaryEqualsEqualsAny.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> | ||
<module name="com.puppycrawl.tools.checkstyle.Checker"> | ||
<module name="com.puppycrawl.tools.checkstyle.TreeWalker"> | ||
<module name="io.spring.javaformat.checkstyle.check.SpringTernaryCheck"> | ||
<property name="equalsTest" value="any"/> | ||
</module> | ||
</module> | ||
</module> |
9 changes: 9 additions & 0 deletions
9
...ormat/spring-javaformat-checkstyle/src/test/resources/config/TernaryEqualsEqualsNever.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> | ||
<module name="com.puppycrawl.tools.checkstyle.Checker"> | ||
<module name="com.puppycrawl.tools.checkstyle.TreeWalker"> | ||
<module name="io.spring.javaformat.checkstyle.check.SpringTernaryCheck"> | ||
<property name="equalsTest" value="never"/> | ||
</module> | ||
</module> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...format/spring-javaformat-checkstyle/src/test/resources/source/TernaryEqualsEqualsAny.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2017-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* This is an invalid example of a ternary expression. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
public class TernaryEqualsEqualsAlways { | ||
|
||
public void test() { | ||
boolean a = true; | ||
boolean b = false; | ||
int c = (a != b ? 1 : 2); | ||
} | ||
|
||
public void test2() { | ||
Boolean a = true; | ||
int c = (a == null ? 1 : 2); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...rmat/spring-javaformat-checkstyle/src/test/resources/source/TernaryEqualsEqualsNever.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright 2017-2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* This is a valid example of a ternary expression. | ||
* | ||
* @author Phillip Webb | ||
*/ | ||
public class TernaryEqualsEqualsNever { | ||
|
||
public void test() { | ||
boolean a = true; | ||
boolean b = false; | ||
int c = (a == b ? 1 : 2); | ||
} | ||
|
||
} |