use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class InlineStyleCheckTest method test.
@Test
public void test() throws Exception {
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/inlineStyleCheck.html"), new InlineStyleCheck());
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("Use CSS classes instead.");
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class IllegalTabCheckTest method test.
@Test
public void test() throws Exception {
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/IllegalTabCheck.html"), new IllegalTabCheck());
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(2).withMessage("Replace all tab characters in this file by sequences of white-spaces.");
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class WhiteSpaceAroundCheckTest method test.
@Test
public void test() throws Exception {
WebSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/whiteSpaceAroundCheck.html"), new WhiteSpaceAroundCheck());
checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("A whitespace is missing after the starting tag at column 4.").next().atLine(1).withMessage("Add a space at column 18.").next().atLine(3).withMessage("Add a space at column 18.").next().atLine(5).withMessage("A whitespace is missing after the starting tag at column 2.").next().atLine(7).withMessage("A whitespace is missing after the starting tag at column 3.").next().atLine(9).withMessage("A whitespace is missing after the starting tag at column 3.").next().atLine(11).withMessage("A whitespace is missing after the starting tag at column 3.").next().atLine(13).withMessage("A whitespace is missing after the starting tag at column 4.").next().atLine(13).withMessage("Add a space at column 18.");
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class PageCountLines method addMeasures.
private void addMeasures() {
WebSourceCode webSourceCode = getWebSourceCode();
webSourceCode.addMeasure(CoreMetrics.NCLOC, linesOfCode);
webSourceCode.addMeasure(CoreMetrics.COMMENT_LINES, commentLines);
webSourceCode.setDetailedLinesOfCode(detailedLinesOfCode);
webSourceCode.setDetailedLinesOfComments(detailedLinesOfComments);
LOG.debug("WebSensor: " + getWebSourceCode().toString() + ":" + linesOfCode + "," + commentLines + "," + headerCommentLines + "," + blankLines);
}
use of org.sonar.plugins.web.visitor.WebSourceCode in project sonar-web by SonarSource.
the class WebSensor method execute.
@Override
public void execute(SensorContext sensorContext) {
// configure the lexer
final PageLexer lexer = new PageLexer();
FileSystem fileSystem = sensorContext.fileSystem();
// configure page scanner and the visitors
final HtmlAstScanner scanner = setupScanner(sensorContext);
FilePredicates predicates = fileSystem.predicates();
Iterable<InputFile> inputFiles = fileSystem.inputFiles(predicates.and(predicates.hasType(InputFile.Type.MAIN), predicates.hasLanguage(WebConstants.LANGUAGE_KEY)));
for (InputFile inputFile : inputFiles) {
WebSourceCode sourceCode = new WebSourceCode(inputFile);
try (FileReader reader = new FileReader(inputFile.file())) {
scanner.scan(lexer.parse(reader), sourceCode, fileSystem.encoding());
saveMetrics(sensorContext, sourceCode);
saveLineLevelMeasures(inputFile, sourceCode);
} catch (Exception e) {
LOG.error("Cannot analyze file " + inputFile.file().getAbsolutePath(), e);
}
}
}
Aggregations