use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class PageCountLinesTest method testCountLinesHtmlFile.
@Test
public void testCountLinesHtmlFile() {
List<Node> nodeList = lexer.parse(readFile("checks/AvoidHtmlCommentCheck/document.html"));
HtmlSourceCode htmlSourceCode = createHtmlSourceCode("test/document.html");
scanner.scan(nodeList, htmlSourceCode);
assertThat(htmlSourceCode.getMeasure(CoreMetrics.NCLOC)).isEqualTo(8);
assertThat(htmlSourceCode.getDetailedLinesOfCode()).containsOnly(1, 2, 3, 4, 6, 7, 8, 9);
assertThat(htmlSourceCode.getMeasure(CoreMetrics.COMMENT_LINES)).isEqualTo(1);
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode 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;
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class RequiredAttributeCheckTest method custom.
@Test
public void custom() {
RequiredAttributeCheck check = new RequiredAttributeCheck();
check.attributes = "img.alt,script.type";
HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/RequiredAttributeCheck.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(2).withMessage("Add the missing \"alt\" to element \"img\".").next().atLine(7).withMessage("Add the missing \"type\" to element \"script\".");
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class DoubleQuotesCheckTest method test.
@Test
public void test() throws Exception {
HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/doubleQuotesCheck.html"), new DoubleQuotesCheck());
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("Use double quotes instead of single ones.");
}
use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.
the class InternationalizationCheckTest method custom.
@Test
public void custom() {
InternationalizationCheck check = new InternationalizationCheck();
check.attributes = "outputLabel.value";
HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/InternationalizationCheck.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLocation(1, 13, 1, 16).withMessage("Define this label in the resource bundle.").next().atLocation(2, 0, 2, 25).withMessage("Define this label in the resource bundle.").next().atLine(9).withMessage("Define this label in the resource bundle.").next().atLine(10).withMessage("Define this label in the resource bundle.").next().atLine(11).withMessage("Define this label in the resource bundle.");
}
Aggregations