Search in sources :

Example 11 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class HeaderCheckTest method scanWithWrongInputFile.

public static void scanWithWrongInputFile(File file, DefaultNodeVisitor visitor) {
    HtmlAstScanner walker = new HtmlAstScanner(Collections.emptyList());
    walker.addVisitor(visitor);
    FileReader reader;
    try {
        reader = new FileReader(file);
    } catch (Exception e) {
        throw new IllegalArgumentException("unable to read file");
    }
    HtmlSourceCode result = new HtmlSourceCode(new TestInputFileBuilder("key", /* wrong path */
    ".").setLanguage(HtmlConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()).build());
    walker.scan(new PageLexer().parse(reader), // won't be able to resolve the file
    result);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) PageLexer(org.sonar.plugins.html.lex.PageLexer) 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) ExpectedException(org.junit.rules.ExpectedException)

Example 12 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class JspScriptletCheckTest method test.

@Test
public void test() throws Exception {
    HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/jspScriptletCheck.html"), new JspScriptletCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(1).withMessage("Replace this scriptlet using tag libraries and expression language.").next().atLine(8);
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) File(java.io.File) Test(org.junit.Test)

Example 13 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class NestedJavaScriptCheckTest method dangling_script_end_tag_should_result_in_a_violation.

@Test
public void dangling_script_end_tag_should_result_in_a_violation() {
    NestedJavaScriptCheck check = new NestedJavaScriptCheck();
    HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/NestedJavaScriptCheck/DanglingScriptEndTag.html"), check);
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLine(4).noMore();
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) File(java.io.File) Test(org.junit.Test)

Example 14 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class NestedJavaScriptCheckTest method no_violations_should_be_reported_for_correct_script_tags.

@Test
public void no_violations_should_be_reported_for_correct_script_tags() {
    NestedJavaScriptCheck check = new NestedJavaScriptCheck();
    HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/NestedJavaScriptCheck/CorrectScriptTags.html"), check);
    checkMessagesVerifier.verify(sourceCode.getIssues()).noMore();
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) File(java.io.File) Test(org.junit.Test)

Example 15 with HtmlSourceCode

use of org.sonar.plugins.html.visitor.HtmlSourceCode in project sonar-web by SonarSource.

the class ResourceIntegrityCheckTest method test.

@Test
public void test() {
    HtmlSourceCode sourceCode = TestHelper.scan(new File("src/test/resources/checks/resourceIntegrityCheck.html"), new ResourceIntegrityCheck());
    checkMessagesVerifier.verify(sourceCode.getIssues()).next().atLocation(1, 0, 1, 47).withMessage("Make sure not using resource integrity feature is safe here.").next().atLocation(2, 0, 2, 41).withMessage("Make sure not using resource integrity feature is safe here.").next().atLocation(3, 0, 3, 46).withMessage("Make sure not using resource integrity feature is safe here.").next().atLocation(4, 0, 4, 61).withMessage("Make sure not using resource integrity feature is safe here.");
}
Also used : HtmlSourceCode(org.sonar.plugins.html.visitor.HtmlSourceCode) File(java.io.File) Test(org.junit.Test)

Aggregations

HtmlSourceCode (org.sonar.plugins.html.visitor.HtmlSourceCode)115 File (java.io.File)111 Test (org.junit.Test)111 InputFile (org.sonar.api.batch.fs.InputFile)8 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)3 PageLexer (org.sonar.plugins.html.lex.PageLexer)3 Node (org.sonar.plugins.html.node.Node)3 HtmlAstScanner (org.sonar.plugins.html.visitor.HtmlAstScanner)3 FileReader (java.io.FileReader)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ExpectedException (org.junit.rules.ExpectedException)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 FileSystem (org.sonar.api.batch.fs.FileSystem)1 ComplexityVisitor (org.sonar.plugins.html.analyzers.ComplexityVisitor)1 PageCountLines (org.sonar.plugins.html.analyzers.PageCountLines)1 VueLexer (org.sonar.plugins.html.lex.VueLexer)1