use of org.sonar.plugins.python.api.tree.StatementList in project sonar-python by SonarSource.
the class WildcardImportCheck method initialize.
@Override
public void initialize(Context context) {
context.registerSyntaxNodeConsumer(Tree.Kind.FILE_INPUT, ctx -> {
if (ctx.pythonFile().fileName().equals("__init__.py")) {
// Ignore __init__.py files, as wildcard imports are commonly used to populate those.
return;
}
FileInput fileInput = (FileInput) ctx.syntaxNode();
StatementList statements = fileInput.statements();
if (statements == null) {
return;
}
WildcardImportVisitor visitor = new WildcardImportVisitor();
statements.accept(visitor);
if (visitor.shouldRaiseIssues) {
visitor.wildcardImports.forEach(importFrom -> ctx.addIssue(importFrom, MESSAGE));
}
});
}
Aggregations