Search in sources :

Example 6 with JSLintResult

use of com.googlecode.jslint4java.JSLintResult in project jslint4java by happygiraffe.

the class Main method lintFile.

// Eclipse's static analysis thinks I never close the UnicodeBomInputStream below.
private void lintFile(String file) throws IOException {
    BufferedReader reader = null;
    try {
        reader = readerForFile(file);
        JSLintResult result = lint.lint(file, reader);
        String msg = formatter.format(result);
        if (msg.length() > 0) {
            info(msg);
        }
        if (!result.getIssues().isEmpty()) {
            setErrored(true);
        }
    } catch (FileNotFoundException e) {
        die(file + ": No such file or directory.");
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) JSLintResult(com.googlecode.jslint4java.JSLintResult)

Example 7 with JSLintResult

use of com.googlecode.jslint4java.JSLintResult in project jslint4java by happygiraffe.

the class CheckstyleXmlFormatterTest method shouldHaveNoProblems.

@Test
public void shouldHaveNoProblems() throws Exception {
    JSLintResult result = new JSLintResult.ResultBuilder("hello.js").duration(0).build();
    String expected = "<file name=\"hello.js\" />";
    XMLAssert.assertXMLEqual(expected, form.format(result));
}
Also used : JSLintResult(com.googlecode.jslint4java.JSLintResult) Test(org.junit.Test)

Example 8 with JSLintResult

use of com.googlecode.jslint4java.JSLintResult in project jslint4java by happygiraffe.

the class CheckstyleXmlFormatterTest method shouldHaveOneProblem.

@Test
public void shouldHaveOneProblem() throws Exception {
    String name = "bad.js";
    Issue issue = new Issue.IssueBuilder(name, 1, 1, "this is not a daffodil").build();
    JSLintResult result = new JSLintResult.ResultBuilder(name).addIssue(issue).build();
    String expected = "<file name=\"bad.js\">" + "<error line='1' column='1' severity='warning' message='this is not a daffodil'" + " source='com.googlecode.jslint4java.JSLint' />" + "</file>";
    XMLAssert.assertXMLEqual(expected, form.format(result));
}
Also used : Issue(com.googlecode.jslint4java.Issue) JSLintResult(com.googlecode.jslint4java.JSLintResult) Test(org.junit.Test)

Example 9 with JSLintResult

use of com.googlecode.jslint4java.JSLintResult in project jslint4java by happygiraffe.

the class JSLintXmlFormatterTest method testNoOutput.

@Test
public void testNoOutput() throws Exception {
    JSLintResult result = new JSLintResult.ResultBuilder("good.js").build();
    String expected = "<file name='good.js'/>";
    String actual = form.format(result);
    XMLAssert.assertXMLEqual(expected, actual);
    XMLAssert.assertXMLValid(getValidatorFor(actual));
}
Also used : JSLintResult(com.googlecode.jslint4java.JSLintResult) Test(org.junit.Test)

Example 10 with JSLintResult

use of com.googlecode.jslint4java.JSLintResult in project jslint4java by happygiraffe.

the class JSLintXmlFormatterTest method testOneIssue.

@Test
public void testOneIssue() throws Exception {
    String name = "bad.js";
    Issue issue = new Issue.IssueBuilder(name, 1, 1, "too many goats teleported").build();
    JSLintResult result = new JSLintResult.ResultBuilder(name).addIssue(issue).build();
    String expected = "<file name='bad.js'>" + "<issue line='1' char='1' reason='too many goats teleported' evidence='' />" + "</file>";
    String actual = form.format(result);
    XMLAssert.assertXMLEqual(expected, actual);
    XMLAssert.assertXMLValid(getValidatorFor(actual));
}
Also used : Issue(com.googlecode.jslint4java.Issue) JSLintResult(com.googlecode.jslint4java.JSLintResult) Test(org.junit.Test)

Aggregations

JSLintResult (com.googlecode.jslint4java.JSLintResult)20 Test (org.junit.Test)17 Issue (com.googlecode.jslint4java.Issue)9 IssueBuilder (com.googlecode.jslint4java.Issue.IssueBuilder)3 BufferedReader (java.io.BufferedReader)2 JSLint (com.googlecode.jslint4java.JSLint)1 UnicodeBomInputStream (com.googlecode.jslint4java.UnicodeBomInputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1