Skip to content

Commit f610de2

Browse files
SONARPY-1006 S1172: Avoid raising issues when the parameter name starts with "_" (#1117)
1 parent 1802adf commit f610de2

File tree

3 files changed

+10
-48
lines changed

3 files changed

+10
-48
lines changed

its/ruling/src/test/resources/expected/python-S1172.json

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@
211211
184,
212212
555,
213213
],
214-
'project:buildbot-0.8.6p1/buildbot/status/web/change_hook.py':[
215-
81,
216-
],
217214
'project:buildbot-0.8.6p1/buildbot/status/web/hooks/base.py':[
218215
23,
219216
],
@@ -222,20 +219,13 @@
222219
100,
223220
100,
224221
],
225-
'project:buildbot-0.8.6p1/buildbot/steps/source/svn.py':[
226-
373,
227-
],
228222
'project:buildbot-0.8.6p1/buildbot/test/fake/fakedb.py':[
229223
354,
230-
628,
231224
957,
232225
],
233226
'project:buildbot-0.8.6p1/buildbot/test/fake/remotecommand.py':[
234227
38,
235228
],
236-
'project:buildbot-0.8.6p1/buildbot/util/eventual.py':[
237-
94,
238-
],
239229
'project:buildbot-0.8.6p1/contrib/buildbot_cvs_mail.py':[
240230
64,
241231
64,
@@ -637,7 +627,6 @@
637627
'project:django-2.2.3/django/utils/six.py':[
638628
182,
639629
539,
640-
687,
641630
],
642631
'project:django-2.2.3/django/utils/translation/reloader.py':[
643632
7,
@@ -1087,9 +1076,6 @@
10871076
232,
10881077
432,
10891078
],
1090-
'project:numpy-1.16.4/numpy/distutils/exec_command.py':[
1091-
196,
1092-
],
10931079
'project:numpy-1.16.4/numpy/distutils/fcompiler/__init__.py':[
10941080
796,
10951081
],
@@ -1144,15 +1130,9 @@
11441130
1099,
11451131
1099,
11461132
],
1147-
'project:tensorflow/python/autograph/pyct/inspect_utils_test.py':[
1148-
49,
1149-
],
11501133
'project:tensorflow/python/compiler/tensorrt/test/conv2d_test.py':[
11511134
67,
11521135
],
1153-
'project:tensorflow/python/data/experimental/kernel_tests/group_by_window_test.py':[
1154-
147,
1155-
],
11561136
'project:tensorflow/python/debug/lib/debug_service_pb2_grpc.py':[
11571137
63,
11581138
76,
@@ -1164,18 +1144,9 @@
11641144
'project:tensorflow/python/keras/engine/base_layer_utils.py':[
11651145
67,
11661146
],
1167-
'project:tensorflow/python/keras/layers/convolutional_recurrent.py':[
1168-
569,
1169-
],
1170-
'project:tensorflow/python/keras/layers/cudnn_recurrent.py':[
1171-
451,
1172-
],
11731147
'project:tensorflow/python/keras/layers/legacy_rnn/rnn_cell_wrapper_impl.py':[
11741148
206,
11751149
],
1176-
'project:tensorflow/python/keras/layers/recurrent.py':[
1177-
2376,
1178-
],
11791150
'project:tensorflow/python/keras/saving/saved_model_experimental.py':[
11801151
367,
11811152
367,
@@ -1204,25 +1175,13 @@
12041175
'project:tensorflow/python/kernel_tests/signal/mel_ops_test.py':[
12051176
62,
12061177
],
1207-
'project:tensorflow/python/kernel_tests/sparse_tensor_dense_matmul_op_test.py':[
1208-
389,
1209-
],
1210-
'project:tensorflow/python/kernel_tests/sparse_xent_op_test.py':[
1211-
356,
1212-
],
1213-
'project:tensorflow/python/ops/ctc_ops.py':[
1214-
241,
1215-
690,
1216-
],
12171178
'project:tensorflow/python/ops/data_flow_ops.py':[
12181179
1935,
12191180
],
12201181
'project:tensorflow/python/ops/rnn.py':[
12211182
158,
12221183
],
12231184
'project:tensorflow/python/ops/variables.py':[
1224-
53,
1225-
58,
12261185
182,
12271186
223,
12281187
],
@@ -1270,12 +1229,6 @@
12701229
140,
12711230
140,
12721231
],
1273-
'project:tensorflow/tools/pip_package/simple_console.py':[
1274-
26,
1275-
],
1276-
'project:tensorflow/tools/pip_package/simple_console_for_windows.py':[
1277-
26,
1278-
],
12791232
'project:tensorflow/tools/test/system_info.py':[
12801233
25,
12811234
],

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,17 @@ public void initialize(Context context) {
5454
private static void checkFunctionParameter(SubscriptionContext ctx, FunctionDef functionDef) {
5555
if (isException(ctx, functionDef)) return;
5656
functionDef.localVariables().stream()
57-
.filter(symbol -> !"self".equals(symbol.name()))
57+
.filter(symbol -> !isIgnoredSymbolName(symbol.name()))
5858
.map(Symbol::usages)
5959
.filter(usages -> usages.size() == 1 && usages.get(0).tree().parent().is(Kind.PARAMETER))
6060
.map(usages -> (Parameter) usages.get(0).tree().parent())
6161
.forEach(param -> ctx.addIssue(param, String.format(MESSAGE, param.name().name())));
6262
}
6363

64+
private static boolean isIgnoredSymbolName(String symbolName) {
65+
return "self".equals(symbolName) || symbolName.startsWith("_");
66+
}
67+
6468
private static boolean isException(SubscriptionContext ctx, FunctionDef functionDef) {
6569
FunctionSymbol functionSymbol = ((FunctionDefImpl) functionDef).functionSymbol();
6670
return CheckUtils.containsCallToLocalsFunction(functionDef) ||

python-checks/src/test/resources/checks/unusedFunctionParameter/unusedFunctionParameter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,8 @@ def bar(q, r=None):
125125

126126
def test_using_fixture(my_fixture):
127127
assert do_something() == expected()
128+
129+
130+
def lambda_handler(_event, _context):
131+
print("foo")
132+

0 commit comments

Comments
 (0)