4343@ Rule (key = "S7508" )
4444public class NestedCollectionsCreationCheck extends PythonSubscriptionCheck {
4545 private static final String MESSAGE = "Remove this redundant call." ;
46+ private static final String SECONDARY_MESSAGE = "A redundant call is done here." ;
4647 private static final String QUICK_FIX_MESSAGE = MESSAGE ;
4748
4849 private static final String LIST_FQN = "list" ;
@@ -55,8 +56,7 @@ public class NestedCollectionsCreationCheck extends PythonSubscriptionCheck {
5556 Map .entry (LIST_FQN , Set .of (LIST_FQN , TUPLE_FQN , SORTED_FQN )),
5657 Map .entry (SET_FQN , Set .of (LIST_FQN , SET_FQN , TUPLE_FQN , REVERSED_FQN , SORTED_FQN )),
5758 Map .entry (SORTED_FQN , Set .of (LIST_FQN , TUPLE_FQN , SORTED_FQN )),
58- Map .entry (TUPLE_FQN , Set .of (LIST_FQN , TUPLE_FQN ))
59- );
59+ Map .entry (TUPLE_FQN , Set .of (LIST_FQN , TUPLE_FQN )));
6060
6161 private TypeCheckMap <Set <TypeCheckBuilder >> sensitiveCallCombinationChecks ;
6262
@@ -82,20 +82,23 @@ private void check(SubscriptionContext ctx) {
8282 sensitiveCallCombinationChecks .getOptionalForType (callExpression .callee ().typeV2 ())
8383 .ifPresent (nestedCallTypeChecks -> TreeUtils .nthArgumentOrKeywordOptional (0 , "" , callExpression .arguments ())
8484 .map (RegularArgument ::expression )
85- .ifPresent (argumentExpression -> {
86- findSensitiveMethodCall (argumentExpression , nestedCallTypeChecks )
87- .ifPresent (redundantCallExpression -> {
88- var issue = ctx .addIssue (callExpression , MESSAGE );
89- createQuickFix (redundantCallExpression ).ifPresent (issue ::addQuickFix );
90- });
91- findAssignedToSensitiveMethodCall (argumentExpression , nestedCallTypeChecks )
92- .ifPresent (argumentAssignedCall -> {
93- var issue = ctx .addIssue (callExpression , MESSAGE );
94- createAssignedQuickFix (argumentExpression , argumentAssignedCall ).ifPresent (issue ::addQuickFix );
95- });
96-
85+ .ifPresent (argumentExpression -> checkCallArgumentsForSensitiveMethods (callExpression , argumentExpression , nestedCallTypeChecks , ctx )));
86+ }
9787
98- }));
88+ private static void checkCallArgumentsForSensitiveMethods (CallExpression callExpression , Expression argumentExpression , Set <TypeCheckBuilder > nestedCallTypeChecks ,
89+ SubscriptionContext ctx ) {
90+ findSensitiveMethodCall (argumentExpression , nestedCallTypeChecks )
91+ .ifPresent (redundantCallExpression -> {
92+ var issue = ctx .addIssue (redundantCallExpression .callee (), MESSAGE )
93+ .secondary (callExpression .callee (), SECONDARY_MESSAGE );
94+ createQuickFix (redundantCallExpression ).ifPresent (issue ::addQuickFix );
95+ });
96+ findAssignedToSensitiveMethodCall (argumentExpression , nestedCallTypeChecks )
97+ .ifPresent (argumentAssignedCall -> {
98+ var issue = ctx .addIssue (argumentAssignedCall .callee (), MESSAGE )
99+ .secondary (callExpression .callee (), SECONDARY_MESSAGE );
100+ createAssignedQuickFix (argumentExpression , argumentAssignedCall ).ifPresent (issue ::addQuickFix );
101+ });
99102 }
100103
101104 private static Optional <CallExpression > findSensitiveMethodCall (@ Nullable Expression expression ,
0 commit comments