]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Don't run disabled lint rules
authorvrana <jakubv@fb.com>
Thu, 14 Feb 2013 23:18:39 +0000 (15:18 -0800)
committervrana <jakubv@fb.com>
Thu, 14 Feb 2013 23:31:10 +0000 (15:31 -0800)
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

src/lint/ArcanistLintSeverity.php
src/lint/engine/ArcanistLintEngine.php
src/lint/linter/ArcanistLinter.php
src/lint/linter/ArcanistXHPASTLinter.php

index 3466cde1c8b5290a555e7be0b57a0d8a006f5e08..05ec37238956a333c905a56114a8c86af8510a05 100644 (file)
@@ -33,9 +33,7 @@ final class ArcanistLintSeverity {
     return $map[$severity_code];
   }
 
-  public static function isAtLeastAsSevere(
-    ArcanistLintMessage $message,
-    $level) {
+  public static function isAtLeastAsSevere($message_sev, $level) {
 
     static $map = array(
       self::SEVERITY_DISABLED => 10,
@@ -45,7 +43,6 @@ final class ArcanistLintSeverity {
       self::SEVERITY_ERROR    => 40,
     );
 
-    $message_sev = $message->getSeverity();
     if (empty($map[$message_sev])) {
       return true;
     }
index 39f995ead545f39c7d8288c47bce337dde4df997..9ea1ddca5b55fff51a88855d86ee0039cf4f66dd 100644 (file)
@@ -247,9 +247,8 @@ abstract class ArcanistLintEngine {
     $this->didRunLinters($linters);
 
     foreach ($linters as $linter) {
-      $minimum = $this->minimumSeverity;
       foreach ($linter->getLintMessages() as $message) {
-        if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) {
+        if (!$this->isSeverityEnabled($message->getSeverity())) {
           continue;
         }
         if (!$this->isRelevantMessage($message)) {
@@ -307,6 +306,11 @@ abstract class ArcanistLintEngine {
     return $this->results;
   }
 
+  public function isSeverityEnabled($severity) {
+    $minimum = $this->minimumSeverity;
+    return ArcanistLintSeverity::isAtLeastAsSevere($severity, $minimum);
+  }
+
   private function shouldUseCache($cache_granularity, $repository_version) {
     switch ($cache_granularity) {
       case ArcanistLinter::GRANULARITY_FILE:
index a910accc1af5d71ad49fca98400f4fc9f97d0ae9..1d5867ab83946096c6c7f81048373c038721de89 100644 (file)
@@ -226,6 +226,11 @@ abstract class ArcanistLinter {
     // This is a hook.
   }
 
+  protected function isCodeEnabled($code) {
+    $severity = $this->getLintMessageSeverity($code);
+    return $this->getEngine()->isSeverityEnabled($severity);
+  }
+
   public function getLintSeverityMap() {
     return array();
   }
index 52b55c74e7193ae46439691d41e0d9a857fcf38e..4f6035ba8e29ee51150c26965567773f683616e7 100644 (file)
@@ -175,34 +175,57 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
 
     $root = $this->trees[$path]->getRootNode();
 
-    $this->lintUseOfThisInStaticMethods($root);
-    $this->lintDynamicDefines($root);
-    $this->lintSurpriseConstructors($root);
-    $this->lintPHPTagUse($root);
-    $this->lintVariableVariables($root);
-    $this->lintTODOComments($root);
-    $this->lintExitExpressions($root);
-    $this->lintSpaceAroundBinaryOperators($root);
-    $this->lintSpaceAfterControlStatementKeywords($root);
-    $this->lintParenthesesShouldHugExpressions($root);
-    $this->lintNamingConventions($root);
-    $this->lintPregQuote($root);
-    $this->lintUndeclaredVariables($root);
-    $this->lintArrayIndexWhitespace($root);
-    $this->lintCommentSpaces($root);
-    $this->lintHashComments($root);
-    $this->lintPrimaryDeclarationFilenameMatch($root);
-    $this->lintTautologicalExpressions($root);
-    $this->lintPlusOperatorOnStrings($root);
-    $this->lintDuplicateKeysInArray($root);
-    $this->lintReusedIterators($root);
-    $this->lintBraceFormatting($root);
-    $this->lintRaggedClasstreeEdges($root);
-    $this->lintImplicitFallthrough($root);
-    $this->lintPHP53Features($root);
-    $this->lintPHP54Features($root);
-    $this->lintStrposUsedForStart($root);
-    $this->lintStrstrUsedForCheck($root);
+    $method_codes = array(
+      'lintStrstrUsedForCheck' => self::LINT_SLOWNESS,
+      'lintStrposUsedForStart' => self::LINT_SLOWNESS,
+      'lintPHP53Features' => self::LINT_PHP_53_FEATURES,
+      'lintPHP54Features' => self::LINT_PHP_54_FEATURES,
+      'lintImplicitFallthrough' => self::LINT_IMPLICIT_FALLTHROUGH,
+      'lintBraceFormatting' => self::LINT_BRACE_FORMATTING,
+      'lintTautologicalExpressions' => self::LINT_TAUTOLOGICAL_EXPRESSION,
+      'lintCommentSpaces' => self::LINT_COMMENT_SPACING,
+      'lintHashComments' => self::LINT_COMMENT_STYLE,
+      'lintReusedIterators' => self::LINT_REUSED_ITERATORS,
+      'lintVariableVariables' => self::LINT_VARIABLE_VARIABLE,
+      'lintUndeclaredVariables' => array(
+        self::LINT_EXTRACT_USE,
+        self::LINT_REUSED_AS_ITERATOR,
+        self::LINT_UNDECLARED_VARIABLE,
+      ),
+      'lintPHPTagUse' => array(
+        self::LINT_PHP_SHORT_TAG,
+        self::LINT_PHP_ECHO_TAG,
+        self::LINT_PHP_OPEN_TAG,
+        self::LINT_PHP_CLOSE_TAG,
+      ),
+      'lintNamingConventions' => self::LINT_NAMING_CONVENTIONS,
+      'lintSurpriseConstructors' => self::LINT_IMPLICIT_CONSTRUCTOR,
+      'lintParenthesesShouldHugExpressions' => self::LINT_PARENTHESES_SPACING,
+      'lintSpaceAfterControlStatementKeywords' =>
+        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) {