File tree Expand file tree Collapse file tree 3 files changed +8
-8
lines changed
main/java/org/sonar/python/checks
java/org/sonar/python/checks Expand file tree Collapse file tree 3 files changed +8
-8
lines changed Original file line number Diff line number Diff line change 36
36
@ Rule (key = "S6725" )
37
37
public class NumpyIsNanCheck extends PythonSubscriptionCheck {
38
38
39
- private static final String MESSAGE = "Don't perform an equality check against \" numpy.nan\" ." ;
40
- private static final String QUICK_FIX_MESSAGE_EQUALITY = "Replace this equality check with numpy.isnan()." ;
41
- private static final String QUICK_FIX_MESSAGE_INEQUALITY = "Replace this inequality check with ! numpy.isnan()." ;
39
+ private static final String MESSAGE = "Don't perform an equality/inequality check against \" numpy.nan\" ." ;
40
+ private static final String QUICK_FIX_MESSAGE_EQUALITY = "Replace this equality check with \" numpy.isnan()\" ." ;
41
+ private static final String QUICK_FIX_MESSAGE_INEQUALITY = "Replace this inequality check with \" not numpy.isnan()\" ." ;
42
42
43
43
@ Override
44
44
public void initialize (Context context ) {
@@ -83,7 +83,7 @@ private static String addPrefix(BinaryExpression be) {
83
83
if ("==" .equals (be .operator ().value ())) {
84
84
return "" ;
85
85
} else {
86
- return "! " ;
86
+ return "not " ;
87
87
}
88
88
}
89
89
Original file line number Diff line number Diff line change 26
26
class NumpyIsNanCheckTest {
27
27
28
28
NumpyIsNanCheck check = new NumpyIsNanCheck ();
29
- private static final String QUICK_FIX_MESSAGE_EQUALITY = "Replace this equality check with numpy.isnan()." ;
30
- private static final String QUICK_FIX_MESSAGE_INEQUALITY = "Replace this inequality check with ! numpy.isnan()." ;
29
+ private static final String QUICK_FIX_MESSAGE_EQUALITY = "Replace this equality check with \" numpy.isnan()\" ." ;
30
+ private static final String QUICK_FIX_MESSAGE_INEQUALITY = "Replace this inequality check with \" not numpy.isnan()\" ." ;
31
31
32
32
@ Test
33
33
void test () {
@@ -66,7 +66,7 @@ void quickFixTestNotEqual() {
66
66
67
67
final String compliant = "import numpy as np\n " +
68
68
"def foo(x):\n " +
69
- " if ! np.isnan(x): print(1)" ;
69
+ " if not np.isnan(x): print(1)" ;
70
70
71
71
performVerification (nonCompliant1 , compliant , QUICK_FIX_MESSAGE_INEQUALITY );
72
72
performVerification (nonCompliant2 , compliant , QUICK_FIX_MESSAGE_INEQUALITY );
Original file line number Diff line number Diff line change 1
1
def foo1 (x ):
2
2
import numpy as np
3
- if x == np .nan : print (1 ) # Noncompliant {{Don't perform an equality check against "numpy.nan".}}
3
+ if x == np .nan : print (1 ) # Noncompliant {{Don't perform an equality/inequality check against "numpy.nan".}}
4
4
# ^^^^^^^^^^^
5
5
if np .nan == x : print (1 ) # Noncompliant
6
6
if x != np .nan : print (1 ) # Noncompliant
You can’t perform that action at this time.
0 commit comments