Himanshu
Himanshu

Reputation: 11

Raising issues on specific file in SonarJS

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?

Upvotes: 0

Views: 26

Answers (1)

Tibor Blenessy
Tibor Blenessy

Reputation: 4430

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);
  }

Upvotes: 0

Related Questions