mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Add a getVersion
function to ArcanistExternalLinter
.
Summary: This method will, theoretically, allow `arc lint` to be configured to require some minimum version of an external linter (although this would probably require significantly more work). Additionally, the existence of this method simplifies the `getCacheVersion` function which, previously, was implemented by the external linters individually. Instead, a general approach to determining the version for cacheing purposes can be used. Fixes T4954. Test Plan: I'm not sure how to test this. Reviewers: chad, epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: epriestley, Korvin Maniphest Tasks: T4954 Differential Revision: https://secure.phabricator.com/D8971
This commit is contained in:
parent
a7327ca0e9
commit
f2b341ae03
7 changed files with 77 additions and 12 deletions
|
@ -34,6 +34,17 @@ final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
|
||||||
return $config->getConfigFromAnySource('lint.csslint.bin', 'csslint');
|
return $config->getConfigFromAnySource('lint.csslint.bin', 'csslint');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVersion() {
|
||||||
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
if (preg_match('/^v(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
|
||||||
|
return $matches['version'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getInstallInstructions() {
|
public function getInstallInstructions() {
|
||||||
return pht('Install CSSLint using `npm install -g csslint`.');
|
return pht('Install CSSLint using `npm install -g csslint`.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,6 +369,21 @@ abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
|
||||||
return array_merge($mandatory_flags, $flags);
|
return array_merge($mandatory_flags, $flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCacheVersion() {
|
||||||
|
$version = $this->getVersion();
|
||||||
|
|
||||||
|
if ($version) {
|
||||||
|
return $version.'-'.json_encode($this->getCommandFlags());
|
||||||
|
} else {
|
||||||
|
// Either we failed to parse the version number or the `getVersion`
|
||||||
|
// function hasn't been implemented.
|
||||||
|
return json_encode($this->getCommandFlags());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVersion() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected function buildFutures(array $paths) {
|
protected function buildFutures(array $paths) {
|
||||||
$executable = $this->getExecutableCommand();
|
$executable = $this->getExecutableCommand();
|
||||||
|
|
|
@ -34,6 +34,17 @@ final class ArcanistFlake8Linter extends ArcanistExternalLinter {
|
||||||
return 'flake8';
|
return 'flake8';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVersion() {
|
||||||
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)\b/', $stdout, $matches)) {
|
||||||
|
return $matches['version'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getInstallInstructions() {
|
public function getInstallInstructions() {
|
||||||
return pht('Install flake8 using `easy_install flake8`.');
|
return pht('Install flake8 using `easy_install flake8`.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,18 +35,16 @@ final class ArcanistJSHintLinter extends ArcanistExternalLinter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCacheVersion() {
|
public function getVersion() {
|
||||||
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
||||||
|
|
||||||
// Extract version number from standard output.
|
|
||||||
$matches = array();
|
$matches = array();
|
||||||
if (preg_match('/^jshint v(\d+\.\d+\.\d+)$/', $stdout, $matches)) {
|
$regex = '/^jshint v(?P<version>\d+\.\d+\.\d+)$/';
|
||||||
$version = $matches[1];
|
if (preg_match($regex, $stdout, $matches)) {
|
||||||
|
return $matches['version'];
|
||||||
} else {
|
} else {
|
||||||
$version = md5($stdout);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $version . '-' . md5(json_encode($this->getCommandFlags()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInstallInstructions() {
|
public function getInstallInstructions() {
|
||||||
|
|
|
@ -15,11 +15,6 @@ final class ArcanistPEP8Linter extends ArcanistExternalLinter {
|
||||||
return 'pep8';
|
return 'pep8';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCacheVersion() {
|
|
||||||
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
|
||||||
return $stdout.implode(' ', $this->getCommandFlags());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDefaultFlags() {
|
public function getDefaultFlags() {
|
||||||
// TODO: Warn that all of this is deprecated.
|
// TODO: Warn that all of this is deprecated.
|
||||||
$config = $this->getEngine()->getConfigurationManager();
|
$config = $this->getEngine()->getConfigurationManager();
|
||||||
|
@ -55,6 +50,17 @@ final class ArcanistPEP8Linter extends ArcanistExternalLinter {
|
||||||
return $arc_root.'/externals/pep8/pep8.py';
|
return $arc_root.'/externals/pep8/pep8.py';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVersion() {
|
||||||
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
if (preg_match('/^(?P<version>\d+\.\d+\.\d+)$/', $stdout, $matches)) {
|
||||||
|
return $matches['version'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getInstallInstructions() {
|
public function getInstallInstructions() {
|
||||||
return pht('Install PEP8 using `easy_install pep8`.');
|
return pht('Install PEP8 using `easy_install pep8`.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,18 @@ final class ArcanistPhpcsLinter extends ArcanistExternalLinter {
|
||||||
return $config->getConfigFromAnySource('lint.phpcs.bin', 'phpcs');
|
return $config->getConfigFromAnySource('lint.phpcs.bin', 'phpcs');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVersion() {
|
||||||
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
$regex = '/^PHP_CodeSniffer version (?P<version>\d+\.\d+\.\d+)\b/';
|
||||||
|
if (preg_match($regex, $stdout, $matches)) {
|
||||||
|
return $matches['version'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function shouldExpectCommandErrors() {
|
public function shouldExpectCommandErrors() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,18 @@ final class ArcanistRubyLinter extends ArcanistExternalLinter {
|
||||||
return 'ruby';
|
return 'ruby';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getVersion() {
|
||||||
|
list($stdout) = execx('%C --version', $this->getExecutableCommand());
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
$regex = '/^ruby (?P<version>\d+\.\d+\.\d+)p\d+/';
|
||||||
|
if (preg_match($regex, $stdout, $matches)) {
|
||||||
|
return $matches['version'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getInstallInstructions() {
|
public function getInstallInstructions() {
|
||||||
return pht('Install `ruby` from <http://www.ruby-lang.org/>.');
|
return pht('Install `ruby` from <http://www.ruby-lang.org/>.');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue