1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-10 14:51:05 +01:00
phorge-arcanist/src/lint/linter/ArcanistXMLLinter.php
epriestley e13f5839d4 Add 'arc linters' to list available linters and status
Summary: Ref T2039. We're starting to get kind of a lot of linters; provide `arc linters` to help users review and understand them and construct `.arclint` files.

Test Plan: {F152205}

Reviewers: btrahan, joshuaspence

Reviewed By: btrahan, joshuaspence

Subscribers: epriestley

Maniphest Tasks: T2039

Differential Revision: https://secure.phabricator.com/D9041
2014-05-11 13:42:56 -07:00

77 lines
2 KiB
PHP

<?php
/**
* A linter which uses [[http://php.net/simplexml | SimpleXML]] to detect
* errors and potential problems in XML files.
*/
final class ArcanistXMLLinter extends ArcanistLinter {
public function getInfoName() {
return pht('SimpleXML Linter');
}
public function getInfoDescription() {
return pht('Uses SimpleXML to detect formatting errors in XML files.');
}
public function getLinterName() {
return 'XML';
}
public function getLinterConfigurationName() {
return 'xml';
}
public function canRun() {
return extension_loaded('libxml') && extension_loaded('simplexml');
}
public function getCacheVersion() {
return LIBXML_VERSION;
}
public function getLintMessageName($code) {
return 'LibXML Error';
}
public function lintPath($path) {
libxml_use_internal_errors(true);
libxml_clear_errors();
if (simplexml_load_string($this->getData($path))) {
// XML appears to be valid.
return;
}
foreach (libxml_get_errors() as $error) {
$message = new ArcanistLintMessage();
$message->setPath($path);
$message->setLine($error->line);
$message->setChar($error->column ? $error->column : null);
$message->setCode($this->getLintMessageFullCode($error->code));
$message->setName($this->getLintMessageName($error->code));
$message->setDescription(trim($error->message));
switch ($error->level) {
case LIBXML_ERR_NONE:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_DISABLED);
break;
case LIBXML_ERR_WARNING:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
break;
case LIBXML_ERR_ERROR:
case LIBXML_ERR_FATAL:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ERROR);
break;
default:
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
break;
}
$this->addLintMessage($message);
}
}
}