mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-03-20 16:20:08 +01:00
Don't run disabled lint rules
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
This commit is contained in:
parent
39704f1e49
commit
eb8b414cc7
4 changed files with 63 additions and 34 deletions
|
@ -33,9 +33,7 @@ final class ArcanistLintSeverity {
|
||||||
return $map[$severity_code];
|
return $map[$severity_code];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isAtLeastAsSevere(
|
public static function isAtLeastAsSevere($message_sev, $level) {
|
||||||
ArcanistLintMessage $message,
|
|
||||||
$level) {
|
|
||||||
|
|
||||||
static $map = array(
|
static $map = array(
|
||||||
self::SEVERITY_DISABLED => 10,
|
self::SEVERITY_DISABLED => 10,
|
||||||
|
@ -45,7 +43,6 @@ final class ArcanistLintSeverity {
|
||||||
self::SEVERITY_ERROR => 40,
|
self::SEVERITY_ERROR => 40,
|
||||||
);
|
);
|
||||||
|
|
||||||
$message_sev = $message->getSeverity();
|
|
||||||
if (empty($map[$message_sev])) {
|
if (empty($map[$message_sev])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,9 +247,8 @@ abstract class ArcanistLintEngine {
|
||||||
$this->didRunLinters($linters);
|
$this->didRunLinters($linters);
|
||||||
|
|
||||||
foreach ($linters as $linter) {
|
foreach ($linters as $linter) {
|
||||||
$minimum = $this->minimumSeverity;
|
|
||||||
foreach ($linter->getLintMessages() as $message) {
|
foreach ($linter->getLintMessages() as $message) {
|
||||||
if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
|
if (!$this->isSeverityEnabled($message->getSeverity())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!$this->isRelevantMessage($message)) {
|
if (!$this->isRelevantMessage($message)) {
|
||||||
|
@ -307,6 +306,11 @@ abstract class ArcanistLintEngine {
|
||||||
return $this->results;
|
return $this->results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isSeverityEnabled($severity) {
|
||||||
|
$minimum = $this->minimumSeverity;
|
||||||
|
return ArcanistLintSeverity::isAtLeastAsSevere($severity, $minimum);
|
||||||
|
}
|
||||||
|
|
||||||
private function shouldUseCache($cache_granularity, $repository_version) {
|
private function shouldUseCache($cache_granularity, $repository_version) {
|
||||||
switch ($cache_granularity) {
|
switch ($cache_granularity) {
|
||||||
case ArcanistLinter::GRANULARITY_FILE:
|
case ArcanistLinter::GRANULARITY_FILE:
|
||||||
|
|
|
@ -226,6 +226,11 @@ abstract class ArcanistLinter {
|
||||||
// This is a hook.
|
// This is a hook.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isCodeEnabled($code) {
|
||||||
|
$severity = $this->getLintMessageSeverity($code);
|
||||||
|
return $this->getEngine()->isSeverityEnabled($severity);
|
||||||
|
}
|
||||||
|
|
||||||
public function getLintSeverityMap() {
|
public function getLintSeverityMap() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,34 +175,57 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
|
||||||
|
|
||||||
$root = $this->trees[$path]->getRootNode();
|
$root = $this->trees[$path]->getRootNode();
|
||||||
|
|
||||||
$this->lintUseOfThisInStaticMethods($root);
|
$method_codes = array(
|
||||||
$this->lintDynamicDefines($root);
|
'lintStrstrUsedForCheck' => self::LINT_SLOWNESS,
|
||||||
$this->lintSurpriseConstructors($root);
|
'lintStrposUsedForStart' => self::LINT_SLOWNESS,
|
||||||
$this->lintPHPTagUse($root);
|
'lintPHP53Features' => self::LINT_PHP_53_FEATURES,
|
||||||
$this->lintVariableVariables($root);
|
'lintPHP54Features' => self::LINT_PHP_54_FEATURES,
|
||||||
$this->lintTODOComments($root);
|
'lintImplicitFallthrough' => self::LINT_IMPLICIT_FALLTHROUGH,
|
||||||
$this->lintExitExpressions($root);
|
'lintBraceFormatting' => self::LINT_BRACE_FORMATTING,
|
||||||
$this->lintSpaceAroundBinaryOperators($root);
|
'lintTautologicalExpressions' => self::LINT_TAUTOLOGICAL_EXPRESSION,
|
||||||
$this->lintSpaceAfterControlStatementKeywords($root);
|
'lintCommentSpaces' => self::LINT_COMMENT_SPACING,
|
||||||
$this->lintParenthesesShouldHugExpressions($root);
|
'lintHashComments' => self::LINT_COMMENT_STYLE,
|
||||||
$this->lintNamingConventions($root);
|
'lintReusedIterators' => self::LINT_REUSED_ITERATORS,
|
||||||
$this->lintPregQuote($root);
|
'lintVariableVariables' => self::LINT_VARIABLE_VARIABLE,
|
||||||
$this->lintUndeclaredVariables($root);
|
'lintUndeclaredVariables' => array(
|
||||||
$this->lintArrayIndexWhitespace($root);
|
self::LINT_EXTRACT_USE,
|
||||||
$this->lintCommentSpaces($root);
|
self::LINT_REUSED_AS_ITERATOR,
|
||||||
$this->lintHashComments($root);
|
self::LINT_UNDECLARED_VARIABLE,
|
||||||
$this->lintPrimaryDeclarationFilenameMatch($root);
|
),
|
||||||
$this->lintTautologicalExpressions($root);
|
'lintPHPTagUse' => array(
|
||||||
$this->lintPlusOperatorOnStrings($root);
|
self::LINT_PHP_SHORT_TAG,
|
||||||
$this->lintDuplicateKeysInArray($root);
|
self::LINT_PHP_ECHO_TAG,
|
||||||
$this->lintReusedIterators($root);
|
self::LINT_PHP_OPEN_TAG,
|
||||||
$this->lintBraceFormatting($root);
|
self::LINT_PHP_CLOSE_TAG,
|
||||||
$this->lintRaggedClasstreeEdges($root);
|
),
|
||||||
$this->lintImplicitFallthrough($root);
|
'lintNamingConventions' => self::LINT_NAMING_CONVENTIONS,
|
||||||
$this->lintPHP53Features($root);
|
'lintSurpriseConstructors' => self::LINT_IMPLICIT_CONSTRUCTOR,
|
||||||
$this->lintPHP54Features($root);
|
'lintParenthesesShouldHugExpressions' => self::LINT_PARENTHESES_SPACING,
|
||||||
$this->lintStrposUsedForStart($root);
|
'lintSpaceAfterControlStatementKeywords' =>
|
||||||
$this->lintStrstrUsedForCheck($root);
|
self::LINT_CONTROL_STATEMENT_SPACING,
|
||||||
|
'lintSpaceAroundBinaryOperators' => self::LINT_BINARY_EXPRESSION_SPACING,
|
||||||
|
'lintDynamicDefines' => self::LINT_DYNAMIC_DEFINE,
|
||||||
|
'lintUseOfThisInStaticMethods' => self::LINT_STATIC_THIS,
|
||||||
|
'lintPregQuote' => self::LINT_PREG_QUOTE_MISUSE,
|
||||||
|
'lintExitExpressions' => self::LINT_EXIT_EXPRESSION,
|
||||||
|
'lintArrayIndexWhitespace' => self::LINT_ARRAY_INDEX_SPACING,
|
||||||
|
'lintTODOComments' => self::LINT_TODO_COMMENT,
|
||||||
|
'lintPrimaryDeclarationFilenameMatch' =>
|
||||||
|
self::LINT_CLASS_FILENAME_MISMATCH,
|
||||||
|
'lintPlusOperatorOnStrings' => self::LINT_PLUS_OPERATOR_ON_STRINGS,
|
||||||
|
'lintDuplicateKeysInArray' => self::LINT_DUPLICATE_KEYS_IN_ARRAY,
|
||||||
|
'lintRaggedClasstreeEdges' => self::LINT_RAGGED_CLASSTREE_EDGE,
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($method_codes as $method => $codes) {
|
||||||
|
foreach ((array)$codes as $code) {
|
||||||
|
if ($this->isCodeEnabled($code)) {
|
||||||
|
call_user_func(array($this, $method), $root);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lintStrstrUsedForCheck($root) {
|
public function lintStrstrUsedForCheck($root) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue