public interface SingleFileVerifier
Path path = Paths.get("main.js");
SingleFileVerifier verifier = SingleFileVerifier.create(path, UTF_8);
// use an AST visitor to add all the comment
verifier.addComment(12, 20, " Noncompliant {{Rule message}}", 2, 0);
// report all issues raised by one rule
verifier.reportIssue("Issue on file").onFile();
verifier.reportIssue("Issue on line").onLine(4);
verifier.reportIssue("Issue on range").onRange(9, 11, 9, 13)
.addSecondary(6, 9, 6, 11, "msg");
verifier.assertOneOrMoreIssues();
Example 2:
// to expect to issue, use: verifier.assertNoIssues();
| Modifier and Type | Interface and Description |
|---|---|
static interface |
SingleFileVerifier.Issue |
static interface |
SingleFileVerifier.IssueBuilder
Must always call one and only one of: onFile, onLine, onRange
|
| Modifier and Type | Method and Description |
|---|---|
SingleFileVerifier |
addComment(int line,
int column,
String content,
int prefixLength,
int suffixLength)
Should be called for all comment of the analyzed source file.
|
void |
assertNoIssues()
Run the comparison and expect to find no issue.
|
void |
assertOneOrMoreIssues()
Run the comparison and expect to find at least one issue.
|
static SingleFileVerifier |
create(Path sourceFilePath,
Charset encoding) |
SingleFileVerifier.IssueBuilder |
reportIssue(String message)
Each issue raised by a rule should be reported using this method.
|
static SingleFileVerifier create(Path sourceFilePath, Charset encoding)
sourceFilePath - encoding - encoding used to load source fileSingleFileVerifier addComment(int line, int column, String content, int prefixLength, int suffixLength)
void visitComment(CommentToken token) {
verifier.addComment(token.line(), token.column(), token.text(), COMMENT_PREFIX_LENGTH, COMMENT_SUFFIX_LENGTH);
}
line - start at 1, beginning of the commentcolumn - start at 1, beginning of the comment prefixcontent - content of the comment with prefix and suffixprefixLength - for example, if the prefix is '//' then the length is 2suffixLength - for example, if the suffix is '-->' then the length is 3SingleFileVerifier.IssueBuilder reportIssue(String message)
verifier.reportIssue("Issue on file").onFile();
verifier.reportIssue("Issue on line").onLine(line);
verifier.reportIssue("Issue on range with a secondary location").onRange(line, column, endLine, endColumn)
.addSecondary(secondary.line, secondary.column, secondary.endLine, secondary.endColumn, "Secondary message");
message - issue messagevoid assertOneOrMoreIssues()
void assertNoIssues()
Copyright © 2009–2018 SonarSource. All rights reserved.