Skip to content

Commit c92dbda

Browse files
Use existing rule S935 instead of S6658 for SpecialMethodReturnTypeCheck (#1528)
1 parent 17c0595 commit c92dbda

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

its/ruling/src/test/java/org/sonar/python/it/RulingHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static void loadProfile(Orchestrator orchestrator, String profile) throws IOExce
9292
static List<String> bugRuleKeys() {
9393
return Arrays.asList(
9494
"PreIncrementDecrement",
95+
"S935",
9596
"S1045",
9697
"S1143",
9798
"S1226",
@@ -144,7 +145,6 @@ static List<String> bugRuleKeys() {
144145
"S6323",
145146
"S6328",
146147
"S6468",
147-
"S6658",
148148
"S6662",
149149
"S905",
150150
"S930");

python-checks/src/main/java/org/sonar/python/checks/SpecialMethodReturnTypeCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.sonar.python.tree.TreeUtils;
3636
import org.sonar.python.tree.TupleImpl;
3737

38-
@Rule(key = "S6658")
38+
@Rule(key = "S935")
3939
public class SpecialMethodReturnTypeCheck extends PythonSubscriptionCheck {
4040
/**
4141
* Stores the return types expected for specific method names as specified here:

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6658.html renamed to python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S935.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h2>Why is this an issue?</h2>
66
object.</p>
77
<p>The Python interpreter will call these methods when performing the operation they’re associated with. Each special method expects a specific return
88
type. Calls to a special method will throw a <code>TypeError</code> if its return type is incorrect.</p>
9-
<p>An issue will be raised when one of the following method doesn’t return the indicated type:</p>
9+
<p>An issue will be raised when one of the following methods doesn’t return the indicated type:</p>
1010
<ul>
1111
<li> <code>__bool__</code> method should return bool </li>
1212
<li> <code>__index__</code> method should return integer </li>
@@ -42,6 +42,9 @@ <h4>Compliant solution</h4>
4242
<h2>Resources</h2>
4343
<h3>Documentation</h3>
4444
<ul>
45-
<li> Python Documentation - <a href="https://docs.python.org/3/reference/datamodel.html#special-method-names">Special method names</a> </li>
45+
<li> Python Data Model Documentation - <a href="https://docs.python.org/3/reference/datamodel.html#special-method-names">Special method names</a>
46+
</li>
47+
<li> Python Object Serialization Documentation - <a href="https://docs.python.org/3/library/pickle.html#pickling-class-instances">Pickling Class
48+
Instances</a> </li>
4649
</ul>
4750

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "Special methods should have an expected return type",
2+
"title": "Functions and methods should only return expected values",
33
"type": "BUG",
44
"status": "ready",
55
"remediation": {
@@ -8,8 +8,13 @@
88
},
99
"tags": [],
1010
"defaultSeverity": "Blocker",
11-
"ruleSpecification": "RSPEC-S6658",
12-
"sqKey": "S6658",
11+
"ruleSpecification": "RSPEC-S935",
12+
"sqKey": "S935",
1313
"scope": "All",
14+
"securityStandards": {
15+
"CWE": [
16+
394
17+
]
18+
},
1419
"quickfix": "unknown"
1520
}

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/Sonar_way_profile.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"S125",
1717
"S905",
1818
"S930",
19+
"S935",
1920
"S1045",
2021
"S1066",
2122
"S1110",
@@ -198,7 +199,6 @@
198199
"S6556",
199200
"S6559",
200201
"S6560",
201-
"S6658",
202202
"S6659",
203203
"S6660",
204204
"S6662",

0 commit comments

Comments
 (0)