Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions eslint_linter/src/ArcanistEslintLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ public function getLinterConfigurationOptions() {
final public function lintPath($path) {}

public function willLintPaths(array $paths) {
$this->checkEslintInstallation();
$this->execution = new ExecFuture('eslint --format=json --no-color ' . implode($paths, ' '));
if(!$this->checkLocalEslintInstallation() && !$this->checkGlobalEslintInstallation()){
throw new ArcanistUsageException(
pht('Eslint is not installed, please run `npm install eslint` or add it to your package.json')
);
}

$this->setExecution($paths);
$this->didRunLinters();
}

Expand All @@ -47,14 +52,29 @@ final public function didRunLinters() {
}
}

private function checkEslintInstallation() {
if (!Filesystem::binaryExists('eslint')) {
throw new ArcanistUsageException(
pht('Eslint is not installed, please run `npm install eslint` or add it to your package.json')
);
private function checkGlobalEslintInstallation() {
if (Filesystem::binaryExists('eslint')) {
return true;
}
return false;
}

private function checkLocalEslintInstallation(){
if (Filesystem::binaryExists('.\node_modules\.bin\eslint')) {
return true;
}
return false;
}

private function setExecution(array $paths){
if($this->checkLocalEslintInstallation()){
$this->execution = new ExecFuture('.\node_modules\.bin\eslint --format=json --no-color ' . implode($paths, ' '));
}
else{
$this->execution = new ExecFuture('eslint --format=json --no-color ' . implode($paths, ' '));
}
}

protected function parseLinterOutput($output) {
$json = json_decode($output, true);

Expand Down