@Override
  public void execute(SensorContext context) {
    List<TreeVisitor> treeVisitors = Lists.newArrayList();
    boolean isAtLeastSq62 = context.getSonarQubeVersion().isGreaterThanOrEqual(V6_2);

    MetricsVisitor metricsVisitor =
        new MetricsVisitor(
            context,
            noSonarFilter,
            context.settings().getBoolean(JavaScriptPlugin.IGNORE_HEADER_COMMENTS),
            fileLinesContextFactory,
            isAtLeastSq62);

    treeVisitors.add(metricsVisitor);
    treeVisitors.add(new HighlighterVisitor(context, fileSystem));
    treeVisitors.add(new SeChecksDispatcher(checks.seChecks()));
    treeVisitors.add(new CpdVisitor(fileSystem, context));
    treeVisitors.addAll(checks.visitorChecks());

    for (TreeVisitor check : treeVisitors) {
      if (check instanceof ParsingErrorCheck) {
        parsingErrorRuleKey = checks.ruleKeyFor((JavaScriptCheck) check);
        break;
      }
    }

    ProgressReport progressReport =
        new ProgressReport(
            "Report about progress of Javascript analyzer", TimeUnit.SECONDS.toMillis(10));
    progressReport.start(Lists.newArrayList(fileSystem.files(mainFilePredicate)));

    analyseFiles(context, treeVisitors, fileSystem.inputFiles(mainFilePredicate), progressReport);

    executeCoverageSensors(context, metricsVisitor.linesOfCode(), isAtLeastSq62);
  }
 private RuleKey ruleKey(JavaScriptCheck check) {
   Preconditions.checkNotNull(check);
   RuleKey ruleKey = checks.ruleKeyFor(check);
   if (ruleKey == null) {
     throw new IllegalStateException("No rule key found for a rule");
   }
   return ruleKey;
 }
  /**
   * Cost is set if <code>cost<code/> is more than zero.
   * */
  private void commonAddIssue(JavaScriptCheck check, int line, String message, double cost) {
    Preconditions.checkNotNull(check);
    Preconditions.checkNotNull(message);

    RuleKey ruleKey = checks.ruleKeyFor(check);
    if (ruleKey == null) {
      throw new IllegalStateException("No rule key found for a rule");
    }

    IssueBuilder issueBuilder = issuable.newIssueBuilder().ruleKey(ruleKey).message(message);

    if (line > 0) {
      issueBuilder.line(line);
    }
    if (cost > 0) {
      issueBuilder.effortToFix(cost);
    }

    issuable.addIssue(issueBuilder.build());
  }
  public JavaScriptSquidSensor(
      CheckFactory checkFactory,
      FileLinesContextFactory fileLinesContextFactory,
      FileSystem fileSystem,
      NoSonarFilter noSonarFilter,
      @Nullable CustomJavaScriptRulesDefinition[] customRulesDefinition) {

    this.checks =
        JavaScriptChecks.createJavaScriptCheck(checkFactory)
            .addChecks(CheckList.REPOSITORY_KEY, CheckList.getChecks())
            .addCustomChecks(customRulesDefinition);
    this.fileLinesContextFactory = fileLinesContextFactory;
    this.fileSystem = fileSystem;
    this.noSonarFilter = noSonarFilter;
    this.mainFilePredicate =
        fileSystem
            .predicates()
            .and(
                fileSystem.predicates().hasType(InputFile.Type.MAIN),
                fileSystem.predicates().hasLanguage(JavaScriptLanguage.KEY));
    this.parser = JavaScriptParserBuilder.createParser(getEncoding());
  }