Steven Morad
Steven Morad

Reputation: 2617

JSLint4Java usage

JSLint4Java is a Java wrapper for JSLint. I need something like this for use in my GWT project, but the only way to use JSLint4Java seems to be from command line or with an ANT task. Does anyone know if there is any way to just import the JARs and use them in a project? When I try adding them to the GWT WAR folder, I get lots of errors like 'xxx cannot be resolved to a type'. Thanks.

Upvotes: 4

Views: 708

Answers (1)

Fabien
Fabien

Reputation: 975

Yes you can import the jar and use it like this :

import com.googlecode.jslint4java.Issue;
import com.googlecode.jslint4java.JSLint;
import com.googlecode.jslint4java.JSLintBuilder;
import com.googlecode.jslint4java.JSLintResult;


public static void lint(final String filePath) throws FileNotFoundException, IOException {
    String fileContent = Streams.read(new FileInputStream(new File(filePath))));
    JSLintBuilder builder = new JSLintBuilder();
    JSLint jsLint = builder.fromDefault();

    JSLintResult result = jsLint.lint("test.js", fileContent);
    for (Issue issue : result.getIssues()) {
        System.out.println(issue.toString());
    }

}

Upvotes: 5

Related Questions