mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-01-09 22:31:02 +01:00
eb8b414cc7
Summary: We always generate all messages and then filter them out based on minimum severity. It's lots of useless work, especially in commit hook mode where we are interested only in errors. Test Plan: $ arc lint --cache 0 --severity error ArcanistXHPASTLinter.php 0.406 s before, 0.074 after Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4963
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Describes the severity of an @{class:ArcanistLintMessage}.
|
|
*
|
|
* @group lint
|
|
*/
|
|
final class ArcanistLintSeverity {
|
|
|
|
const SEVERITY_ADVICE = 'advice';
|
|
const SEVERITY_AUTOFIX = 'autofix';
|
|
const SEVERITY_WARNING = 'warning';
|
|
const SEVERITY_ERROR = 'error';
|
|
const SEVERITY_DISABLED = 'disabled';
|
|
|
|
public static function getLintSeverities() {
|
|
return array(
|
|
self::SEVERITY_ADVICE => 'Advice',
|
|
self::SEVERITY_AUTOFIX => 'Auto-Fix',
|
|
self::SEVERITY_WARNING => 'Warning',
|
|
self::SEVERITY_ERROR => 'Error',
|
|
self::SEVERITY_DISABLED => 'Disabled',
|
|
);
|
|
}
|
|
|
|
public static function getStringForSeverity($severity_code) {
|
|
$map = self::getLintSeverities();
|
|
|
|
if (!array_key_exists($severity_code, $map)) {
|
|
throw new Exception("Unknown lint severity '{$severity_code}'!");
|
|
}
|
|
|
|
return $map[$severity_code];
|
|
}
|
|
|
|
public static function isAtLeastAsSevere($message_sev, $level) {
|
|
|
|
static $map = array(
|
|
self::SEVERITY_DISABLED => 10,
|
|
self::SEVERITY_ADVICE => 20,
|
|
self::SEVERITY_AUTOFIX => 25,
|
|
self::SEVERITY_WARNING => 30,
|
|
self::SEVERITY_ERROR => 40,
|
|
);
|
|
|
|
if (empty($map[$message_sev])) {
|
|
return true;
|
|
}
|
|
|
|
return $map[$message_sev] >= idx($map, $level, 0);
|
|
}
|
|
|
|
|
|
}
|