]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Require space after `//`
authorvrana <jakubv@fb.com>
Thu, 21 Jun 2012 23:21:04 +0000 (16:21 -0700)
committervrana <jakubv@fb.com>
Tue, 26 Jun 2012 21:12:17 +0000 (14:12 -0700)
Summary:
I use `//~` for marking places which shouldn't be committed.
It also looks ugly.
Maybe it can be just a warning but we provide a patch so error is OK?

Test Plan: New test.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D2824

src/lint/engine/PhutilLintEngine.php
src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/xhpast/hash-comments.lint-test

index 97d9232daf186a84d3e65f0280bdafa6c876456b..39c257800f9e5e7ae059154b280d966f728a2c5c 100644 (file)
@@ -92,6 +92,8 @@ class PhutilLintEngine extends ArcanistLintEngine {
           => ArcanistLintSeverity::SEVERITY_WARNING,
         ArcanistXHPASTLinter::LINT_PHP_53_FEATURES
           => ArcanistLintSeverity::SEVERITY_ERROR,
+        ArcanistXHPASTLinter::LINT_COMMENT_SPACING
+          => ArcanistLintSeverity::SEVERITY_ERROR,
       ));
     $linters[] = $xhpast_linter;
     foreach ($paths as $path) {
index e34a7f68003b65a3f4b0865cc010589d001441be..8e1e1c85f44ad233a7506f74f5de64689e62e647 100644 (file)
@@ -57,6 +57,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
   const LINT_PHP_53_FEATURES           = 31;
   const LINT_REUSED_AS_ITERATOR        = 32;
   const LINT_PHT_WITH_DYNAMIC_STRING   = 33;
+  const LINT_COMMENT_SPACING           = 34;
 
 
   public function getLintNameMap() {
@@ -93,6 +94,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
       self::LINT_PHP_53_FEATURES           => 'Use Of PHP 5.3 Features',
       self::LINT_REUSED_AS_ITERATOR        => 'Variable Reused As Iterator',
       self::LINT_PHT_WITH_DYNAMIC_STRING   => 'Use of pht() on Dynamic String',
+      self::LINT_COMMENT_SPACING           => 'Comment Spaces',
     );
   }
 
@@ -124,6 +126,9 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
       self::LINT_PHT_WITH_DYNAMIC_STRING
         => ArcanistLintSeverity::SEVERITY_WARNING,
 
+      self::LINT_COMMENT_SPACING
+        => ArcanistLintSeverity::SEVERITY_ADVICE,
+
       // This is disabled by default because it implies a very strict policy
       // which isn't necessary in the general case.
       self::LINT_RAGGED_CLASSTREE_EDGE
@@ -194,6 +199,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
     $this->lintPregQuote($root);
     $this->lintUndeclaredVariables($root);
     $this->lintArrayIndexWhitespace($root);
+    $this->lintCommentSpaces($root);
     $this->lintHashComments($root);
     $this->lintPrimaryDeclarationFilenameMatch($root);
     $this->lintTautologicalExpressions($root);
@@ -567,6 +573,24 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
   }
 
 
+  protected function lintCommentSpaces($root) {
+    foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
+      $value = $comment->getValue();
+      if ($value[0] != '#') {
+        $match = null;
+        if (preg_match('@^(/[/*]+)[^/*\s]@', $value, $match)) {
+          $this->raiseLintAtOffset(
+            $comment->getOffset(),
+            self::LINT_COMMENT_SPACING,
+            'Put space after comment start.',
+            $match[1],
+            $match[1].' ');
+        }
+      }
+    }
+  }
+
+
   protected function lintHashComments($root) {
     foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
       $value = $comment->getValue();
@@ -579,7 +603,7 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
         self::LINT_COMMENT_STYLE,
         'Use "//" single-line comments, not "#".',
         '#',
-        '//');
+        (preg_match('/^#\S/', $value) ? '// ' : '//'));
     }
   }
 
index 3c5d700db2d7908ecd86eeb2eab5a77736876347..c4853f5ad770dc662763e56bc739f7d7e87098cd 100644 (file)
  */
 //#yes
 /*#yes*/
+#
+//
+/////////////////// yes
+/*no */
+/**no */
+/** yes */
+/**** yes ****/
 ~~~~~~~~~~
 error:2:1
 error:3:1
 error:5:1
 error:6:11
+advice:13:1
+advice:14:1
+error:15:1
+advice:18:1
+advice:19:1
 ~~~~~~~~~~
 <?php
 // no
-//no
+// no
 // yes
 // no
-/* yes */ //no
+/* yes */ // no
 /*
  * yes
  */
 /**
  * yes
  */
-//#yes
-/*#yes*/
+// #yes
+/* #yes*/
+//
+//
+/////////////////// yes
+/* no */
+/** no */
+/** yes */
+/**** yes ****/