Search in sources :

Example 1 with LintResult

use of com.jscs.cli.data.LintResult in project jscs-plugin by idok.

the class JscsRunnerTest method testSimpleLintJSX.

@Test
public void testSimpleLintJSX() {
    String file = JSCS_PLUGIN_ROOT + "/testData/jsx.js";
    JscsSettings settings = createSettings(file);
    settings.esprima = "esprima-fb";
    LintResult result = JscsRunner.lint(settings);
    System.out.println(result.errorOutput);
    System.out.println(result.jscsLint.file.name);
    System.out.println("found " + result.jscsLint.file.errors.size() + " issues");
    for (JscsLint.Issue err : result.jscsLint.file.errors) {
        System.out.println(err.message);
    }
    assertEquals("File should match", file, result.jscsLint.file.name);
    assertEquals("Should be no errors", 0, result.jscsLint.file.errors.size());
}
Also used : JscsLint(com.jscs.cli.data.JscsLint) LintResult(com.jscs.cli.data.LintResult) JscsSettings(com.jscs.cli.JscsSettings) Test(org.junit.Test)

Example 2 with LintResult

use of com.jscs.cli.data.LintResult in project jscs-plugin by idok.

the class JscsRunnerTest method testSimpleLintES6.

@Test
public void testSimpleLintES6() {
    String file = JSCS_PLUGIN_ROOT + "/testData/es6.js";
    JscsSettings settings = createSettings(file);
    settings.esnext = true;
    LintResult result = JscsRunner.lint(settings);
    System.out.println(result.errorOutput);
    System.out.println(result.jscsLint.file.name);
    System.out.println("found " + result.jscsLint.file.errors.size() + " issues");
    for (JscsLint.Issue err : result.jscsLint.file.errors) {
        System.out.println(err.message);
    }
    assertEquals("File should match", file, result.jscsLint.file.name);
    assertEquals("Should be no errors", 0, result.jscsLint.file.errors.size());
}
Also used : JscsLint(com.jscs.cli.data.JscsLint) LintResult(com.jscs.cli.data.LintResult) JscsSettings(com.jscs.cli.JscsSettings) Test(org.junit.Test)

Example 3 with LintResult

use of com.jscs.cli.data.LintResult in project jscs-plugin by idok.

the class JscsRunnerTest method testSimpleLint2.

//    @Test
//    public void testSimpleLint() {
//        JscsSettings settings = createSettings(JSCS_PLUGIN_ROOT + "/testData/eq.js");
//        ProcessOutput out;
//        try {
//            out = JscsRunner.lint(settings);
////            System.out.println(settings);
//            System.out.println(out.getStdout());
//            assertEquals("Exit code should be 1", 1, out.getExitCode());
//        } catch (ExecutionException e) {
//            e.printStackTrace();
//        }
//    }
@Test
public void testSimpleLint2() {
    JscsSettings settings = createSettings(JSCS_PLUGIN_ROOT + "/testData/test.js");
    LintResult result = JscsRunner.lint(settings);
    System.out.println(result.errorOutput);
    System.out.println(result.jscsLint.file.name);
    System.out.println("found " + result.jscsLint.file.errors.size() + " issues");
    for (JscsLint.Issue err : result.jscsLint.file.errors) {
        System.out.println(err.message);
    }
    assertEquals("Exit code should be 1", JSCS_PLUGIN_ROOT + "/testData/test.js", result.jscsLint.file.name);
}
Also used : JscsLint(com.jscs.cli.data.JscsLint) LintResult(com.jscs.cli.data.LintResult) JscsSettings(com.jscs.cli.JscsSettings) Test(org.junit.Test)

Example 4 with LintResult

use of com.jscs.cli.data.LintResult in project jscs-plugin by idok.

the class JscsRunner method lint.

public static LintResult lint(@NotNull JscsSettings settings) {
    LintResult result = new LintResult();
    try {
        GeneralCommandLine commandLine = createCommandLineLint(settings);
        ProcessOutput out = execute(commandLine, TIME_OUT);
        //        if (out.getExitCode() == 0) {
        //        } else {
        result.errorOutput = out.getStderr();
        try {
            result.jscsLint = JscsLint.read(out.getStdout());
        } catch (Exception e) {
        //result.errorOutput = out.getStdout();
        }
    //        }
    } catch (Exception e) {
        e.printStackTrace();
        result.errorOutput = e.toString();
    }
    return result;
}
Also used : LintResult(com.jscs.cli.data.LintResult) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Example 5 with LintResult

use of com.jscs.cli.data.LintResult in project jscs-plugin by idok.

the class JscsRunner method fix.

public static LintResult fix(@NotNull JscsSettings settings) {
    LintResult result = new LintResult();
    try {
        GeneralCommandLine commandLine = createCommandLineLint(settings);
        commandLine.addParameter("--fix");
        ProcessOutput out = execute(commandLine, TIME_OUT);
        result.errorOutput = out.getStderr();
        try {
            result.jscsLint = JscsLint.read(out.getStdout());
        } catch (Exception e) {
            LOG.error(e);
        //result.errorOutput = out.getStdout();
        }
    } catch (Exception e) {
        e.printStackTrace();
        result.errorOutput = e.toString();
    }
    return result;
}
Also used : LintResult(com.jscs.cli.data.LintResult) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

LintResult (com.jscs.cli.data.LintResult)6 JscsSettings (com.jscs.cli.JscsSettings)3 JscsLint (com.jscs.cli.data.JscsLint)3 Test (org.junit.Test)3 ExecutionException (com.intellij.execution.ExecutionException)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JscsProjectComponent (com.jscs.JscsProjectComponent)1