Hi, I am trying to create a custom rule and i dont know how.
First of all i had to say that i read and try Custom rules 101 and I have followed the steps and I have managed to create the rule.
Now i was trying to create a simple rule for Java:
The rule is that I search for embeded SQL statements, for this, I want to search each line for the word SELECT.
I was trying to do this:
@Override
public List<Kind> nodesToVisit() {
return Collections.singletonList(Kind.FOR_EACH_STATEMENT);
}
@Override
public void visitNode(Tree tree) {
StatementTree method = (StatementTree) tree;
//Strategy: Look at each phrase to find a "SELECT", If found, reportIssue
String line = method.toString();
String[] words= line.split(" ");
for(int i = 0;i<words.length ;i++) {
if(words[i].equals("SELECT")) {
reportIssue(tree, "SQL detected");
}
}
}
I don,t know and i cant find info about Kind. Simply i read this and I thought that FOR_EACH_STTEMENT could be what I needed.
If anyone could help me I would really appreciate it. Thanks