Search in sources :

Example 1 with PageCountLines

use of org.sonar.plugins.html.analyzers.PageCountLines in project sonar-web by SonarSource.

the class TestHelper method scan.

public static HtmlSourceCode scan(File file, DefaultNodeVisitor visitor) {
    FileReader fileReader;
    try {
        fileReader = new FileReader(file);
    } catch (FileNotFoundException e) {
        throw new IllegalStateException(e);
    }
    HtmlSourceCode result = new HtmlSourceCode(new TestInputFileBuilder("key", file.getPath()).setLanguage(HtmlConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()).setCharset(StandardCharsets.UTF_8).build());
    HtmlAstScanner walker = new HtmlAstScanner(Arrays.asList(new PageCountLines(), new ComplexityVisitor()));
    walker.addVisitor(visitor);
    walker.scan(new PageLexer().parse(fileReader), result);
    return result;
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) PageLexer(org.sonar.plugins.html.lex.PageLexer) ComplexityVisitor(org.sonar.plugins.html.analyzers.ComplexityVisitor) FileNotFoundException(java.io.FileNotFoundException) PageCountLines(org.sonar.plugins.html.analyzers.PageCountLines) FileReader(java.io.FileReader) HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) HtmlAstScanner(org.sonar.plugins.html.visitor.HtmlAstScanner)

Example 2 with PageCountLines

use of org.sonar.plugins.html.analyzers.PageCountLines in project sonar-web by SonarSource.

the class HtmlSensor method setupScanner.

/**
 * Create PageScanner with Visitors.
 */
private HtmlAstScanner setupScanner(SensorContext context) {
    List<DefaultNodeVisitor> visitors = new ArrayList<>();
    if (context.runtime().getProduct() != SonarProduct.SONARLINT) {
        visitors.add(new HtmlTokensVisitor(context));
    }
    visitors.add(new PageCountLines());
    visitors.add(new ComplexityVisitor());
    visitors.add(new NoSonarScanner(noSonarFilter));
    HtmlAstScanner scanner = new HtmlAstScanner(visitors);
    for (Object check : checks.all()) {
        ((AbstractPageCheck) check).setRuleKey(checks.ruleKey(check));
        scanner.addVisitor((AbstractPageCheck) check);
    }
    return scanner;
}
Also used : ComplexityVisitor(org.sonar.plugins.html.analyzers.ComplexityVisitor) DefaultNodeVisitor(org.sonar.plugins.html.visitor.DefaultNodeVisitor) ArrayList(java.util.ArrayList) PageCountLines(org.sonar.plugins.html.analyzers.PageCountLines) NoSonarScanner(org.sonar.plugins.html.visitor.NoSonarScanner) AbstractPageCheck(org.sonar.plugins.html.checks.AbstractPageCheck) HtmlAstScanner(org.sonar.plugins.html.visitor.HtmlAstScanner)

Aggregations

ComplexityVisitor (org.sonar.plugins.html.analyzers.ComplexityVisitor)2 PageCountLines (org.sonar.plugins.html.analyzers.PageCountLines)2 HtmlAstScanner (org.sonar.plugins.html.visitor.HtmlAstScanner)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 InputFile (org.sonar.api.batch.fs.InputFile)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 AbstractPageCheck (org.sonar.plugins.html.checks.AbstractPageCheck)1 PageLexer (org.sonar.plugins.html.lex.PageLexer)1 DefaultNodeVisitor (org.sonar.plugins.html.visitor.DefaultNodeVisitor)1 HtmlSourceCode (org.sonar.plugins.html.visitor.HtmlSourceCode)1 NoSonarScanner (org.sonar.plugins.html.visitor.NoSonarScanner)1