Changeset View
Standalone View
src/lint/linter/ArcanistESLintLinter.php
| <?php | <?php | ||||
| final class ArcanistESLintLinter extends ArcanistExternalLinter { | final class ArcanistESLintLinter extends ArcanistExternalLinter { | ||||
| private $eslintenv; | |||||
| private $eslintconfig; | |||||
| public function getInfoName() { | public function getInfoName() { | ||||
| return 'ESLint'; | return 'ESLint'; | ||||
| } | } | ||||
| public function getInfoURI() { | public function getInfoURI() { | ||||
| return 'https://www.eslint.org'; | return 'https://www.eslint.org'; | ||||
| } | } | ||||
michaeljs1990: This is the only way I see presently to set a min version. However as noted above the user can… | |||||
| public function getInfoDescription() { | public function getInfoDescription() { | ||||
| return pht('ESLint is a linter for JavaScript source files.'); | return pht('ESLint is a linter for JavaScript source files.'); | ||||
| } | } | ||||
Done Inline ActionsLinter names are typically uppercase, consider changing this to ESLINT. joshuaspence: Linter names are typically uppercase, consider changing this to `ESLINT`. | |||||
Not Done Inline ActionsThis was actually changed since - see T9353. avivey: This was actually changed since - see T9353.
The idea is that the one-liner output from `arc… | |||||
| public function getVersion() { | |||||
| $output = exec('eslint --version'); | |||||
| if (strpos($output, 'command not found') !== false) { | |||||
| return false; | |||||
| } | |||||
| return $output; | |||||
| } | |||||
| public function getLinterName() { | public function getLinterName() { | ||||
Done Inline ActionsTechnically this should be written as pht('Install ESLint using `%s`.', 'npm install -g eslint') because npm install -g eslint isn't really translatable. joshuaspence: Technically this should be written as `pht('Install ESLint using ```%s```.', 'npm install -g… | |||||
Not Done Inline ActionsHi! I tried using this linter, and configured it to use the eslint binary relative to my project (node_modules/.bin/eslint), and it wouldn't report the version (because I don't have eslint installed globally). Maybe the line should be this, instead? list($output) = execx('%C --version', $this->getExecutableCommand());bspoon: Hi! I tried using this linter, and configured it to use the eslint binary relative to my… | |||||
Not Done Inline ActionsYou are correct, sorry I missed that. Will push up a change for it shortly. michaeljs1990: You are correct, sorry I missed that. Will push up a change for it shortly. | |||||
| return 'ESLint'; | return 'ESLINT'; | ||||
| } | } | ||||
| public function getLinterConfigurationName() { | public function getLinterConfigurationName() { | ||||
| return 'eslint'; | return 'eslint'; | ||||
Done Inline ActionsThis is the default value, just remove this method. joshuaspence: This is the default value, just remove this method. | |||||
| } | } | ||||
| public function getDefaultBinary() { | public function getDefaultBinary() { | ||||
| return 'eslint'; | return 'eslint'; | ||||
| } | } | ||||
| public function getInstallInstructions() { | public function getInstallInstructions() { | ||||
| return pht('Install ESLint using `npm install -g eslint`.'); | return pht('Install ESLint using `%s`.', 'npm install -g eslint'); | ||||
| } | |||||
| public function getMandatoryFlags() { | |||||
| $options = array(); | |||||
| $options[] = '--format=stylish'; | |||||
| if ($this->eslintenv) { | |||||
| $options[] = '--env='.$this->eslintenv; | |||||
| } | |||||
| if ($this->eslintconfig) { | |||||
| $options[] = '--config='.$this->eslintconfig; | |||||
| } | |||||
| return $options; | |||||
| } | |||||
| public function getLinterConfigurationOptions() { | |||||
| $options = array( | |||||
| 'eslint.eslintenv' => array( | |||||
| 'type' => 'optional string', | |||||
| 'help' => pht('enables specific environments.'), | |||||
| ), | |||||
| 'eslint.eslintconfig' => array( | |||||
| 'type' => 'optional string', | |||||
| 'help' => pht('config file to use the default is .eslint.'), | |||||
| ), | |||||
| ); | |||||
| return $options + parent::getLinterConfigurationOptions(); | |||||
| } | |||||
| public function setLinterConfigurationValue($key, $value) { | |||||
| switch ($key) { | |||||
| case 'eslint.eslintenv': | |||||
| $this->eslintenv = $value; | |||||
| return; | |||||
| case 'eslint.eslintconfig': | |||||
| $this->eslintconfig = $value; | |||||
| return; | |||||
| } | } | ||||
| protected function canCustomizeLintSeverities() { | return parent::setLinterConfigurationValue($key, $value); | ||||
| return true; | |||||
| } | } | ||||
| protected function parseLinterOutput($path, $err, $stdout, $stderr) { | protected function parseLinterOutput($path, $err, $stdout, $stderr) { | ||||
| $lines = phutil_split_lines($stdout, false); | $lines = phutil_split_lines($stdout, false); | ||||
| $messages = array(); | $messages = array(); | ||||
| foreach ($lines as $line) { | foreach ($lines as $line) { | ||||
| // Clean up nasty ESLint output | // Clean up nasty ESLint output | ||||
| Show All 23 Lines | |||||
This is the only way I see presently to set a min version. However as noted above the user can potential mess this up by setting a lower version in .arclint or .arcconfig and I have no way to stop this presently.