From d75791e56eb2871b3a5d23d9b827b0f8250a6a9e Mon Sep 17 00:00:00 2001 From: Yadvaindera Sood Date: Mon, 20 Aug 2018 16:42:40 -0400 Subject: [PATCH] tagview/arcanist-extensions#21 ArcanistESLinter should look for ESlint locally installed in project before looking for global installation of ESLint. If both are missing it should throw an exception. --- eslint_linter/src/ArcanistEslintLinter.php | 34 +++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/eslint_linter/src/ArcanistEslintLinter.php b/eslint_linter/src/ArcanistEslintLinter.php index 5f121ab..e9cd1f0 100644 --- a/eslint_linter/src/ArcanistEslintLinter.php +++ b/eslint_linter/src/ArcanistEslintLinter.php @@ -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(); } @@ -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);