Skip to content

Commit 2aebe38

Browse files
authored
Update rules metadata (#2069)
1 parent cbef8fd commit 2aebe38

File tree

10 files changed

+57
-20
lines changed

10 files changed

+57
-20
lines changed

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S1721.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<p>This rule is deprecated; use {rule:python:S5905} instead.</p>
22
<h2>Why is this an issue?</h2>
33
<p>Parentheses are not required after the <code>assert</code>, <code>del</code>, <code>elif</code>, <code>except</code>, <code>for</code>,
4-
<code>if</code>, <code>in</code>, <code>not</code>, <code>raise</code>, <code>return</code>, <code>while</code>, and <code>yield</code> keywords, and
5-
using them unnecessarily impairs readability. They should therefore be omitted.</p>
4+
<code>if</code>, <code>not</code>, <code>raise</code>, <code>return</code>, <code>while</code>, and <code>yield</code> keywords. Similarly,
5+
parentheses are not required after <code>in</code> in a <code>for</code> loop. Using parentheses unnecessarily impairs readability, and therefore,
6+
they should be omitted.</p>
67
<h3>Noncompliant code example</h3>
78
<pre>
89
x = 1

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"title": "Hard-coded credentials are security-sensitive",
2+
"title": "Hard-coded passwords are security-sensitive",
33
"type": "SECURITY_HOTSPOT",
44
"code": {
55
"impacts": {
@@ -41,5 +41,6 @@
4141
"3.5.2",
4242
"6.4.1"
4343
]
44-
}
44+
},
45+
"quickfix": "unknown"
4546
}

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S2710.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ <h2>Why is this an issue?</h2>
77
<code>__new__</code> as their first argument is always the class instead of "self".</p>
88
<p>By default this rule accepts <code>cls</code> and <code>mcs</code>, which is sometime used in metaclasses, as valid names for class parameters. You
99
can set your own list of accepted names via the parameter <code>classParameterNames</code>.</p>
10-
<h3>How to fix it</h3>
10+
<h2>How to fix it</h2>
1111
<p>Follow the naming convention for the first parameter name of a class method.</p>
12+
<h3>Code examples</h3>
1213
<h4>Noncompliant code example</h4>
1314
<pre data-diff-id="1" data-diff-type="noncompliant">
1415
class Rectangle(object):

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S5685.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h2>Why is this an issue?</h2>
1111
<li> <strong>Compatibility:</strong> If you are working on projects that need to be compatible with older versions of Python (before 3.8), you
1212
should avoid using the walrus operator, as it won’t be available in those versions. </li>
1313
</ul>
14-
<h3>How to fix it</h3>
14+
<h2>How to fix it</h2>
1515
<p>Avoid using the walrus operator for the cases when it is not mandatory.</p>
1616
<h3>Code examples</h3>
1717
<h4>Noncompliant code example</h4>

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6321.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,8 @@ <h3>Documentation</h3>
204204
<h3>Standards</h3>
205205
<ul>
206206
<li> CWE - <a href="https://cwe.mitre.org/data/definitions/284">CWE-284 - Improper Access Control</a> </li>
207+
<li> OWASP - <a href="https://owasp.org/Top10/A01_2021-Broken_Access_Control/">Top 10 2021 Category A1 - Broken Access Control</a> </li>
208+
<li> OWASP - <a href="https://owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure">Top 10 2017 Category A3 - Sensitive Data
209+
Exposure</a> </li>
207210
</ul>
208211

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
"CWE": [
2525
284
2626
],
27+
"OWASP": [
28+
"A3"
29+
],
30+
"OWASP Top 10 2021": [
31+
"A1"
32+
],
2733
"PCI DSS 3.2": [
2834
"6.5.8"
2935
],

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6711.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,14 @@ <h3>Code examples</h3>
400400
<h4>Noncompliant code example</h4>
401401
<pre data-diff-id="1" data-diff-type="noncompliant">
402402
import numpy as np
403-
def foo():
404-
np.random.seed(42)
405-
x = np.random.randn() # Noncompliant: this relies on numpy.random.RandomState, which is deprecated
403+
np.random.seed(42)
404+
x = np.random.randn() # Noncompliant: this relies on numpy.random.RandomState, which is deprecated
406405
</pre>
407406
<h4>Compliant solution</h4>
408407
<pre data-diff-id="1" data-diff-type="compliant">
409408
import numpy as np
410-
def foo():
411-
generator = np.random.default_rng(42)
412-
x = generator.standard_normal()
409+
generator = np.random.default_rng(42)
410+
x = generator.standard_normal()
413411
</pre>
414412
<h2>Resources</h2>
415413
<h3>Documentation</h3>

python-checks/src/main/resources/org/sonar/l10n/py/rules/python/S6929.html

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<p>This rule raises an issue when the axis argument is not provided to TensorFlow’s reduction operations.</p>
1+
<p>This rule raises an issue when the <code>axis</code>/<code>dim`</code> argument is not provided to reduction operations.</p>
22
<h2>Why is this an issue?</h2>
3-
<p>The result of TensorFlow’s reduction operations (i.e. <code>tf.math.reduce_sum</code>, <code>tf.math.reduce_std</code>), highly depends on the
4-
shape of the Tensor provided.</p>
3+
<h3>TensorFlow</h3>
4+
<p>The result of reduction operations (i.e. <code>tf.math.reduce_sum</code>, <code>tf.math.reduce_std</code>, <code>torch.sum</code>,
5+
<code>torch.mean</code>, etc…​), highly depends on the shape of the Tensor provided.</p>
56
<pre>
67
import tensorflow as tf
78

@@ -42,7 +43,9 @@ <h2>Why is this an issue?</h2>
4243
<p>In the example above, specifying the axis clarifies the intent, as the result now is <code>[5, 7]</code>. If the intent was to effectively reduce
4344
across all dimensions the user should provide the list of axis <code>axis=[0,1]</code> or clearly state the default behavior should be applied with
4445
<code>axis=None</code>.</p>
45-
<h2>How to fix it</h2>
46+
<h3>The PyTorch equivalent</h3>
47+
<p>The same behavior occurs in PyTorch, but the argument is called <code>dim</code> instead of <code>axis</code>.</p>
48+
<h2>How to fix it in TensorFlow</h2>
4649
<p>To fix this issue provide the axis argument when using a TensorFlow reduction operation such as <code>tf.math.reduce_sum</code>,
4750
<code>tf.math.reduce_prod</code>, <code>tf.math.reduce_mean</code>, etc…​</p>
4851
<h3>Code examples</h3>
@@ -60,6 +63,24 @@ <h4>Compliant solution</h4>
6063
x = tf.constant([[1, 1, 1], [1, 1, 1]])
6164
tf.math.reduce_sum(x, axis=0) # Compliant: the reduction will happen only on the axis 0, resulting in `[2,2,2]`
6265
</pre>
66+
<h2>How to fix it in PyTorch</h2>
67+
<p>To fix this issue provide the dim argument when using a PyTorch reduction operation such as <code>torch.sum</code>, <code>torch.prod</code>,
68+
<code>torch.mean</code>, etc…​</p>
69+
<h3>Code examples</h3>
70+
<h4>Noncompliant code example</h4>
71+
<pre data-diff-id="2" data-diff-type="noncompliant">
72+
import torch
73+
74+
x = torch.tensor([[1, 1, 1], [1, 1, 1]])
75+
torch.sum(x) # Noncompliant: the dim argument defaults to None
76+
</pre>
77+
<h4>Compliant solution</h4>
78+
<pre data-diff-id="2" data-diff-type="compliant">
79+
import torch
80+
81+
x = torch.tensor([[1, 1, 1], [1, 1, 1]])
82+
torch.sum(x, dim=None) # Compliant: all dimensions will be reduced
83+
</pre>
6384
<h2>Resources</h2>
6485
<h3>Documentation</h3>
6586
<ul>
@@ -71,6 +92,7 @@ <h3>Documentation</h3>
7192
<li> TensorFlow Documentation - <a href="https://www.tensorflow.org/api_docs/python/tf/math/reduce_sum">tf.math.reduce_sum reference</a> </li>
7293
<li> TensorFlow Documentation - <a href="https://www.tensorflow.org/api_docs/python/tf/math/reduce_variance">tf.math.reduce_variance reference</a>
7394
</li>
95+
<li> PyTorch Documentation - <a href="https://pytorch.org/docs/stable/torch.html#reduction-ops">Reduction operations</a> </li>
7496
</ul>
7597
<h3>Articles &amp; blog posts</h3>
7698
<ul>

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
{
2-
"title": "The axis argument should be specified when using TensorFlow\u0027s reduction operations",
2+
"title": "The reduction axis\/dimension should be specified when using reduction operations",
33
"type": "CODE_SMELL",
44
"status": "ready",
55
"remediation": {
66
"func": "Constant\/Issue",
77
"constantCost": "5min"
88
},
9-
"tags": [],
9+
"tags": [
10+
"tensorflow",
11+
"pytorch",
12+
"machine-learning",
13+
"scientific-computing"
14+
],
1015
"defaultSeverity": "Major",
1116
"ruleSpecification": "RSPEC-6929",
1217
"sqKey": "S6929",
1318
"scope": "All",
14-
"quickfix": "unknown",
19+
"quickfix": "targeted",
1520
"code": {
1621
"impacts": {
1722
"MAINTAINABILITY": "MEDIUM",

sonarpedia.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"languages": [
44
"PY"
55
],
6-
"latest-update": "2024-09-24T09:07:11.168038831Z",
6+
"latest-update": "2024-10-14T08:24:54.620505158Z",
77
"options": {
88
"no-language-in-filenames": true,
99
"preserve-filenames": true

0 commit comments

Comments
 (0)