Search in sources :

Example 1 with JSLintResult

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

the class JUnitXmlResultFormatterTest method testFileSetReallyIsFile.

@Test
public void testFileSetReallyIsFile() throws Exception {
    thrown.expect(BuildException.class);
    thrown.expectMessage("must be a directory");
    JSLintResult result = aResult("foo.js");
    formatter.setFile(folder.newFile("foo"));
    formatResult(result);
}
Also used : JSLintResult(com.googlecode.jslint4java.JSLintResult) Test(org.junit.Test)

Example 2 with JSLintResult

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

the class XmlResultFormatterTest method testXmlOutputGood.

@Test
public void testXmlOutputGood() throws Exception {
    JSLintResult result = new JSLintResult.ResultBuilder("main.js").build();
    runTest(result);
}
Also used : JSLintResult(com.googlecode.jslint4java.JSLintResult) Test(org.junit.Test)

Example 3 with JSLintResult

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

the class JSLintTask method lintStream.

/**
     * Lint a given stream. Closes the stream after use.
     *
     * @param lint
     *
     * @throws IOException
     */
private int lintStream(JSLint lint, Resource resource) throws UnsupportedEncodingException, IOException {
    BufferedReader reader = null;
    try {
        UnicodeBomInputStream stream = new UnicodeBomInputStream(resource.getInputStream());
        stream.skipBOM();
        reader = new BufferedReader(new InputStreamReader(stream, encoding));
        String name = resource.toString();
        JSLintResult result = lint.lint(name, reader);
        log("Found " + result.getIssues().size() + " issues in " + name, Project.MSG_VERBOSE);
        for (ResultFormatter rf : formatters) {
            rf.output(result);
        }
        return result.getIssues().size();
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) UnicodeBomInputStream(com.googlecode.jslint4java.UnicodeBomInputStream) BufferedReader(java.io.BufferedReader) JSLintResult(com.googlecode.jslint4java.JSLintResult)

Example 4 with JSLintResult

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

the class XmlResultFormatterTest method testXmlOutputBad.

@Test
public void testXmlOutputBad() throws Exception {
    String name = "main.js";
    Issue issue = new Issue.IssueBuilder(name, 1, 1, "smelly socks").build();
    JSLintResult result = new JSLintResult.ResultBuilder(name).addIssue(issue).build();
    runTest(result);
}
Also used : Issue(com.googlecode.jslint4java.Issue) JSLintResult(com.googlecode.jslint4java.JSLintResult) Test(org.junit.Test)

Example 5 with JSLintResult

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

the class JSLintMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("skipping JSLint");
        return;
    }
    JSLint jsLint = applyJSlintSource();
    applyDefaults();
    applyOptions(jsLint);
    List<File> files = getFilesToProcess();
    int failures = 0;
    ReportWriter reporter = makeReportWriter();
    try {
        reporter.open();
        for (File file : files) {
            JSLintResult result = lintFile(jsLint, file);
            failures += result.getIssues().size();
            logIssues(result, reporter);
        }
    } finally {
        reporter.close();
    }
    if (failures > 0) {
        String message = "JSLint found " + failures + " problems in " + files.size() + " files";
        if (failOnError) {
            throw new MojoFailureException(message);
        } else {
            getLog().info(message);
        }
    }
}
Also used : JSLint(com.googlecode.jslint4java.JSLint) MojoFailureException(org.apache.maven.plugin.MojoFailureException) JSLintResult(com.googlecode.jslint4java.JSLintResult) File(java.io.File) JSLint(com.googlecode.jslint4java.JSLint)

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