Hello Lonzak,
I finally had the time to investigate the issues you where having, thanks a lot for the reproducer you sent (the Futurama example made me laugh).
I identified a two distinct issues:
- Regarding template rule "Track uses of disallowed classes":
The implementation of the rule is currently not targeting method invocations nor package declarations, meaning that any method call such as MyForbiddenType.foo() is never going to raise any issue... This will be handled by the following ticket: SONARJAVA-2743 - Regarding template rule "Track comments matching a regular expression":
On this one I think it's only a configuration problem. We use java.util.regex.Pattern.compile(regularExpression, Pattern.DOTALL) to compile the regex provided to the templated rule. This pattern is then tested directly against the FULL content (as string) of each "COMMENT" (in term of Abstract Syntax Tree). It term of implementation, it means that we use the "matches()" method rather than the "find()", consequently, we expect that the whole comment should match the regex. I gave a try to the following and the regex you provided:
public static void main(String[] args) {
Pattern compile = Pattern.compile("\\bTODO\\s(?!\\d{6}\\b)", Pattern.DOTALL);
System.out.println("find()");
System.out.println(compile.matcher("// TODO").find()); // <<<---- false
System.out.println(compile.matcher("// TODO continue").find()); // <<<---- true
System.out.println("matches()");
System.out.println(compile.matcher("// TODO").matches()); // <<<---- false
System.out.println(compile.matcher("// TODO continue").matches()); // <<<---- false
}
Now, by changing your regext to a DOTALL format, I have the following: .*\bTODO\s(?!\d{6}\b).*
I successfully raise an issue:
![image.png](https://groups.google.com/group/sonarqube/attach/225d03ca90908/image.png?part=0.1&view=1)
I consequently think that there is no reason to change the rule itself. I'm however going to modify the description of
RSPEC-124 in order to make it very explicit that we expect the DOTALL pattern to be used in the regex, and that the pattern is applied against the whole comment content.
Now, in conclusion, I'm glad to see that these two issues are not related at all with the project being multi-module, but simply flaws/bad documentation in rule.
Thanks again for your feedback (and for insisting)!
Cheers,
Michael