Skip to content

Commit

Permalink
Add ESLint path variables (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomtomgo authored Feb 18, 2020
1 parent ba7bce3 commit b991f9d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public enum GeneralOption implements ConfigurationOption {

ESLINT_ENABLED("eslint.enabled", "ESLint enabled", "false"),
ESLINT_RCFILE("eslint.rcfile", "ESLint rcfile", null),
ESLINT_EXECUTABLE("eslint.executable", "ESLint executable", "eslint"),
ESLINT_PLUGINS_FOLDER("eslint.pluginsFolder", "ESLint plugin folder", null),

PYLINT_ENABLED("pylint.enabled", "Pylint enabled", "false"),
PYLINT_RCFILE("pylint.rcfile", "Pylint rcfile", null),
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/pl/touk/sputnik/processor/eslint/ESLintExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,30 @@

class ESLintExecutor {

private static final String ESLINT_EXECUTABLE = "eslint";
private static final String[] ESLINT_OUTPUT_FORMAT = {"--format", "json"};
private static final String ESLINT_RCFILE_NAME = "--config";
private static final String ESLINT_RESOLVE_PLUGINS_RELATIVE_TO = "--resolve-plugins-relative-to";

private final String eslintRcFile;
private final String eslintExecutable;
private final String pluginsFolder;

ESLintExecutor(String eslintRcFile) {
ESLintExecutor(String eslintRcFile, String eslintExecutable, String pluginsFolder) {
this.eslintRcFile = eslintRcFile;
this.eslintExecutable = eslintExecutable;
this.pluginsFolder = pluginsFolder;
}

String runOnFile(String filePath) {
return new ExternalProcess().executeCommand(buildParams(filePath));
}

private String[] buildParams(String filePath) {
List<String> args = Lists.newArrayList(ESLINT_EXECUTABLE);
List<String> args = Lists.newArrayList(eslintExecutable);
args.addAll(Arrays.asList(ESLINT_OUTPUT_FORMAT));
if (pluginsFolder != null) {
args.addAll(Arrays.asList(ESLINT_RESOLVE_PLUGINS_RELATIVE_TO, pluginsFolder));
}
if (eslintRcFile != null) {
args.addAll(Arrays.asList(ESLINT_RCFILE_NAME, eslintRcFile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class ESLintProcessor extends ProcessorRunningExternalProcess {
private final ESLintExecutor executor;

ESLintProcessor(Configuration configuration) {
executor = new ESLintExecutor(configuration.getProperty(GeneralOption.ESLINT_RCFILE));
executor = new ESLintExecutor(configuration.getProperty(GeneralOption.ESLINT_RCFILE),
configuration.getProperty(GeneralOption.ESLINT_EXECUTABLE),
configuration.getProperty(GeneralOption.ESLINT_PLUGINS_FOLDER));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pl.touk.sputnik.processor.eslint;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import pl.touk.sputnik.processor.eslint.json.FileViolations;
import pl.touk.sputnik.processor.eslint.json.Message;
Expand All @@ -14,7 +15,7 @@

class ESLintResultParser implements ExternalProcessResultParser {

private final ObjectMapper objectMapper = new ObjectMapper();
private final ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

@Override
public List<Violation> parse(String output) {
Expand Down

0 comments on commit b991f9d

Please sign in to comment.