mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 23:02:41 +01:00
Provide a getProjectRoot method for ArcanistLinter
Summary: Adds a `getProjectRoot()` method to the `ArcanistLinter` class, simplifying a bunch of code. Test Plan: `arc unit` Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D12474
This commit is contained in:
parent
9444072e21
commit
1d72cfc944
4 changed files with 24 additions and 8 deletions
|
@ -339,7 +339,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
|
||||||
$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->getProjectRoot());
|
||||||
$futures[$path] = $future;
|
$futures[$path] = $future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,8 +407,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
|
||||||
public function setLinterConfigurationValue($key, $value) {
|
public function setLinterConfigurationValue($key, $value) {
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'interpreter':
|
case 'interpreter':
|
||||||
$working_copy = $this->getEngine()->getWorkingCopy();
|
$root = $this->getProjectRoot();
|
||||||
$root = $working_copy->getProjectRoot();
|
|
||||||
|
|
||||||
foreach ((array)$value as $path) {
|
foreach ((array)$value as $path) {
|
||||||
if (Filesystem::binaryExists($path)) {
|
if (Filesystem::binaryExists($path)) {
|
||||||
|
@ -429,8 +428,7 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
|
||||||
case 'bin':
|
case 'bin':
|
||||||
$is_script = $this->shouldUseInterpreter();
|
$is_script = $this->shouldUseInterpreter();
|
||||||
|
|
||||||
$working_copy = $this->getEngine()->getWorkingCopy();
|
$root = $this->getProjectRoot();
|
||||||
$root = $working_copy->getProjectRoot();
|
|
||||||
|
|
||||||
foreach ((array)$value as $path) {
|
foreach ((array)$value as $path) {
|
||||||
if (!$is_script && Filesystem::binaryExists($path)) {
|
if (!$is_script && Filesystem::binaryExists($path)) {
|
||||||
|
|
|
@ -248,6 +248,24 @@ abstract class ArcanistLinter {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function getProjectRoot() {
|
||||||
|
$engine = $this->getEngine();
|
||||||
|
if (!$engine) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'You must call %s before you can call %s.',
|
||||||
|
'setEngine()',
|
||||||
|
__FUNCTION__.'()'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$working_copy = $engine->getWorkingCopy();
|
||||||
|
if (!$working_copy) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $working_copy->getProjectRoot();
|
||||||
|
}
|
||||||
|
|
||||||
final public function getOtherLocation($offset, $path = null) {
|
final public function getOtherLocation($offset, $path = null) {
|
||||||
if ($path === null) {
|
if ($path === null) {
|
||||||
$path = $this->getActivePath();
|
$path = $this->getActivePath();
|
||||||
|
@ -386,7 +404,7 @@ abstract class ArcanistLinter {
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected function addLintMessage(ArcanistLintMessage $message) {
|
final protected function addLintMessage(ArcanistLintMessage $message) {
|
||||||
$root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
|
$root = $this->getProjectRoot();
|
||||||
$path = Filesystem::resolvePath($message->getPath(), $root);
|
$path = Filesystem::resolvePath($message->getPath(), $root);
|
||||||
$message->setPath(Filesystem::readablePath($path, $root));
|
$message->setPath(Filesystem::readablePath($path, $root));
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ final class ArcanistScriptAndRegexLinter extends ArcanistLinter {
|
||||||
*/
|
*/
|
||||||
public function willLintPaths(array $paths) {
|
public function willLintPaths(array $paths) {
|
||||||
$script = $this->getConfiguredScript();
|
$script = $this->getConfiguredScript();
|
||||||
$root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
|
$root = $this->getProjectRoot();
|
||||||
|
|
||||||
$futures = array();
|
$futures = array();
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
|
|
|
@ -54,7 +54,7 @@ final class ArcanistSpellingLinter extends ArcanistLinter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadDictionary($path) {
|
public function loadDictionary($path) {
|
||||||
$root = $this->getEngine()->getWorkingCopy()->getProjectRoot();
|
$root = $this->getProjectRoot();
|
||||||
$path = Filesystem::resolvePath($path, $root);
|
$path = Filesystem::resolvePath($path, $root);
|
||||||
|
|
||||||
$dict = phutil_json_decode(Filesystem::readFile($path));
|
$dict = phutil_json_decode(Filesystem::readFile($path));
|
||||||
|
|
Loading…
Reference in a new issue