Page MenuHomePhorge

No OneTemporary

diff --git a/src/lint/linter/ArcanistCSSLintLinter.php b/src/lint/linter/ArcanistCSSLintLinter.php
index 7733393c..a6cb2f45 100644
--- a/src/lint/linter/ArcanistCSSLintLinter.php
+++ b/src/lint/linter/ArcanistCSSLintLinter.php
@@ -1,123 +1,119 @@
<?php
/**
* Uses "CSS Lint" to detect checkstyle errors in CSS code.
*/
final class ArcanistCSSLintLinter extends ArcanistExternalLinter {
public function getInfoName() {
return 'CSSLint';
}
public function getInfoURI() {
return 'http://csslint.net';
}
public function getInfoDescription() {
return pht(
'Use `%s` to detect issues with CSS source files.',
'csslint');
}
public function getLinterName() {
return 'CSSLint';
}
public function getLinterConfigurationName() {
return 'csslint';
}
protected function getMandatoryFlags() {
return array(
'--format=lint-xml',
);
}
protected function getDefaultFlags() {
return $this->getDeprecatedConfiguration('lint.csslint.options', array());
}
public function getDefaultBinary() {
return $this->getDeprecatedConfiguration('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() {
return pht(
'Install %s using `%s`.', 'CSSLint',
'npm install -g csslint');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$report_dom = new DOMDocument();
$ok = @$report_dom->loadXML($stdout);
if (!$ok) {
return false;
}
$files = $report_dom->getElementsByTagName('file');
$messages = array();
foreach ($files as $file) {
foreach ($file->childNodes as $child) {
$message = id(new ArcanistLintMessage())
->setPath($path)
->setLine($child->getAttribute('line'))
->setChar($child->getAttribute('char'))
->setCode($this->getLinterName())
->setDescription($child->getAttribute('reason'))
->setOriginalText(
substr(
$child->getAttribute('evidence'),
$child->getAttribute('char') - 1));
switch ($child->getAttribute('severity')) {
case 'error':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
case 'warning':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
break;
default:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
}
$messages[] = $message;
}
}
return $messages;
}
protected function getLintCodeFromLinterConfigurationKey($code) {
// NOTE: We can't figure out which rule generated each message, so we
// can not customize severities. I opened a pull request to add this
// ability; see:
//
// https://github.com/stubbornella/csslint/pull/409
throw new Exception(
pht(
"%s does not currently support custom severity levels, because ".
"rules can't be identified from messages in output.",
'CSSLint'));
}
}
diff --git a/src/lint/linter/ArcanistClosureLinter.php b/src/lint/linter/ArcanistClosureLinter.php
index d437f3b6..e6f77187 100644
--- a/src/lint/linter/ArcanistClosureLinter.php
+++ b/src/lint/linter/ArcanistClosureLinter.php
@@ -1,70 +1,66 @@
<?php
/**
* Uses `gjslint` to detect errors and potential problems in JavaScript code.
*/
final class ArcanistClosureLinter extends ArcanistExternalLinter {
public function getInfoName() {
return 'Closure Linter';
}
public function getInfoURI() {
return 'https://developers.google.com/closure/utilities/';
}
public function getInfoDescription() {
return pht("Uses Google's Closure Linter to check JavaScript code.");
}
public function getLinterName() {
return 'GJSLINT';
}
public function getLinterConfigurationName() {
return 'gjslint';
}
public function getDefaultBinary() {
return 'gjslint';
}
public function getInstallInstructions() {
return pht(
'Install %s using `%s`.',
'gjslint',
'sudo easy_install http://closure-linter.googlecode.com/'.
'files/closure_linter-latest.tar.gz');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return false;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stdout, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
if (!preg_match('/^Line (\d+), E:(\d+): (.*)/', $line, $matches)) {
continue;
}
$message = id(new ArcanistLintMessage())
->setPath($path)
->setLine($matches[1])
->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR)
->setCode($this->getLinterName().$matches[2])
->setDescription($matches[3]);
$messages[] = $message;
}
return $messages;
}
}
diff --git a/src/lint/linter/ArcanistCoffeeLintLinter.php b/src/lint/linter/ArcanistCoffeeLintLinter.php
index 75521623..9161fd14 100644
--- a/src/lint/linter/ArcanistCoffeeLintLinter.php
+++ b/src/lint/linter/ArcanistCoffeeLintLinter.php
@@ -1,150 +1,146 @@
<?php
final class ArcanistCoffeeLintLinter extends ArcanistExternalLinter {
private $config;
public function getInfoName() {
return 'CoffeeLint';
}
public function getInfoURI() {
return 'http://www.coffeelint.org';
}
public function getInfoDescription() {
return pht(
'CoffeeLint is a style checker that helps keep CoffeeScript '.
'code clean and consistent.');
}
public function getLinterName() {
return 'COFFEE';
}
public function getLinterConfigurationName() {
return 'coffeelint';
}
public function getDefaultBinary() {
return 'coffeelint';
}
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() {
return pht(
'Install CoffeeLint using `%s`.',
'npm install -g coffeelint');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return true;
}
public function getReadDataFromStdinFilename() {
return '--stdin';
}
protected function getMandatoryFlags() {
$options = array(
'--reporter=checkstyle',
);
if ($this->config) {
$options[] = '--file='.$this->config;
}
return $options;
}
public function getLinterConfigurationOptions() {
$options = array(
'coffeelint.config' => array(
'type' => 'optional string',
'help' => pht('A custom configuration file.'),
),
);
return $options + parent::getLinterConfigurationOptions();
}
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'coffeelint.config':
$this->config = $value;
return;
}
return parent::setLinterConfigurationValue($key, $value);
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$report_dom = new DOMDocument();
$ok = @$report_dom->loadXML($stdout);
if (!$ok) {
return false;
}
$files = $report_dom->getElementsByTagName('file');
$messages = array();
foreach ($files as $file) {
foreach ($file->getElementsByTagName('error') as $error) {
// Column number is not provided in the output.
// See https://github.com/clutchski/coffeelint/issues/87
$message = id(new ArcanistLintMessage())
->setPath($path)
->setLine($error->getAttribute('line'))
->setCode($this->getLinterName())
->setDescription(preg_replace(
'/; context: .*$/',
'.',
$error->getAttribute('message')));
switch ($error->getAttribute('severity')) {
case 'warning':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
break;
case 'error':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
default:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
break;
}
$messages[] = $message;
}
}
return $messages;
}
protected function getLintCodeFromLinterConfigurationKey($code) {
// NOTE: We can't figure out which rule generated each message, so we
// can not customize severities.
throw new Exception(
pht(
"CoffeeLint does not currently support custom severity levels, ".
"because rules can't be identified from messages in output."));
}
}
diff --git a/src/lint/linter/ArcanistCppcheckLinter.php b/src/lint/linter/ArcanistCppcheckLinter.php
index f4661b64..830452a5 100644
--- a/src/lint/linter/ArcanistCppcheckLinter.php
+++ b/src/lint/linter/ArcanistCppcheckLinter.php
@@ -1,110 +1,114 @@
<?php
/**
* Uses Cppcheck to do basic checks in a C++ file.
*/
final class ArcanistCppcheckLinter extends ArcanistExternalLinter {
public function getInfoName() {
return 'Cppcheck';
}
public function getInfoURI() {
return 'http://cppcheck.sourceforge.net';
}
public function getInfoDescription() {
return pht('Use `cppcheck` to perform static analysis on C/C++ code.');
}
public function getLinterName() {
return 'cppcheck';
}
public function getLinterConfigurationName() {
return 'cppcheck';
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.cppcheck.prefix');
$bin = $this->getDeprecatedConfiguration('lint.cppcheck.bin', 'cppcheck');
if ($prefix) {
return $prefix.'/'.$bin;
} else {
return $bin;
}
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
$regex = '/^Cppcheck (?P<version>\d+\.\d+)$/';
if (preg_match($regex, $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install Cppcheck using `apt-get install cppcheck` or similar.');
}
protected function getMandatoryFlags() {
return array(
'--quiet',
'--inline-suppr',
'--xml',
'--xml-version=2',
);
}
protected function getDefaultFlags() {
return $this->getDeprecatedConfiguration(
'lint.cppcheck.options',
array('-j2', '--enable=performance,style,portability,information'));
}
+ public function shouldExpectCommandErrors() {
+ return false;
+ }
+
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$dom = new DOMDocument();
$ok = @$dom->loadXML($stderr);
if (!$ok) {
return false;
}
$errors = $dom->getElementsByTagName('error');
$messages = array();
foreach ($errors as $error) {
foreach ($error->getElementsByTagName('location') as $location) {
$message = new ArcanistLintMessage();
$message->setPath($location->getAttribute('file'));
$message->setLine($location->getAttribute('line'));
$message->setCode('Cppcheck');
$message->setName($error->getAttribute('id'));
$message->setDescription($error->getAttribute('msg'));
switch ($error->getAttribute('severity')) {
case 'error':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
default:
if ($error->getAttribute('inconclusive')) {
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
} else {
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
}
break;
}
$messages[] = $message;
}
}
return $messages;
}
}
diff --git a/src/lint/linter/ArcanistCpplintLinter.php b/src/lint/linter/ArcanistCpplintLinter.php
index 3f660066..0e3f5b66 100644
--- a/src/lint/linter/ArcanistCpplintLinter.php
+++ b/src/lint/linter/ArcanistCpplintLinter.php
@@ -1,94 +1,90 @@
<?php
/**
* Uses Google's `cpplint.py` to check code.
*/
final class ArcanistCpplintLinter extends ArcanistExternalLinter {
public function getLinterName() {
return 'CPPLINT';
}
public function getLinterConfigurationName() {
return 'cpplint';
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.cpplint.prefix');
$bin = $this->getDeprecatedConfiguration('lint.cpplint.bin', 'cpplint.py');
if ($prefix) {
return $prefix.'/'.$bin;
} else {
return $bin;
}
}
public function getInstallInstructions() {
return pht('Install cpplint.py using `wget http://google-styleguide.'.
'googlecode.com/svn/trunk/cpplint/cpplint.py`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return true;
}
public function getReadDataFromStdinFilename() {
return '-';
}
protected function getDefaultFlags() {
return $this->getDeprecatedConfiguration('lint.cpplint.options', array());
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = explode("\n", $stderr);
$messages = array();
foreach ($lines as $line) {
$line = trim($line);
$matches = null;
$regex = '/^-:(\d+):\s*(.*)\s*\[(.*)\] \[(\d+)\]$/';
if (!preg_match($regex, $line, $matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[1]);
$message->setCode($matches[3]);
$message->setName($matches[3]);
$message->setDescription($matches[2]);
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
protected function getLintCodeFromLinterConfigurationKey($code) {
if (!preg_match('@^[a-z_]+/[a-z_]+$@', $code)) {
throw new Exception(
pht(
'Unrecognized lint message code "%s". Expected a valid cpplint '.
'lint code like "%s" or "%s".',
$code,
'build/include_order',
'whitespace/braces'));
}
return $code;
}
}
diff --git a/src/lint/linter/ArcanistExternalLinter.php b/src/lint/linter/ArcanistExternalLinter.php
index bcb7e1af..b6790d4f 100644
--- a/src/lint/linter/ArcanistExternalLinter.php
+++ b/src/lint/linter/ArcanistExternalLinter.php
@@ -1,538 +1,538 @@
<?php
/**
* Base class for linters which operate by invoking an external program and
* parsing results.
*
* @task bin Interpreters, Binaries and Flags
* @task parse Parsing Linter Output
* @task exec Executing the Linter
*/
abstract class ArcanistExternalLinter extends ArcanistFutureLinter {
private $bin;
private $interpreter;
private $flags;
/* -( Interpreters, Binaries and Flags )----------------------------------- */
/**
* Return the default binary name or binary path where the external linter
* lives. This can either be a binary name which is expected to be installed
* in PATH (like "jshint"), or a relative path from the project root
* (like "resources/support/bin/linter") or an absolute path.
*
* If the binary needs an interpreter (like "python" or "node"), you should
* also override @{method:shouldUseInterpreter} and provide the interpreter
* in @{method:getDefaultInterpreter}.
*
* @return string Default binary to execute.
* @task bin
*/
abstract public function getDefaultBinary();
/**
* Return a human-readable string describing how to install the linter. This
* is normally something like "Install such-and-such by running `npm install
* -g such-and-such`.", but will differ from linter to linter.
*
* @return string Human readable install instructions
* @task bin
*/
abstract public function getInstallInstructions();
/**
* Return true to continue when the external linter exits with an error code.
* By default, linters which exit with an error code are assumed to have
* failed. However, some linters exit with a specific code to indicate that
* lint messages were detected.
*
* If the linter sometimes raises errors during normal operation, override
* this method and return true so execution continues when it exits with
* a nonzero status.
*
* @param bool Return true to continue on nonzero error code.
* @task bin
*/
public function shouldExpectCommandErrors() {
- return false;
+ 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
* are format flags, like `--format=xml`, which must always be given for
* the output to be usable.
*
* Flags which are not mandatory should be provided in
* @{method:getDefaultFlags} instead.
*
* @return list<string> Mandatory flags, like `"--format=xml"`.
* @task bin
*/
protected function getMandatoryFlags() {
return array();
}
/**
* Provide default, overridable flags to the linter. Generally these are
* configuration flags which affect behavior but aren't critical. Flags
* which are required should be provided in @{method:getMandatoryFlags}
* instead.
*
* Default flags can be overridden with @{method:setFlags}.
*
* @return list<string> Overridable default flags.
* @task bin
*/
protected function getDefaultFlags() {
return array();
}
/**
* Override default flags with custom flags. If not overridden, flags provided
* by @{method:getDefaultFlags} are used.
*
* @param list<string> New flags.
* @return this
* @task bin
*/
final public function setFlags($flags) {
$this->flags = (array)$flags;
return $this;
}
/**
* Return the binary or script to execute. This method synthesizes defaults
* and configuration. You can override the binary with @{method:setBinary}.
*
* @return string Binary to execute.
* @task bin
*/
final public function getBinary() {
return coalesce($this->bin, $this->getDefaultBinary());
}
/**
* Override the default binary with a new one.
*
* @param string New binary.
* @return this
* @task bin
*/
final public function setBinary($bin) {
$this->bin = $bin;
return $this;
}
/**
* Return true if this linter should use an interpreter (like "python" or
* "node") in addition to the script.
*
* After overriding this method to return `true`, override
* @{method:getDefaultInterpreter} to set a default.
*
* @return bool True to use an interpreter.
* @task bin
*/
public function shouldUseInterpreter() {
return false;
}
/**
* Return the default interpreter, like "python" or "node". This method is
* only invoked if @{method:shouldUseInterpreter} has been overridden to
* return `true`.
*
* @return string Default interpreter.
* @task bin
*/
public function getDefaultInterpreter() {
throw new PhutilMethodNotImplementedException();
}
/**
* Get the effective interpreter. This method synthesizes configuration and
* defaults.
*
* @return string Effective interpreter.
* @task bin
*/
final public function getInterpreter() {
return coalesce($this->interpreter, $this->getDefaultInterpreter());
}
/**
* Set the interpreter, overriding any default.
*
* @param string New interpreter.
* @return this
* @task bin
*/
final public function setInterpreter($interpreter) {
$this->interpreter = $interpreter;
return $this;
}
/* -( Parsing Linter Output )---------------------------------------------- */
/**
* Parse the output of the external lint program into objects of class
* @{class:ArcanistLintMessage} which `arc` can consume. Generally, this
* means examining the output and converting each warning or error into a
* message.
*
* If parsing fails, returning `false` will cause the caller to throw an
* appropriate exception. (You can also throw a more specific exception if
* you're able to detect a more specific condition.) Otherwise, return a list
* of messages.
*
* @param string Path to the file being linted.
* @param int Exit code of the linter.
* @param string Stdout of the linter.
* @param string Stderr of the linter.
* @return list<ArcanistLintMessage>|false List of lint messages, or false
* to indicate parser failure.
* @task parse
*/
abstract protected function parseLinterOutput($path, $err, $stdout, $stderr);
/* -( Executing the Linter )----------------------------------------------- */
/**
* Check that the binary and interpreter (if applicable) exist, and throw
* an exception with a message about how to install them if they do not.
*
* @return void
*/
final public function checkBinaryConfiguration() {
$interpreter = null;
if ($this->shouldUseInterpreter()) {
$interpreter = $this->getInterpreter();
}
$binary = $this->getBinary();
// NOTE: If we have an interpreter, we don't require the script to be
// executable (so we just check that the path exists). Otherwise, the
// binary must be executable.
if ($interpreter) {
if (!Filesystem::binaryExists($interpreter)) {
throw new ArcanistMissingLinterException(
pht(
'Unable to locate interpreter "%s" to run linter %s. You may need '.
'to install the interpreter, or adjust your linter configuration.',
$interpreter,
get_class($this)));
}
if (!Filesystem::pathExists($binary)) {
throw new ArcanistMissingLinterException(
sprintf(
"%s\n%s",
pht(
'Unable to locate script "%s" to run linter %s. You may need '.
'to install the script, or adjust your linter configuration.',
$binary,
get_class($this)),
pht(
'TO INSTALL: %s',
$this->getInstallInstructions())));
}
} else {
if (!Filesystem::binaryExists($binary)) {
throw new ArcanistMissingLinterException(
sprintf(
"%s\n%s",
pht(
'Unable to locate binary "%s" to run linter %s. You may need '.
'to install the binary, or adjust your linter configuration.',
$binary,
get_class($this)),
pht(
'TO INSTALL: %s',
$this->getInstallInstructions())));
}
}
}
/**
* Get the composed executable command, including the interpreter and binary
* but without flags or paths. This can be used to execute `--version`
* commands.
*
* @return string Command to execute the raw linter.
* @task exec
*/
final protected function getExecutableCommand() {
$this->checkBinaryConfiguration();
$interpreter = null;
if ($this->shouldUseInterpreter()) {
$interpreter = $this->getInterpreter();
}
$binary = $this->getBinary();
if ($interpreter) {
$bin = csprintf('%s %s', $interpreter, $binary);
} else {
$bin = csprintf('%s', $binary);
}
return $bin;
}
/**
* Get the composed flags for the executable, including both mandatory and
* configured flags.
*
* @return list<string> Composed flags.
* @task exec
*/
final protected function getCommandFlags() {
$mandatory_flags = $this->getMandatoryFlags();
if (!is_array($mandatory_flags)) {
phutil_deprecated(
'String support for flags.', 'You should use list<string> instead.');
$mandatory_flags = (array) $mandatory_flags;
}
$flags = nonempty($this->flags, $this->getDefaultFlags());
if (!is_array($flags)) {
phutil_deprecated(
'String support for flags.', 'You should use list<string> instead.');
$flags = (array) $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());
}
}
/**
* Prepare the path to be added to the command string.
*
* This method is expected to return an already escaped string.
*
* @param string Path to the file being linted
* @return string The command-ready file argument
*/
protected function getPathArgumentForLinterFuture($path) {
return csprintf('%s', $path);
}
final protected function buildFutures(array $paths) {
$executable = $this->getExecutableCommand();
$bin = csprintf('%C %Ls', $executable, $this->getCommandFlags());
$futures = array();
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);
$path_argument = $this->getPathArgumentForLinterFuture($disk_path);
$future = new ExecFuture('%C %C', $bin, $path_argument);
}
$future->setCWD($this->getEngine()->getWorkingCopy()->getProjectRoot());
$futures[$path] = $future;
}
return $futures;
}
final protected function resolveFuture($path, Future $future) {
list($err, $stdout, $stderr) = $future->resolve();
if ($err && !$this->shouldExpectCommandErrors()) {
$future->resolvex();
}
$messages = $this->parseLinterOutput($path, $err, $stdout, $stderr);
if ($messages === false) {
if ($err) {
$future->resolvex();
} else {
throw new Exception(
sprintf(
"%s\n\nSTDOUT\n%s\n\nSTDERR\n%s",
pht('Linter failed to parse output!'),
$stdout,
$stderr));
}
}
foreach ($messages as $message) {
$this->addLintMessage($message);
}
}
public function getLinterConfigurationOptions() {
$options = array(
'bin' => array(
'type' => 'optional string | list<string>',
'help' => pht(
'Specify a string (or list of strings) identifying the binary '.
'which should be invoked to execute this linter. This overrides '.
'the default binary. If you provide a list of possible binaries, '.
'the first one which exists will be used.'),
),
'flags' => array(
'type' => 'optional list<string>',
'help' => pht(
'Provide a list of additional flags to pass to the linter on the '.
'command line.'),
),
);
if ($this->shouldUseInterpreter()) {
$options['interpreter'] = array(
'type' => 'optional string | list<string>',
'help' => pht(
'Specify a string (or list of strings) identifying the interpreter '.
'which should be used to invoke the linter binary. If you provide '.
'a list of possible interpreters, the first one that exists '.
'will be used.'),
);
}
return $options + parent::getLinterConfigurationOptions();
}
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'interpreter':
$working_copy = $this->getEngine()->getWorkingCopy();
$root = $working_copy->getProjectRoot();
foreach ((array)$value as $path) {
if (Filesystem::binaryExists($path)) {
$this->setInterpreter($path);
return;
}
$path = Filesystem::resolvePath($path, $root);
if (Filesystem::binaryExists($path)) {
$this->setInterpreter($path);
return;
}
}
throw new Exception(
pht('None of the configured interpreters can be located.'));
case 'bin':
$is_script = $this->shouldUseInterpreter();
$working_copy = $this->getEngine()->getWorkingCopy();
$root = $working_copy->getProjectRoot();
foreach ((array)$value as $path) {
if (!$is_script && Filesystem::binaryExists($path)) {
$this->setBinary($path);
return;
}
$path = Filesystem::resolvePath($path, $root);
if ((!$is_script && Filesystem::binaryExists($path)) ||
($is_script && Filesystem::pathExists($path))) {
$this->setBinary($path);
return;
}
}
throw new Exception(
pht('None of the configured binaries can be located.'));
case 'flags':
if (!is_array($value)) {
phutil_deprecated(
'String support for flags.',
'You should use list<string> instead.');
$value = (array) $value;
}
$this->setFlags($value);
return;
}
return parent::setLinterConfigurationValue($key, $value);
}
/**
* Map a configuration lint code to an `arc` lint code. Primarily, this is
* intended for validation, but can also be used to normalize case or
* otherwise be more permissive in accepted inputs.
*
* If the code is not recognized, you should throw an exception.
*
* @param string Code specified in configuration.
* @return string Normalized code to use in severity map.
*/
protected function getLintCodeFromLinterConfigurationKey($code) {
return $code;
}
}
diff --git a/src/lint/linter/ArcanistFlake8Linter.php b/src/lint/linter/ArcanistFlake8Linter.php
index 658a6dd6..6c1c6d6f 100644
--- a/src/lint/linter/ArcanistFlake8Linter.php
+++ b/src/lint/linter/ArcanistFlake8Linter.php
@@ -1,132 +1,128 @@
<?php
/**
* Uses "flake8" to detect various errors in Python code.
* Requires version 1.7.0 or newer of flake8.
*/
final class ArcanistFlake8Linter extends ArcanistExternalLinter {
public function getInfoName() {
return 'Flake8';
}
public function getInfoURI() {
return 'https://pypi.python.org/pypi/flake8';
}
public function getInfoDescription() {
return pht(
'Uses `flake8` to run several linters (PyFlakes, pep8, and a McCabe '.
'complexity checker) on Python source files.');
}
public function getLinterName() {
return 'flake8';
}
public function getLinterConfigurationName() {
return 'flake8';
}
protected function getDefaultFlags() {
return $this->getDeprecatedConfiguration('lint.flake8.options', array());
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.flake8.prefix');
$bin = $this->getDeprecatedConfiguration('lint.flake8.bin', 'flake8');
if ($prefix) {
return $prefix.'/'.$bin;
} else {
return $bin;
}
}
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() {
return pht('Install flake8 using `easy_install flake8`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stdout, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
// stdin:2: W802 undefined name 'foo' # pyflakes
// stdin:3:1: E302 expected 2 blank lines, found 1 # pep8
$regexp = '/^(.*?):(\d+):(?:(\d+):)? (\S+) (.*)$/';
if (!preg_match($regexp, $line, $matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[2]);
if (!empty($matches[3])) {
$message->setChar($matches[3]);
}
$message->setCode($matches[4]);
$message->setName($this->getLinterName().' '.$matches[3]);
$message->setDescription($matches[5]);
$message->setSeverity($this->getLintMessageSeverity($matches[4]));
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
protected function getDefaultMessageSeverity($code) {
if (preg_match('/^C/', $code)) {
// "C": Cyclomatic complexity
return ArcanistLintSeverity::SEVERITY_ADVICE;
} else if (preg_match('/^W/', $code)) {
// "W": PEP8 Warning
return ArcanistLintSeverity::SEVERITY_WARNING;
} else {
// "E": PEP8 Error
// "F": PyFlakes Error
return ArcanistLintSeverity::SEVERITY_ERROR;
}
}
protected function getLintCodeFromLinterConfigurationKey($code) {
if (!preg_match('/^(E|W|C|F)\d+$/', $code)) {
throw new Exception(
pht(
'Unrecognized lint message code "%s". Expected a valid flake8 '.
'lint code like "%s", or "%s", or "%s", or "%s".',
$code,
'E225',
'W291',
'F811',
'C901'));
}
return $code;
}
}
diff --git a/src/lint/linter/ArcanistGoLintLinter.php b/src/lint/linter/ArcanistGoLintLinter.php
index 806bda6d..e886e05c 100644
--- a/src/lint/linter/ArcanistGoLintLinter.php
+++ b/src/lint/linter/ArcanistGoLintLinter.php
@@ -1,60 +1,64 @@
<?php
final class ArcanistGoLintLinter extends ArcanistExternalLinter {
public function getInfoName() {
return 'Golint';
}
public function getInfoURI() {
return 'https://github.com/golang/lint';
}
public function getInfoDescription() {
return pht('Golint is a linter for Go source code.');
}
public function getLinterName() {
return 'GOLINT';
}
public function getLinterConfigurationName() {
return 'golint';
}
public function getDefaultBinary() {
return 'golint';
}
public function getInstallInstructions() {
return pht('Install Golint using `go get github.com/golang/lint/golint`.');
}
+ public function shouldExpectCommandErrors() {
+ return false;
+ }
+
protected function canCustomizeLintSeverities() {
return true;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stdout, false);
$messages = array();
foreach ($lines as $line) {
$matches = explode(':', $line, 4);
if (count($matches) === 4) {
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[1]);
$message->setChar($matches[2]);
$message->setCode($this->getLinterName());
$message->setDescription(ucfirst(trim($matches[3])));
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
$messages[] = $message;
}
}
return $messages;
}
}
diff --git a/src/lint/linter/ArcanistHLintLinter.php b/src/lint/linter/ArcanistHLintLinter.php
index 312110d4..df22c25b 100644
--- a/src/lint/linter/ArcanistHLintLinter.php
+++ b/src/lint/linter/ArcanistHLintLinter.php
@@ -1,111 +1,107 @@
<?php
/**
* Calls `hlint` and parses its results.
*/
final class ArcanistHLintLinter extends ArcanistExternalLinter {
public function getInfoName() {
return 'HLint';
}
public function getInfoURI() {
return 'https://github.com/ndmitchell/hlint';
}
public function getInfoDescription() {
return pht('HLint is a linter for Haskell code.');
}
public function getLinterName() {
return 'HLINT';
}
public function getLinterConfigurationName() {
return 'hlint';
}
public function getDefaultBinary() {
return 'hlint';
}
public function getInstallInstructions() {
return pht('Install hlint with `cabal install hlint`.');
}
public function supportsReadDataFromStdin() {
return true;
}
public function getReadDataFromStdinFilename() {
return '-';
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
protected function getMandatoryFlags() {
return array('--json');
}
public function getVersion() {
list($stdout, $stderr) = execx(
'%C --version', $this->getExecutableCommand());
$matches = null;
if (preg_match('@HLint v(.*),@', $stdout, $matches)) {
return $matches[1];
}
return null;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$json = phutil_json_decode($stdout);
$messages = array();
foreach ($json as $fix) {
if ($fix === null) {
return;
}
$message = new ArcanistLintMessage();
$message->setCode($this->getLinterName());
$message->setPath($path);
$message->setLine($fix['startLine']);
$message->setChar($fix['startColumn']);
$message->setName($fix['hint']);
$message->setOriginalText($fix['from']);
$message->setReplacementText($fix['to']);
/* Some improvements may slightly change semantics, so attach
all necessary notes too. */
$notes = '';
foreach ($fix['note'] as $note) {
$notes .= ' **NOTE**: '.trim($note, '"').'.';
}
$message->setDescription(
pht(
'In module `%s`, declaration `%s`.%s',
$fix['module'], $fix['decl'], $notes));
switch ($fix['severity']) {
case 'Error':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
case 'Warning':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
break;
default:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
break;
}
$messages[] = $message;
}
return $messages;
}
}
diff --git a/src/lint/linter/ArcanistJSHintLinter.php b/src/lint/linter/ArcanistJSHintLinter.php
index ea18e771..47483d4c 100644
--- a/src/lint/linter/ArcanistJSHintLinter.php
+++ b/src/lint/linter/ArcanistJSHintLinter.php
@@ -1,188 +1,184 @@
<?php
/**
* Uses JSHint to detect errors and potential problems in JavaScript code.
*/
final class ArcanistJSHintLinter extends ArcanistExternalLinter {
private $jshintignore;
private $jshintrc;
public function getInfoName() {
return 'JSHint';
}
public function getInfoURI() {
return 'http://www.jshint.com';
}
public function getInfoDescription() {
return pht('Use `jshint` to detect issues with JavaScript source files.');
}
public function getLinterName() {
return 'JSHint';
}
public function getLinterConfigurationName() {
return 'jshint';
}
protected function getDefaultMessageSeverity($code) {
if (preg_match('/^W/', $code)) {
return ArcanistLintSeverity::SEVERITY_WARNING;
} else if (preg_match('/^E043$/', $code)) {
// TODO: If JSHint encounters a large number of errors, it will quit
// prematurely and add an additional "Too Many Errors" error. Ideally, we
// should be able to pass some sort of `--force` option to `jshint`.
//
// See https://github.com/jshint/jshint/issues/180
return ArcanistLintSeverity::SEVERITY_DISABLED;
} else {
return ArcanistLintSeverity::SEVERITY_ERROR;
}
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.jshint.prefix');
$bin = $this->getDeprecatedConfiguration('lint.jshint.bin', 'jshint');
if ($prefix) {
return $prefix.'/'.$bin;
} else {
return $bin;
}
}
public function getVersion() {
// NOTE: `jshint --version` emits version information on stderr, not stdout.
list($stdout, $stderr) = execx(
'%C --version',
$this->getExecutableCommand());
$matches = array();
$regex = '/^jshint v(?P<version>\d+\.\d+\.\d+)$/';
if (preg_match($regex, $stderr, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install JSHint using `npm install -g jshint`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return true;
}
public function getReadDataFromStdinFilename() {
return '-';
}
protected function getMandatoryFlags() {
$options = array();
$options[] = '--reporter='.dirname(realpath(__FILE__)).'/reporter.js';
if ($this->jshintrc) {
$options[] = '--config='.$this->jshintrc;
}
if ($this->jshintignore) {
$options[] = '--exclude-path='.$this->jshintignore;
}
return $options;
}
public function getLinterConfigurationOptions() {
$options = array(
'jshint.jshintignore' => array(
'type' => 'optional string',
'help' => pht('Pass in a custom jshintignore file path.'),
),
'jshint.jshintrc' => array(
'type' => 'optional string',
'help' => pht('Custom configuration file.'),
),
);
return $options + parent::getLinterConfigurationOptions();
}
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'jshint.jshintignore':
$this->jshintignore = $value;
return;
case 'jshint.jshintrc':
$this->jshintrc = $value;
return;
}
return parent::setLinterConfigurationValue($key, $value);
}
protected function getDefaultFlags() {
$options = $this->getDeprecatedConfiguration(
'lint.jshint.options',
array());
$config = $this->getDeprecatedConfiguration('lint.jshint.config');
if ($config) {
$options[] = '--config='.$config;
}
return $options;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$errors = json_decode($stdout, true);
if (!is_array($errors)) {
// Something went wrong and we can't decode the output. Exit abnormally.
throw new RuntimeException(
"JSHint returned unparseable output.\n".
"stdout:\n\n{$stdout}".
"stderr:\n\n{$stderr}");
}
$messages = array();
foreach ($errors as $err) {
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine(idx($err, 'line'));
$message->setChar(idx($err, 'col'));
$message->setCode(idx($err, 'code'));
$message->setName('JSHint'.idx($err, 'code'));
$message->setDescription(idx($err, 'reason'));
$message->setSeverity($this->getLintMessageSeverity(idx($err, 'code')));
$messages[] = $message;
}
return $messages;
}
protected function getLintCodeFromLinterConfigurationKey($code) {
if (!preg_match('/^(E|W)\d+$/', $code)) {
throw new Exception(
pht(
'Unrecognized lint message code "%s". Expected a valid JSHint '.
'lint code like "%s" or "%s".',
$code,
'E033',
'W093'));
}
return $code;
}
}
diff --git a/src/lint/linter/ArcanistJSONLintLinter.php b/src/lint/linter/ArcanistJSONLintLinter.php
index 254f8b31..064782f8 100644
--- a/src/lint/linter/ArcanistJSONLintLinter.php
+++ b/src/lint/linter/ArcanistJSONLintLinter.php
@@ -1,97 +1,93 @@
<?php
/**
* A linter for JSON files.
*/
final class ArcanistJSONLintLinter extends ArcanistExternalLinter {
public function getInfoName() {
return 'JSON Lint';
}
public function getInfoURI() {
return 'https://github.com/zaach/jsonlint';
}
public function getInfoDescription() {
return pht('Use `jsonlint` to detect syntax errors in JSON files.');
}
public function getLinterName() {
return 'JSON';
}
public function getLinterConfigurationName() {
return 'jsonlint';
}
public function getDefaultBinary() {
return 'jsonlint';
}
public function getVersion() {
// NOTE: `jsonlint --version` returns a non-zero exit status.
list($err, $stdout) = exec_manual(
'%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() {
return pht('Install jsonlint using `npm install -g jsonlint`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return true;
}
protected function getMandatoryFlags() {
return array(
'--compact',
);
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stderr, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
$match = preg_match(
'/^(?:(?<path>.+): )?'.
'line (?<line>\d+), col (?<column>\d+), '.
'(?<description>.*)$/',
$line,
$matches);
if ($match) {
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches['line']);
$message->setChar($matches['column']);
$message->setCode($this->getLinterName());
$message->setDescription(ucfirst($matches['description']));
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
$messages[] = $message;
}
}
if ($err && !$messages) {
return false;
}
return $messages;
}
}
diff --git a/src/lint/linter/ArcanistJscsLinter.php b/src/lint/linter/ArcanistJscsLinter.php
index 97ec382d..cc037214 100644
--- a/src/lint/linter/ArcanistJscsLinter.php
+++ b/src/lint/linter/ArcanistJscsLinter.php
@@ -1,154 +1,150 @@
<?php
final class ArcanistJscsLinter extends ArcanistExternalLinter {
private $config;
private $preset;
public function getInfoName() {
return 'JSCS';
}
public function getInfoURI() {
return 'https://github.com/mdevils/node-jscs';
}
public function getInfoDescription() {
return pht('Use `jscs` to detect issues with Javascript source files.');
}
public function getLinterName() {
return 'JSCS';
}
public function getLinterConfigurationName() {
return 'jscs';
}
public function getDefaultBinary() {
return 'jscs';
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
$regex = '/^(?P<version>\d+\.\d+\.\d+)$/';
if (preg_match($regex, $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install JSCS using `npm install -g jscs`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
protected function getMandatoryFlags() {
$options = array();
$options[] = '--reporter=checkstyle';
$options[] = '--no-colors';
if ($this->config) {
$options[] = '--config='.$this->config;
}
if ($this->preset) {
$options[] = '--preset='.$this->preset;
}
return $options;
}
public function getLinterConfigurationOptions() {
$options = array(
'jscs.config' => array(
'type' => 'optional string',
'help' => pht('Pass in a custom jscsrc file path.'),
),
'jscs.preset' => array(
'type' => 'optional string',
'help' => pht('Custom preset.'),
),
);
return $options + parent::getLinterConfigurationOptions();
}
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'jscs.config':
$this->config = $value;
return;
case 'jscs.preset':
$this->preset = $value;
return;
}
return parent::setLinterConfigurationValue($key, $value);
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$report_dom = new DOMDocument();
$ok = @$report_dom->loadXML($stdout);
if (!$ok) {
return false;
}
$messages = array();
foreach ($report_dom->getElementsByTagName('file') as $file) {
foreach ($file->getElementsByTagName('error') as $error) {
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($error->getAttribute('line'));
$message->setChar($error->getAttribute('column'));
$message->setCode('JSCS');
$message->setDescription($error->getAttribute('message'));
switch ($error->getAttribute('severity')) {
case 'error':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
case 'warning':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
break;
default:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
break;
}
$messages[] = $message;
}
}
if ($err && !$messages) {
return false;
}
return $messages;
}
protected function getLintCodeFromLinterConfigurationKey($code) {
// NOTE: We can't figure out which rule generated each message, so we
// can not customize severities.
//
// See https://github.com/mdevils/node-jscs/issues/224
throw new Exception(
pht(
"JSCS does not currently support custom severity levels, because ".
"rules can't be identified from messages in output."));
}
}
diff --git a/src/lint/linter/ArcanistLesscLinter.php b/src/lint/linter/ArcanistLesscLinter.php
index 00a40436..f225bb35 100644
--- a/src/lint/linter/ArcanistLesscLinter.php
+++ b/src/lint/linter/ArcanistLesscLinter.php
@@ -1,199 +1,195 @@
<?php
/**
* A linter for LESSCSS files.
*
* This linter uses [[https://github.com/less/less.js | lessc]] to detect
* errors and potential problems in [[http://lesscss.org/ | LESS]] code.
*/
final class ArcanistLesscLinter extends ArcanistExternalLinter {
const LINT_RUNTIME_ERROR = 1;
const LINT_ARGUMENT_ERROR = 2;
const LINT_FILE_ERROR = 3;
const LINT_NAME_ERROR = 4;
const LINT_OPERATION_ERROR = 5;
const LINT_PARSE_ERROR = 6;
const LINT_SYNTAX_ERROR = 7;
private $strictMath = false;
private $strictUnits = false;
public function getInfoName() {
return pht('Less');
}
public function getInfoURI() {
return 'https://lesscss.org/';
}
public function getInfoDescription() {
return pht(
'Use the `--lint` mode provided by `lessc` to detect errors in Less '.
'source files.');
}
public function getLinterName() {
return 'LESSC';
}
public function getLinterConfigurationName() {
return 'lessc';
}
public function getLinterConfigurationOptions() {
return parent::getLinterConfigurationOptions() + array(
'lessc.strict-math' => array(
'type' => 'optional bool',
'help' => pht(
'Enable strict math, which only processes mathematical expressions '.
'inside extraneous parentheses.'),
),
'lessc.strict-units' => array(
'type' => 'optional bool',
'help' => pht('Enable strict handling of units in expressions.'),
),
);
}
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'lessc.strict-math':
$this->strictMath = $value;
return;
case 'lessc.strict-units':
$this->strictUnits = $value;
return;
}
return parent::setLinterConfigurationValue($key, $value);
}
public function getLintNameMap() {
return array(
self::LINT_RUNTIME_ERROR => pht('Runtime Error'),
self::LINT_ARGUMENT_ERROR => pht('Argument Error'),
self::LINT_FILE_ERROR => pht('File Error'),
self::LINT_NAME_ERROR => pht('Name Error'),
self::LINT_OPERATION_ERROR => pht('Operation Error'),
self::LINT_PARSE_ERROR => pht('Parse Error'),
self::LINT_SYNTAX_ERROR => pht('Syntax Error'),
);
}
public function getDefaultBinary() {
return 'lessc';
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
$regex = '/^lessc (?P<version>\d+\.\d+\.\d+)\b/';
if (preg_match($regex, $stdout, $matches)) {
$version = $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht('Install lessc using `npm install -g less`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
// Technically `lessc` can read data from standard input however, when doing
// so, relative imports cannot be resolved. Therefore, this functionality is
// disabled.
return false;
}
public function getReadDataFromStdinFilename() {
return '-';
}
protected function getMandatoryFlags() {
return array(
'--lint',
'--no-color',
'--strict-math='.($this->strictMath ? 'on' : 'off'),
'--strict-units='.($this->strictUnits ? 'on' : 'off'),
);
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stderr, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
$match = preg_match(
'/^(?P<name>\w+): (?P<description>.+) '.
'in (?P<path>.+|-) '.
'on line (?P<line>\d+), column (?P<column>\d+):$/',
$line,
$matches);
if ($match) {
switch ($matches['name']) {
case 'RuntimeError':
$code = self::LINT_RUNTIME_ERROR;
break;
case 'ArgumentError':
$code = self::LINT_ARGUMENT_ERROR;
break;
case 'FileError':
$code = self::LINT_FILE_ERROR;
break;
case 'NameError':
$code = self::LINT_NAME_ERROR;
break;
case 'OperationError':
$code = self::LINT_OPERATION_ERROR;
break;
case 'ParseError':
$code = self::LINT_PARSE_ERROR;
break;
case 'SyntaxError':
$code = self::LINT_SYNTAX_ERROR;
break;
default:
throw new RuntimeException(pht(
'Unrecognized lint message code "%s".',
$code));
}
$code = $this->getLintCodeFromLinterConfigurationKey($matches['name']);
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches['line']);
$message->setChar($matches['column']);
$message->setCode($this->getLintMessageFullCode($code));
$message->setSeverity($this->getLintMessageSeverity($code));
$message->setName($this->getLintMessageName($code));
$message->setDescription(ucfirst($matches['description']));
$messages[] = $message;
}
}
if ($err && !$messages) {
return false;
}
return $messages;
}
}
diff --git a/src/lint/linter/ArcanistPEP8Linter.php b/src/lint/linter/ArcanistPEP8Linter.php
index 51608277..82ab607f 100644
--- a/src/lint/linter/ArcanistPEP8Linter.php
+++ b/src/lint/linter/ArcanistPEP8Linter.php
@@ -1,130 +1,126 @@
<?php
/**
* Uses "pep8.py" to enforce PEP8 rules for Python.
*/
final class ArcanistPEP8Linter extends ArcanistExternalLinter {
public function getInfoName() {
return 'pep8';
}
public function getInfoURI() {
return 'https://pypi.python.org/pypi/pep8';
}
public function getInfoDescription() {
return pht(
'pep8 is a tool to check your Python code against some of the '.
'style conventions in PEP 8.');
}
public function getLinterName() {
return 'PEP8';
}
public function getLinterConfigurationName() {
return 'pep8';
}
protected function getDefaultFlags() {
return $this->getDeprecatedConfiguration('lint.pep8.options', array());
}
public function shouldUseInterpreter() {
return ($this->getDefaultBinary() !== 'pep8');
}
public function getDefaultInterpreter() {
return 'python2.6';
}
public function getDefaultBinary() {
if (Filesystem::binaryExists('pep8')) {
return 'pep8';
}
$old_prefix = $this->getDeprecatedConfiguration('lint.pep8.prefix');
$old_bin = $this->getDeprecatedConfiguration('lint.pep8.bin');
if ($old_prefix || $old_bin) {
$old_bin = nonempty($old_bin, 'pep8');
return $old_prefix.'/'.$old_bin;
}
$arc_root = dirname(phutil_get_library_root('arcanist'));
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() {
return pht('Install PEP8 using `easy_install pep8`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stdout, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
if (!preg_match('/^(.*?):(\d+):(\d+): (\S+) (.*)$/', $line, $matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[2]);
$message->setChar($matches[3]);
$message->setCode($matches[4]);
$message->setName('PEP8 '.$matches[4]);
$message->setDescription($matches[5]);
$message->setSeverity($this->getLintMessageSeverity($matches[4]));
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
protected function getDefaultMessageSeverity($code) {
if (preg_match('/^W/', $code)) {
return ArcanistLintSeverity::SEVERITY_WARNING;
} else {
return ArcanistLintSeverity::SEVERITY_ERROR;
}
}
protected function getLintCodeFromLinterConfigurationKey($code) {
if (!preg_match('/^(E|W)\d+$/', $code)) {
throw new Exception(
pht(
'Unrecognized lint message code "%s". Expected a valid PEP8 '.
'lint code like "%s" or "%s".',
$code,
'E101',
'W291'));
}
return $code;
}
}
diff --git a/src/lint/linter/ArcanistPhpLinter.php b/src/lint/linter/ArcanistPhpLinter.php
index 438cfe6e..328e87ce 100644
--- a/src/lint/linter/ArcanistPhpLinter.php
+++ b/src/lint/linter/ArcanistPhpLinter.php
@@ -1,109 +1,105 @@
<?php
/**
* Uses "php -l" to detect syntax errors in PHP code.
*/
final class ArcanistPhpLinter extends ArcanistExternalLinter {
const LINT_PARSE_ERROR = 1;
const LINT_FATAL_ERROR = 2;
public function getInfoName() {
return 'php -l';
}
public function getInfoURI() {
return 'http://php.net/';
}
public function getInfoDescription() {
return pht('Checks for syntax errors in PHP files.');
}
public function getLinterName() {
return 'PHP';
}
public function getLinterConfigurationName() {
return 'php';
}
public function getLintNameMap() {
return array(
self::LINT_PARSE_ERROR => pht('Parse Error'),
self::LINT_FATAL_ERROR => pht('Fatal Error'),
);
}
protected function getMandatoryFlags() {
return array('-l');
}
public function getInstallInstructions() {
return pht('Install PHP.');
}
public function getDefaultBinary() {
return 'php';
}
public function getVersion() {
list($stdout) = execx(
'%C --run %s',
$this->getExecutableCommand(),
'echo phpversion();');
return $stdout;
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return false;
}
protected function canCustomizeLintSeverities() {
return false;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
// Older versions of PHP had both on stdout, newer ones split it.
// Combine stdout and stderr for consistency.
$stdout = $stderr."\n".$stdout;
$matches = array();
$regex = '/^(PHP )?(?<type>.+) error: +(?<error>.+) in (?<file>.+) '.
'on line (?<line>\d+)$/m';
if (preg_match($regex, $stdout, $matches)) {
$code = $this->getLintCodeFromLinterConfigurationKey($matches['type']);
$message = id(new ArcanistLintMessage())
->setPath($path)
->setLine($matches['line'])
->setCode($this->getLinterName().$code)
->setName($this->getLintMessageName($code))
->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR)
->setDescription($matches['error']);
// `php -l` only returns the first error.
return array($message);
}
return array();
}
protected function getLintCodeFromLinterConfigurationKey($code) {
switch (phutil_utf8_strtolower($code)) {
case 'parse':
return self::LINT_PARSE_ERROR;
case 'fatal':
return self::LINT_FATAL_ERROR;
default:
throw new Exception(pht('Unrecognized lint message code "%s"', $code));
}
}
}
diff --git a/src/lint/linter/ArcanistPhpcsLinter.php b/src/lint/linter/ArcanistPhpcsLinter.php
index e9aefe45..220719ed 100644
--- a/src/lint/linter/ArcanistPhpcsLinter.php
+++ b/src/lint/linter/ArcanistPhpcsLinter.php
@@ -1,140 +1,136 @@
<?php
/**
* Uses "PHP_CodeSniffer" to detect checkstyle errors in PHP code.
*/
final class ArcanistPhpcsLinter extends ArcanistExternalLinter {
private $reports;
public function getInfoName() {
return 'PHP_CodeSniffer';
}
public function getInfoURI() {
return 'http://pear.php.net/package/PHP_CodeSniffer/';
}
public function getInfoDescription() {
return pht(
'PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and '.
'detects violations of a defined set of coding standards.');
}
public function getLinterName() {
return 'PHPCS';
}
public function getLinterConfigurationName() {
return 'phpcs';
}
public function getMandatoryFlags() {
return array('--report=xml');
}
public function getInstallInstructions() {
return pht('Install PHPCS with `pear install PHP_CodeSniffer`.');
}
protected function getDefaultFlags() {
$options = $this->getDeprecatedConfiguration('lint.phpcs.options', array());
$standard = $this->getDeprecatedConfiguration('lint.phpcs.standard');
if (!empty($standard)) {
if (is_array($options)) {
$options[] = '--standard='.$standard;
} else {
$options .= ' --standard='.$standard;
}
}
return $options;
}
public function getDefaultBinary() {
return $this->getDeprecatedConfiguration('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() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return true;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
// NOTE: Some version of PHPCS after 1.4.6 stopped printing a valid, empty
// XML document to stdout in the case of no errors. If PHPCS exits with
// error 0, just ignore output.
if (!$err) {
return array();
}
$report_dom = new DOMDocument();
$ok = @$report_dom->loadXML($stdout);
if (!$ok) {
return false;
}
$files = $report_dom->getElementsByTagName('file');
$messages = array();
foreach ($files as $file) {
foreach ($file->childNodes as $child) {
if (!($child instanceof DOMElement)) {
continue;
}
if ($child->tagName == 'error') {
$prefix = 'E';
} else {
$prefix = 'W';
}
$code = 'PHPCS.'.$prefix.'.'.$child->getAttribute('source');
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($child->getAttribute('line'));
$message->setChar($child->getAttribute('column'));
$message->setCode($code);
$message->setDescription($child->nodeValue);
$message->setSeverity($this->getLintMessageSeverity($code));
$messages[] = $message;
}
}
return $messages;
}
protected function getDefaultMessageSeverity($code) {
if (preg_match('/^PHPCS\\.W\\./', $code)) {
return ArcanistLintSeverity::SEVERITY_WARNING;
} else {
return ArcanistLintSeverity::SEVERITY_ERROR;
}
}
protected function getLintCodeFromLinterConfigurationKey($code) {
if (!preg_match('/^PHPCS\\.(E|W)\\./', $code)) {
throw new Exception(
"Invalid severity code '{$code}', should begin with 'PHPCS.'.");
}
return $code;
}
}
diff --git a/src/lint/linter/ArcanistPuppetLintLinter.php b/src/lint/linter/ArcanistPuppetLintLinter.php
index 2cc39a40..ea5b66cf 100644
--- a/src/lint/linter/ArcanistPuppetLintLinter.php
+++ b/src/lint/linter/ArcanistPuppetLintLinter.php
@@ -1,147 +1,143 @@
<?php
/**
* A linter for Puppet files.
*/
final class ArcanistPuppetLintLinter extends ArcanistExternalLinter {
private $config;
public function getInfoName() {
return 'puppet-lint';
}
public function getInfoURI() {
return 'http://puppet-lint.com/';
}
public function getInfoDescription() {
return pht(
'Use `%s` to check that your Puppet manifests '.
'conform to the style guide.',
'puppet-lint');
}
public function getLinterName() {
return 'PUPPETLINT';
}
public function getLinterConfigurationName() {
return 'puppet-lint';
}
public function getDefaultBinary() {
return 'puppet-lint';
}
public function getVersion() {
list($stdout) = execx('%C --version', $this->getExecutableCommand());
$matches = array();
$regex = '/^puppet-lint (?P<version>\d+\.\d+\.\d+)$/';
if (preg_match($regex, $stdout, $matches)) {
return $matches['version'];
} else {
return false;
}
}
public function getInstallInstructions() {
return pht(
'Install puppet-lint using `%s`.',
'gem install puppet-lint');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
protected function getMandatoryFlags() {
return array(
'--error-level=all',
sprintf('--log-format=%s', implode('|', array(
'%{linenumber}',
'%{column}',
'%{kind}',
'%{check}',
'%{message}',
))),
);
}
public function getLinterConfigurationOptions() {
$options = array(
'puppet-lint.config' => array(
'type' => 'optional string',
'help' => pht('Pass in a custom configuration file path.'),
),
);
return $options + parent::getLinterConfigurationOptions();
}
public function setLinterConfigurationValue($key, $value) {
switch ($key) {
case 'puppet-lint.config':
$this->config = $value;
return;
default:
return parent::setLinterConfigurationValue($key, $value);
}
}
protected function getDefaultFlags() {
$options = array();
if ($this->config) {
$options[] = '--config='.$this->config;
}
return $options;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stdout, false);
$messages = array();
foreach ($lines as $line) {
$matches = explode('|', $line, 5);
if (count($matches) < 5) {
continue;
}
$message = id(new ArcanistLintMessage())
->setPath($path)
->setLine($matches[0])
->setChar($matches[1])
->setCode($this->getLinterName())
->setName(ucwords(str_replace('_', ' ', $matches[3])))
->setDescription(ucfirst($matches[4]));
switch ($matches[2]) {
case 'warning':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
break;
case 'error':
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
default:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
break;
}
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
}
diff --git a/src/lint/linter/ArcanistPyFlakesLinter.php b/src/lint/linter/ArcanistPyFlakesLinter.php
index fe047c50..4180fc90 100644
--- a/src/lint/linter/ArcanistPyFlakesLinter.php
+++ b/src/lint/linter/ArcanistPyFlakesLinter.php
@@ -1,106 +1,102 @@
<?php
/**
* Uses "PyFlakes" to detect various errors in Python code.
*/
final class ArcanistPyFlakesLinter extends ArcanistExternalLinter {
public function getInfoURI() {
return 'https://pypi.python.org/pypi/pyflakes';
}
public function getInfoName() {
return pht('PyFlakes');
}
public function getInfoDescription() {
return pht(
'PyFlakes is a simple program which checks Python source files for '.
'errors.');
}
public function getLinterName() {
return 'PYFLAKES';
}
public function getLinterConfigurationName() {
return 'pyflakes';
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.pyflakes.prefix');
$bin = $this->getDeprecatedConfiguration('lint.pyflakes.bin', 'pyflakes');
if ($prefix) {
return $prefix.'/'.$bin;
} else {
return $bin;
}
}
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() {
return pht('Install pyflakes with `pip install pyflakes`.');
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
public function supportsReadDataFromStdin() {
return true;
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stdout, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
if (!preg_match('/^(.*?):(\d+): (.*)$/', $line, $matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$severity = ArcanistLintSeverity::SEVERITY_WARNING;
$description = $matches[3];
$error_regexp = '/(^undefined|^duplicate|before assignment$)/';
if (preg_match($error_regexp, $description)) {
$severity = ArcanistLintSeverity::SEVERITY_ERROR;
}
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[2]);
$message->setCode($this->getLinterName());
$message->setDescription($description);
$message->setSeverity($severity);
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
protected function canCustomizeLintSeverities() {
return false;
}
}
diff --git a/src/lint/linter/ArcanistRubyLinter.php b/src/lint/linter/ArcanistRubyLinter.php
index 27847220..bdf3ab82 100644
--- a/src/lint/linter/ArcanistRubyLinter.php
+++ b/src/lint/linter/ArcanistRubyLinter.php
@@ -1,102 +1,98 @@
<?php
/**
* Uses `ruby` to detect various errors in Ruby code.
*/
final class ArcanistRubyLinter extends ArcanistExternalLinter {
public function getInfoURI() {
return 'https://www.ruby-lang.org/';
}
public function getInfoName() {
return pht('Ruby');
}
public function getInfoDescription() {
return pht('Use `ruby` to check for syntax errors in Ruby source files.');
}
public function getLinterName() {
return 'RUBY';
}
public function getLinterConfigurationName() {
return 'ruby';
}
public function getDefaultBinary() {
$prefix = $this->getDeprecatedConfiguration('lint.ruby.prefix');
if ($prefix !== null) {
$ruby_bin = $prefix.'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() {
return pht('Install `ruby` from <http://www.ruby-lang.org/>.');
}
public function supportsReadDataFromStdin() {
return true;
}
- public function shouldExpectCommandErrors() {
- return true;
- }
-
protected function getMandatoryFlags() {
// -w: turn on warnings
// -c: check syntax
return array('-w', '-c');
}
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
$lines = phutil_split_lines($stderr, false);
$messages = array();
foreach ($lines as $line) {
$matches = null;
if (!preg_match('/(.*?):(\d+): (.*?)$/', $line, $matches)) {
continue;
}
foreach ($matches as $key => $match) {
$matches[$key] = trim($match);
}
$code = head(explode(',', $matches[3]));
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($matches[2]);
$message->setCode($this->getLinterName());
$message->setName(pht('Syntax Error'));
$message->setDescription($matches[3]);
$message->setSeverity($this->getLintMessageSeverity($code));
$messages[] = $message;
}
if ($err && !$messages) {
return false;
}
return $messages;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Jan 19 2025, 12:06 (4 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124386
Default Alt Text
(77 KB)

Event Timeline