]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Respect @nolint
authoradonohue <aran@fb.com>
Fri, 25 Feb 2011 01:59:49 +0000 (17:59 -0800)
committerepriestley <epriestley@phabricator.com>
Sun, 27 Feb 2011 04:54:06 +0000 (20:54 -0800)
Summary:
Respect @nolint annotations

Test Plan:
New "test case"

Differential Revision: 41
Reviewed By: epriestley
Reviewers: epriestley
CC: epriestley
src/__phutil_library_map__.php
src/lint/engine/phutil/PhutilLintEngine.php
src/lint/engine/phutil/__init__.php
src/lint/linter/generated/ArcanistGeneratedLinter.php
src/lint/linter/nolint/ArcanistNoLintLinter.php [new file with mode: 0644]
src/lint/linter/nolint/__init__.php [new file with mode: 0644]
src/lint/linter/nolint/__tests__/ArcanistNoLintTestCase.php [new file with mode: 0644]
src/lint/linter/nolint/__tests__/__init__.php [new file with mode: 0644]

index f9fe69079c567b66b4f95259b951a9b7d5bd8ded..dd5b4f0ccce4ed88254b0b22cc5690c98522af60 100644 (file)
@@ -49,6 +49,7 @@ phutil_register_library_map(array(
     'ArcanistMarkCommittedWorkflow' => 'workflow/mark-committed',
     'ArcanistNoEffectException' => 'exception/usage/noeffect',
     'ArcanistNoEngineException' => 'exception/usage/noengine',
+    'ArcanistNoLintLinter' => 'lint/linter/nolint',
     'ArcanistPEP8Linter' => 'lint/linter/pep8',
     'ArcanistPatchWorkflow' => 'workflow/patch',
     'ArcanistPhutilModuleLinter' => 'lint/linter/phutilmodule',
@@ -98,6 +99,7 @@ phutil_register_library_map(array(
     'ArcanistMarkCommittedWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistNoEffectException' => 'ArcanistUsageException',
     'ArcanistNoEngineException' => 'ArcanistUsageException',
+    'ArcanistNoLintLinter' => 'ArcanistLinter',
     'ArcanistPEP8Linter' => 'ArcanistLinter',
     'ArcanistPatchWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistPhutilModuleLinter' => 'ArcanistLinter',
index d923c16608c6798543633e18a6b1537017bfae5e..cc1d25a415ec82bf0669abc3393043e1048b96d3 100644 (file)
@@ -53,6 +53,9 @@ class PhutilLintEngine extends ArcanistLintEngine {
     $generated_linter = new ArcanistGeneratedLinter();
     $linters[] = $generated_linter;
 
+    $nolint_linter = new ArcanistNoLintLinter();
+    $linters[] = $nolint_linter;
+
     $text_linter = new ArcanistTextLinter();
     $linters[] = $text_linter;
     foreach ($paths as $path) {
@@ -64,6 +67,9 @@ class PhutilLintEngine extends ArcanistLintEngine {
         $generated_linter->addPath($path);
         $generated_linter->addData($path, $this->loadData($path));
 
+        $nolint_linter->addPath($path);
+        $nolint_linter->addData($path, $this->loadData($path));
+
         $text_linter->addPath($path);
         $text_linter->addData($path, $this->loadData($path));
       }
index 77ce9ef998a7702edb77bfd579e9e3ab3f4d31f9..1f5377b76dc44b01f1548030654a49eb214d74c4 100644 (file)
@@ -10,6 +10,7 @@ phutil_require_module('arcanist', 'lint/engine/base');
 phutil_require_module('arcanist', 'lint/linter/apachelicense');
 phutil_require_module('arcanist', 'lint/linter/filename');
 phutil_require_module('arcanist', 'lint/linter/generated');
+phutil_require_module('arcanist', 'lint/linter/nolint');
 phutil_require_module('arcanist', 'lint/linter/phutilmodule');
 phutil_require_module('arcanist', 'lint/linter/text');
 phutil_require_module('arcanist', 'lint/linter/xhpast');
index db7390911fa44e55d0798f8d5284f25b3059a436..91e30eff513dbc9a923ba63befc4a0d95e11a93c 100644 (file)
@@ -1,5 +1,21 @@
 <?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.
+ */
+
 /**
  * Stops other linters from running on generated code.
  *
@@ -26,8 +42,8 @@ class ArcanistGeneratedLinter extends ArcanistLinter {
 
   public function lintPath($path) {
     $data = $this->getData($path);
-    
-    if (preg_match('/@generated/', $data)) {
+
+    if (preg_match('/@'.'generated/', $data)) {
       $this->stopAllLinters();
     }
   }
diff --git a/src/lint/linter/nolint/ArcanistNoLintLinter.php b/src/lint/linter/nolint/ArcanistNoLintLinter.php
new file mode 100644 (file)
index 0000000..705446e
--- /dev/null
@@ -0,0 +1,50 @@
+<?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.
+ */
+
+/**
+ * Stops other linters from running on code marked with
+ * a nolint annotation.
+ *
+ * @group linter
+ */
+class ArcanistNoLintLinter extends ArcanistLinter {
+  public function willLintPaths(array $paths) {
+    return;
+  }
+
+  public function getLinterName() {
+    return 'NOLINT';
+  }
+
+  public function getLintSeverityMap() {
+    return array();
+  }
+
+  public function getLintNameMap() {
+    return array(
+    );
+  }
+
+  public function lintPath($path) {
+    $data = $this->getData($path);
+
+    if (preg_match('/@'.'nolint/', $data)) {
+      $this->stopAllLinters();
+    }
+  }
+}
diff --git a/src/lint/linter/nolint/__init__.php b/src/lint/linter/nolint/__init__.php
new file mode 100644 (file)
index 0000000..65ac5d6
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+/**
+ * This file is automatically generated. Lint this module to rebuild it.
+ * @generated
+ */
+
+
+
+phutil_require_module('arcanist', 'lint/linter/base');
+
+
+phutil_require_source('ArcanistNoLintLinter.php');
diff --git a/src/lint/linter/nolint/__tests__/ArcanistNoLintTestCase.php b/src/lint/linter/nolint/__tests__/ArcanistNoLintTestCase.php
new file mode 100644 (file)
index 0000000..8be51db
--- /dev/null
@@ -0,0 +1,29 @@
+<?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.
+ */
+
+/**
+ * Test for @{class:ArcanistNoLintLinter}.
+ *
+ * Not a real test... meant to fail lint
+ * if @nolint is not respected.
+ *
+ * @group testcase
+ */
+class ArcanistNoLintTestCaseMisnamed extends ArcanistLinterTestCase {
+
+}
diff --git a/src/lint/linter/nolint/__tests__/__init__.php b/src/lint/linter/nolint/__tests__/__init__.php
new file mode 100644 (file)
index 0000000..5c3f320
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+/**
+ * This file is automatically generated. Lint this module to rebuild it.
+ * @generated
+ */
+
+
+
+phutil_require_module('arcanist', 'lint/linter/base/test');
+
+
+phutil_require_source('ArcanistNoLintTestCase.php');