0

I'm trying to write a custom linter that finds any usage of Log class in the project.

Everything compiles and I do have other linters that work well so it seems that everything is integrated as it should be.

Can you tell me what am I missing?

public class LoggerUsageDetector extends Detector
    implements Detector.ClassScanner {

public static final Issue ISSUE = Issue.create("SywLogIsNotUsed",
        "You must use our `SywLog`",
        "Logging should be avoided in production for security and performance reasons."
        + " Therefore, we created a SywLog that wraps all our calls to Logger and disable them for release flavor.",
        Category.CORRECTNESS,
        9,
        Severity.FATAL,
        new Implementation(LoggerUsageDetector.class,
                Scope.CLASS_FILE_SCOPE));

@Override
public List<String> getApplicableCallNames() {
    return Arrays.asList("v", "d", "i", "w", "e", "wtf");
}

@Override
public List<String> getApplicableMethodNames() {
    return Arrays.asList("v", "d", "i", "w", "e", "wtf");
}

@Override
public void checkCall(@NonNull ClassContext context,
                      @NonNull ClassNode classNode,
                      @NonNull MethodNode method,
                      @NonNull MethodInsnNode call) {
        context.report(ISSUE,
                method,
                call,
                context.getLocation(call),
                "You must use our `SywLog`");

}
}

And here is the registry of course:

public class LintersIssueRegistry extends IssueRegistry {

@Override
public List<Issue> getIssues() {
    return new ArrayList<Issue>() {{
        add(MyAnnotationDetector.CAREFUL_NOW_ISSUE);
        add(LoggerUsageDetector.ISSUE);
    }};
}

}

My "target" code that should throw an error:

    private void doSomething() {
    Log.v("ta", "");
    Log.d("ta", "");
    Log.wtf("ta", "");
}
Rom Shiri
  • 1,390
  • 4
  • 16
  • 29
  • What is the problem? Or should we assume that it "just isn't working"? Is there example code you are running this on? Maybe it has something to do with your target code? – Jon Adams Jan 03 '17 at 16:02
  • I get no errors when using Log class in my code. Updated my question. – Rom Shiri Jan 03 '17 at 16:13

0 Answers0