Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistExternalLinter.php
| Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | /* -( Interpreters, Binaries and Flags )----------------------------------- */ | ||||
| * @param bool Return true to continue on nonzero error code. | * @param bool Return true to continue on nonzero error code. | ||||
| * @task bin | * @task bin | ||||
| */ | */ | ||||
| public function shouldExpectCommandErrors() { | public function shouldExpectCommandErrors() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** | /** | ||||
| * Return true to indicate that the external linter can read input from | |||||
| * stdin, rather than requiring a file. If this mode is supported, it is | |||||
| * slightly more flexible and may perform better, and is thus preferable. | |||||
| * | |||||
| * To send data over stdin instead of via a command line parameter, override | |||||
| * this method and return true. If the linter also needs a command line | |||||
| * flag (like `--stdin` or `-`), override | |||||
| * @{method:getReadDataFromStdinFilename} to provide it. | |||||
| * | |||||
| * For example, linters are normally invoked something like this: | |||||
| * | |||||
| * $ linter file.js | |||||
| * | |||||
| * If you override this method, invocation will be more similar to this: | |||||
| * | |||||
| * $ linter < file.js | |||||
| * | |||||
| * If you additionally override @{method:getReadDataFromStdinFilename} to | |||||
| * return `"-"`, invocation will be similar to this: | |||||
| * | |||||
| * $ linter - < file.js | |||||
| * | |||||
| * @return bool True to send data over stdin. | |||||
| * @task bin | |||||
| */ | |||||
| public function supportsReadDataFromStdin() { | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * If the linter can read data over stdin, override | |||||
| * @{method:supportsReadDataFromStdin} and then optionally override this | |||||
| * method to provide any required arguments (like `-` or `--stdin`). See | |||||
| * that method for discussion. | |||||
| * | |||||
| * @return string|null Additional arguments required by the linter when | |||||
| * operating in stdin mode. | |||||
| * @task bin | |||||
| */ | |||||
| public function getReadDataFromStdinFilename() { | |||||
| return null; | |||||
| } | |||||
| /** | |||||
| * Provide mandatory, non-overridable flags to the linter. Generally these | * Provide mandatory, non-overridable flags to the linter. Generally these | ||||
| * are format flags, like `--format=xml`, which must always be given for | * are format flags, like `--format=xml`, which must always be given for | ||||
| * the output to be usable. | * the output to be usable. | ||||
| * | * | ||||
| * Flags which are not mandatory should be provided in | * Flags which are not mandatory should be provided in | ||||
| * @{method:getDefaultFlags} instead. | * @{method:getDefaultFlags} instead. | ||||
| * | * | ||||
| * @return list<string> Mandatory flags, like `"--format=xml"`. | * @return list<string> Mandatory flags, like `"--format=xml"`. | ||||
| ▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | /* -( Executing the Linter )----------------------------------------------- */ | ||||
| final protected function buildFutures(array $paths) { | final protected function buildFutures(array $paths) { | ||||
| $executable = $this->getExecutableCommand(); | $executable = $this->getExecutableCommand(); | ||||
| $bin = csprintf('%C %Ls', $executable, $this->getCommandFlags()); | $bin = csprintf('%C %Ls', $executable, $this->getCommandFlags()); | ||||
| $futures = array(); | $futures = array(); | ||||
| foreach ($paths as $path) { | foreach ($paths as $path) { | ||||
| if ($this->supportsReadDataFromStdin()) { | |||||
| $future = new ExecFuture( | |||||
| '%C %C', | |||||
| $bin, | |||||
| $this->getReadDataFromStdinFilename()); | |||||
| $future->write($this->getEngine()->loadData($path)); | |||||
| } else { | |||||
| // TODO: In commit hook mode, we need to do more handling here. | |||||
| $disk_path = $this->getEngine()->getFilePathOnDisk($path); | $disk_path = $this->getEngine()->getFilePathOnDisk($path); | ||||
| $path_argument = $this->getPathArgumentForLinterFuture($disk_path); | $path_argument = $this->getPathArgumentForLinterFuture($disk_path); | ||||
| $future = new ExecFuture('%C %C', $bin, $path_argument); | $future = new ExecFuture('%C %C', $bin, $path_argument); | ||||
| } | |||||
| $future->setCWD($this->getEngine()->getWorkingCopy()->getProjectRoot()); | $future->setCWD($this->getEngine()->getWorkingCopy()->getProjectRoot()); | ||||
| $futures[$path] = $future; | $futures[$path] = $future; | ||||
| } | } | ||||
| return $futures; | return $futures; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines | |||||