]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add @nocommit and tests to Text linter.
authorepriestley <epriestley@javelinjs.com>
Thu, 17 Feb 2011 01:26:51 +0000 (17:26 -0800)
committerepriestley <epriestley@javelinjs.com>
Thu, 17 Feb 2011 01:26:51 +0000 (17:26 -0800)
Summary:

Test Plan:

Reviewers:

CC:

src/__phutil_library_map__.php
src/lint/linter/apachelicense/__tests__/__init__.php
src/lint/linter/base/test/__init__.php
src/lint/linter/text/ArcanistTextLinter.php
src/lint/linter/text/__tests__/ArcanistTextLinterTestCase.php [new file with mode: 0644]
src/lint/linter/text/__tests__/__init__.php [new file with mode: 0644]
src/lint/linter/text/__tests__/data/nocommit-hook.lint-test [new file with mode: 0644]
src/lint/linter/text/__tests__/data/nocommit-nohook.lint-test [new file with mode: 0644]
src/lint/linter/xhpast/__tests__/__init__.php

index 2b53d7b82350626635e36b3993cd0056b1ff3a62..d0d784a48bb278aafe0d37f151dfa8a663285695 100644 (file)
@@ -59,6 +59,7 @@ phutil_register_library_map(array(
     'ArcanistSubversionAPI' => 'repository/api/subversion',
     'ArcanistSvnHookPreCommitWorkflow' => 'workflow/svn-hook-pre-commit',
     'ArcanistTextLinter' => 'lint/linter/text',
+    'ArcanistTextLinterTestCase' => 'lint/linter/text/__tests__',
     'ArcanistUnitTestResult' => 'unit/result',
     'ArcanistUnitWorkflow' => 'workflow/unit',
     'ArcanistUsageException' => 'exception/usage',
@@ -104,6 +105,7 @@ phutil_register_library_map(array(
     'ArcanistSubversionAPI' => 'ArcanistRepositoryAPI',
     'ArcanistSvnHookPreCommitWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistTextLinter' => 'ArcanistLinter',
+    'ArcanistTextLinterTestCase' => 'ArcanistLinterTestCase',
     'ArcanistUnitWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistUserAbortException' => 'ArcanistUsageException',
     'ArcanistXHPASTLinter' => 'ArcanistLinter',
index d9c8c50f796232489d8dbcc5acf3b4eeb59ae14b..49d0c3a4b13350b19cd7bc642f80d5b8b59ce4da 100644 (file)
@@ -8,6 +8,7 @@
 
 phutil_require_module('arcanist', 'lint/linter/apachelicense');
 phutil_require_module('arcanist', 'lint/linter/base/test');
+phutil_require_module('arcanist', 'workingcopyidentity');
 
 
 phutil_require_source('ArcanistApacheLicenseLinterTestCase.php');
index c51dbca462a2188b9d147f06671ae45fa3de1dab..3ae02c6ee8e30a497514d0e00e455dd1a3696ba4 100644 (file)
@@ -9,7 +9,6 @@
 phutil_require_module('arcanist', 'lint/engine/test');
 phutil_require_module('arcanist', 'lint/patcher');
 phutil_require_module('arcanist', 'unit/engine/phutil/testcase');
-phutil_require_module('arcanist', 'workingcopyidentity');
 
 phutil_require_module('phutil', 'filesystem');
 phutil_require_module('phutil', 'utils');
index 61ccad079f504396ac13f9e9c8a1cdf894a0369a..23c24c77badbece5149b0d833350bdb417c130c1 100644 (file)
@@ -24,6 +24,7 @@ class ArcanistTextLinter extends ArcanistLinter {
   const LINT_EOF_NEWLINE            = 4;
   const LINT_BAD_CHARSET            = 5;
   const LINT_TRAILING_WHITESPACE    = 6;
+  const LINT_NO_COMMIT              = 7;
 
   private $maxLineLength = 80;
 
@@ -54,6 +55,7 @@ class ArcanistTextLinter extends ArcanistLinter {
       self::LINT_EOF_NEWLINE          => 'File Does Not End in Newline',
       self::LINT_BAD_CHARSET          => 'Bad Charset',
       self::LINT_TRAILING_WHITESPACE  => 'Trailing Whitespace',
+      self::LINT_NO_COMMIT            => 'Explicit @no'.'commit',
     );
   }
 
@@ -74,6 +76,10 @@ class ArcanistTextLinter extends ArcanistLinter {
     $this->lintLineLength($path);
     $this->lintEOFNewline($path);
     $this->lintTrailingWhitespace($path);
+
+    if ($this->getEngine()->getCommitHookMode()) {
+      $this->lintNoCommit($path);
+    }
   }
 
   protected function lintNewlines($path) {
@@ -181,4 +187,21 @@ class ArcanistTextLinter extends ArcanistLinter {
     }
   }
 
+  private function lintNoCommit($path) {
+    $data = $this->getData($path);
+
+    $deadly = '@no'.'commit';
+
+    $offset = strpos($data, $deadly);
+    if ($offset !== false) {
+      $this->raiseLintAtOffset(
+        $offset,
+        self::LINT_NO_COMMIT,
+        'This file is explicitly marked as "'.$deadly.'", which blocks '.
+        'commits.',
+        $deadly);
+    }
+  }
+
+
 }
diff --git a/src/lint/linter/text/__tests__/ArcanistTextLinterTestCase.php b/src/lint/linter/text/__tests__/ArcanistTextLinterTestCase.php
new file mode 100644 (file)
index 0000000..caff624
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+class ArcanistTextLinterTestCase extends ArcanistLinterTestCase {
+
+  public function testTextLint() {
+    $linter = new ArcanistTextLinter();
+    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
+    return $this->executeTestsInDirectory(
+      dirname(__FILE__).'/data/',
+      $linter,
+      $working_copy);
+  }
+
+}
diff --git a/src/lint/linter/text/__tests__/__init__.php b/src/lint/linter/text/__tests__/__init__.php
new file mode 100644 (file)
index 0000000..773f78c
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+/**
+ * This file is automatically generated. Lint this module to rebuild it.
+ * @generated
+ */
+
+
+
+phutil_require_module('arcanist', 'lint/linter/base/test');
+phutil_require_module('arcanist', 'lint/linter/text');
+phutil_require_module('arcanist', 'workingcopyidentity');
+
+
+phutil_require_source('ArcanistTextLinterTestCase.php');
diff --git a/src/lint/linter/text/__tests__/data/nocommit-hook.lint-test b/src/lint/linter/text/__tests__/data/nocommit-hook.lint-test
new file mode 100644 (file)
index 0000000..902ef7c
--- /dev/null
@@ -0,0 +1,8 @@
+@nocommit
+~~~~~~~~~~
+error:1:1
+~~~~~~~~~~
+~~~~~~~~~~
+{
+  "hook" : true
+}
\ No newline at end of file
diff --git a/src/lint/linter/text/__tests__/data/nocommit-nohook.lint-test b/src/lint/linter/text/__tests__/data/nocommit-nohook.lint-test
new file mode 100644 (file)
index 0000000..06570b2
--- /dev/null
@@ -0,0 +1,2 @@
+@nocommit
+~~~~~~~~~~
index bed07e76bd09a2d4270610b91ca931bd2b5cf104..d960ac84767824e658cf9cb97552c0faba01b0e0 100644 (file)
@@ -8,6 +8,7 @@
 
 phutil_require_module('arcanist', 'lint/linter/base/test');
 phutil_require_module('arcanist', 'lint/linter/xhpast');
+phutil_require_module('arcanist', 'workingcopyidentity');
 
 
 phutil_require_source('ArcanistXHPASTLinterTestCase.php');