Search in sources :

Example 1 with SUBSCRIPTION

use of org.sonar.plugins.python.api.tree.Tree.Kind.SUBSCRIPTION in project sonar-python by SonarSource.

the class CorsCheck method checkAllowOriginProperty.

private static void checkAllowOriginProperty(SubscriptionContext ctx) {
    AssignmentStatement assignment = (AssignmentStatement) ctx.syntaxNode();
    Optional<Expression> lhs = getOnlyAssignedLhs(assignment);
    if (lhs.isPresent() && lhs.get().is(SUBSCRIPTION)) {
        SubscriptionExpression subscription = (SubscriptionExpression) lhs.get();
        List<Expression> subscripts = subscription.subscripts().expressions();
        if (subscripts.size() != 1) {
            return;
        }
        if (subscription.object().is(NAME) && TYPES_TO_CHECK.stream().anyMatch(t -> subscription.object().type().canOnlyBe(t))) {
            reportIfAllowOriginIsSet(ctx, assignment, subscripts.get(0));
        } else {
            checkAllowOriginPropertyQualifiedExpr(ctx, assignment, subscription, subscripts);
        }
    }
}
Also used : LIST_LITERAL(org.sonar.plugins.python.api.tree.Tree.Kind.LIST_LITERAL) Arrays(java.util.Arrays) RegularArgument(org.sonar.plugins.python.api.tree.RegularArgument) REGULAR_ARGUMENT(org.sonar.plugins.python.api.tree.Tree.Kind.REGULAR_ARGUMENT) PythonSubscriptionCheck(org.sonar.plugins.python.api.PythonSubscriptionCheck) ASSIGNMENT_STMT(org.sonar.plugins.python.api.tree.Tree.Kind.ASSIGNMENT_STMT) FunctionDef(org.sonar.plugins.python.api.tree.FunctionDef) AssignmentStatement(org.sonar.plugins.python.api.tree.AssignmentStatement) ArgList(org.sonar.plugins.python.api.tree.ArgList) TreeUtils(org.sonar.python.tree.TreeUtils) Decorator(org.sonar.plugins.python.api.tree.Decorator) CALL_EXPR(org.sonar.plugins.python.api.tree.Tree.Kind.CALL_EXPR) STRING_LITERAL(org.sonar.plugins.python.api.tree.Tree.Kind.STRING_LITERAL) Name(org.sonar.plugins.python.api.tree.Name) QualifiedExpression(org.sonar.plugins.python.api.tree.QualifiedExpression) DICTIONARY_LITERAL(org.sonar.plugins.python.api.tree.Tree.Kind.DICTIONARY_LITERAL) Expression(org.sonar.plugins.python.api.tree.Expression) Parameter(org.sonar.plugins.python.api.tree.Parameter) Nullable(javax.annotation.Nullable) DictionaryLiteralElement(org.sonar.plugins.python.api.tree.DictionaryLiteralElement) Expressions(org.sonar.python.checks.Expressions) KeyValuePair(org.sonar.plugins.python.api.tree.KeyValuePair) DECORATOR(org.sonar.plugins.python.api.tree.Tree.Kind.DECORATOR) StringLiteral(org.sonar.plugins.python.api.tree.StringLiteral) SubscriptionContext(org.sonar.plugins.python.api.SubscriptionContext) ListLiteral(org.sonar.plugins.python.api.tree.ListLiteral) KEY_VALUE_PAIR(org.sonar.plugins.python.api.tree.Tree.Kind.KEY_VALUE_PAIR) NAME(org.sonar.plugins.python.api.tree.Tree.Kind.NAME) ParameterList(org.sonar.plugins.python.api.tree.ParameterList) List(java.util.List) CallExpression(org.sonar.plugins.python.api.tree.CallExpression) ExpressionList(org.sonar.plugins.python.api.tree.ExpressionList) SUBSCRIPTION(org.sonar.plugins.python.api.tree.Tree.Kind.SUBSCRIPTION) SubscriptionExpression(org.sonar.plugins.python.api.tree.SubscriptionExpression) Argument(org.sonar.plugins.python.api.tree.Argument) Optional(java.util.Optional) Tree(org.sonar.plugins.python.api.tree.Tree) TUPLE(org.sonar.plugins.python.api.tree.Tree.Kind.TUPLE) Rule(org.sonar.check.Rule) DictionaryLiteral(org.sonar.plugins.python.api.tree.DictionaryLiteral) Tuple(org.sonar.plugins.python.api.tree.Tuple) Collections(java.util.Collections) Symbol(org.sonar.plugins.python.api.symbols.Symbol) AssignmentStatement(org.sonar.plugins.python.api.tree.AssignmentStatement) QualifiedExpression(org.sonar.plugins.python.api.tree.QualifiedExpression) Expression(org.sonar.plugins.python.api.tree.Expression) CallExpression(org.sonar.plugins.python.api.tree.CallExpression) SubscriptionExpression(org.sonar.plugins.python.api.tree.SubscriptionExpression) SubscriptionExpression(org.sonar.plugins.python.api.tree.SubscriptionExpression)

Aggregations

Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 Rule (org.sonar.check.Rule)1 PythonSubscriptionCheck (org.sonar.plugins.python.api.PythonSubscriptionCheck)1 SubscriptionContext (org.sonar.plugins.python.api.SubscriptionContext)1 Symbol (org.sonar.plugins.python.api.symbols.Symbol)1 ArgList (org.sonar.plugins.python.api.tree.ArgList)1 Argument (org.sonar.plugins.python.api.tree.Argument)1 AssignmentStatement (org.sonar.plugins.python.api.tree.AssignmentStatement)1 CallExpression (org.sonar.plugins.python.api.tree.CallExpression)1 Decorator (org.sonar.plugins.python.api.tree.Decorator)1 DictionaryLiteral (org.sonar.plugins.python.api.tree.DictionaryLiteral)1 DictionaryLiteralElement (org.sonar.plugins.python.api.tree.DictionaryLiteralElement)1 Expression (org.sonar.plugins.python.api.tree.Expression)1 ExpressionList (org.sonar.plugins.python.api.tree.ExpressionList)1 FunctionDef (org.sonar.plugins.python.api.tree.FunctionDef)1 KeyValuePair (org.sonar.plugins.python.api.tree.KeyValuePair)1