Search in sources :

Example 11 with ParameterList

use of org.sonar.plugins.python.api.tree.ParameterList in project sonar-python by SonarSource.

the class ExitHasBadArgumentsCheck method initialize.

@Override
public void initialize(Context context) {
    context.registerSyntaxNodeConsumer(Tree.Kind.FUNCDEF, ctx -> {
        FunctionDef funcDef = (FunctionDef) ctx.syntaxNode();
        if (!funcDef.name().name().equals("__exit__")) {
            return;
        }
        ParameterList parameters = funcDef.parameters();
        int arity = 0;
        if (parameters != null) {
            if (parameters.nonTuple().stream().anyMatch(ExitHasBadArgumentsCheck::isStarredParam)) {
                return;
            }
            arity = parameters.all().size();
        }
        raiseIssue(ctx, funcDef, arity);
    });
}
Also used : FunctionDef(org.sonar.plugins.python.api.tree.FunctionDef) ParameterList(org.sonar.plugins.python.api.tree.ParameterList)

Aggregations

ParameterList (org.sonar.plugins.python.api.tree.ParameterList)11 AnyParameter (org.sonar.plugins.python.api.tree.AnyParameter)5 FunctionDef (org.sonar.plugins.python.api.tree.FunctionDef)5 LambdaExpression (org.sonar.plugins.python.api.tree.LambdaExpression)3 Name (org.sonar.plugins.python.api.tree.Name)3 Parameter (org.sonar.plugins.python.api.tree.Parameter)3 Token (org.sonar.plugins.python.api.tree.Token)3 AstNode (com.sonar.sslr.api.AstNode)2 ArrayList (java.util.ArrayList)1 Rule (org.sonar.check.Rule)1 RuleProperty (org.sonar.check.RuleProperty)1 PythonSubscriptionCheck (org.sonar.plugins.python.api.PythonSubscriptionCheck)1 SubscriptionContext (org.sonar.plugins.python.api.SubscriptionContext)1 FunctionSymbol (org.sonar.plugins.python.api.symbols.FunctionSymbol)1 Symbol (org.sonar.plugins.python.api.symbols.Symbol)1 AliasedName (org.sonar.plugins.python.api.tree.AliasedName)1 AssignmentExpression (org.sonar.plugins.python.api.tree.AssignmentExpression)1 ComprehensionExpression (org.sonar.plugins.python.api.tree.ComprehensionExpression)1 ConditionalExpression (org.sonar.plugins.python.api.tree.ConditionalExpression)1 Decorator (org.sonar.plugins.python.api.tree.Decorator)1