use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class TestHelper method scan.
public static WebSourceCode scan(File file, DefaultNodeVisitor visitor) {
FileReader fileReader;
try {
fileReader = new FileReader(file);
} catch (FileNotFoundException e) {
throw Throwables.propagate(e);
}
WebSourceCode result = new WebSourceCode(new DefaultInputFile("key", file.getPath()).setLanguage(WebConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()));
HtmlAstScanner walker = new HtmlAstScanner(ImmutableList.of(new PageCountLines(), new ComplexityVisitor()));
walker.addVisitor(visitor);
walker.scan(new PageLexer().parse(fileReader), result, Charsets.UTF_8);
return result;
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class IllegalAttributeCheckTest method custom.
@Test
public void custom() {
IllegalAttributeCheck check = new IllegalAttributeCheck();
check.attributes = "foo.a,b";
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/IllegalAttributeCheck.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("Remove the \"a\" attribute from the \"foo\" tag").next().atLine(3).withMessage("Remove the \"b\" attribute from the \"baz\" tag");
}
use of org.sonar.plugins.web.visitor.WebSourceCode 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";
WebSourceCode 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.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class DoubleQuotesCheckTest method test.
@Test
public void test() throws Exception {
WebSourceCode 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.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class FileLengthCheckTest method custom.
@Test
public void custom() {
FileLengthCheck check = new FileLengthCheck();
check.maxLength = 3;
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/FileLengthCheck.html"), check);
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(null).withMessage("Current file has 5 lines, which is greater than 3 authorized. Split it into smaller files.");
}
Aggregations