Raising issues on specific file in SonarJS

26 views Asked by At

I am writing a custom rule regarding raising the issue if some keyword is not found in the file and that too I want to check on only one js file, not on all js files. Is there any way to pass filename on which I want to check rule specifically and raise the issue?

1

There are 1 answers

0
Tibor Blenessy On

The easiest way would be to test the filename in your rule implementation, you can do something like this in your rule

  @Override
  public List<Issue> scanFile(TreeVisitorContext context) {
    JavaScriptFile jsFile = context.getJavaScriptFile();
    if (jsFile.fileName().equals("file.js")) {
      addIssue(context.getTopTree(), "Issue on specific file.");
    }
    return super.scanFile(context);
  }