|
19 | 19 | import java.util.Arrays; |
20 | 20 | import java.util.HashSet; |
21 | 21 | import java.util.List; |
22 | | -import java.util.Objects; |
23 | 22 | import java.util.Optional; |
24 | 23 | import java.util.Set; |
25 | 24 | import org.sonar.check.Rule; |
|
31 | 30 | import org.sonar.plugins.python.api.tree.CallExpression; |
32 | 31 | import org.sonar.plugins.python.api.tree.Decorator; |
33 | 32 | import org.sonar.plugins.python.api.tree.Expression; |
34 | | -import org.sonar.plugins.python.api.tree.FileInput; |
35 | 33 | import org.sonar.plugins.python.api.tree.FunctionDef; |
36 | 34 | import org.sonar.plugins.python.api.tree.ListLiteral; |
37 | 35 | import org.sonar.plugins.python.api.tree.RegularArgument; |
38 | 36 | import org.sonar.plugins.python.api.tree.StringLiteral; |
39 | 37 | import org.sonar.python.semantic.FunctionSymbolImpl; |
40 | 38 | import org.sonar.python.tree.FunctionDefImpl; |
41 | | -import org.sonar.python.tree.TreeUtils; |
42 | 39 |
|
43 | 40 | import static org.sonar.plugins.python.api.tree.Tree.Kind.CALL_EXPR; |
44 | | -import static org.sonar.plugins.python.api.tree.Tree.Kind.FILE_INPUT; |
45 | 41 | import static org.sonar.plugins.python.api.tree.Tree.Kind.FUNCDEF; |
46 | 42 | import static org.sonar.plugins.python.api.tree.Tree.Kind.LIST_LITERAL; |
47 | 43 | import static org.sonar.plugins.python.api.tree.Tree.Kind.REGULAR_ARGUMENT; |
@@ -137,27 +133,13 @@ private static Optional<CallExpression> getFlaskViewDecorator(FunctionDef functi |
137 | 133 |
|
138 | 134 | private static boolean isFlaskRouteDecorator(CallExpression callExpression) { |
139 | 135 | Symbol calleeSymbol = callExpression.calleeSymbol(); |
140 | | - if (calleeSymbol == null) { |
141 | | - return false; |
142 | | - } |
143 | | - return calleeSymbol.name().equals("route"); |
| 136 | + return calleeSymbol != null && "flask.scaffold.Scaffold.route".equals(calleeSymbol.fullyQualifiedName()); |
144 | 137 | } |
145 | 138 |
|
146 | 139 | private static void checkFlaskView(CallExpression callExpression, SubscriptionContext ctx) { |
147 | 140 | RegularArgument methodsArg = argumentByKeyword("methods", callExpression.arguments()); |
148 | | - if (methodsArg != null && hasBothUnsafeAndSafeHttpMethods(methodsArg) && isFlaskImported(callExpression)) { |
| 141 | + if (methodsArg != null && hasBothUnsafeAndSafeHttpMethods(methodsArg)) { |
149 | 142 | ctx.addIssue(callExpression, MESSAGE); |
150 | 143 | } |
151 | 144 | } |
152 | | - |
153 | | - private static boolean isFlaskImported(CallExpression callExpression) { |
154 | | - // When SONARPY-834 will be implemented we can have a cleaner implementation |
155 | | - // checking decorator fqn to be equal to flask.blueprints.Blueprint.route |
156 | | - return Optional.ofNullable(TreeUtils.firstAncestorOfKind(callExpression, FILE_INPUT)) |
157 | | - .filter(fileInput -> ((FileInput) fileInput).globalVariables().stream() |
158 | | - .map(Symbol::fullyQualifiedName) |
159 | | - .filter(Objects::nonNull) |
160 | | - .anyMatch(fqn -> fqn.contains("flask"))) |
161 | | - .isPresent(); |
162 | | - } |
163 | 145 | } |
0 commit comments