From c83f3f6aebc4c6271e5f9864f6037ace32e4823d Mon Sep 17 00:00:00 2001 From: adonohue Date: Thu, 24 Feb 2011 17:59:49 -0800 Subject: [PATCH] Respect @nolint Summary: Respect @nolint annotations Test Plan: New "test case" Differential Revision: 41 Reviewed By: epriestley Reviewers: epriestley CC: epriestley --- src/__phutil_library_map__.php | 2 + src/lint/engine/phutil/PhutilLintEngine.php | 6 +++ src/lint/engine/phutil/__init__.php | 1 + .../generated/ArcanistGeneratedLinter.php | 20 +++++++- .../linter/nolint/ArcanistNoLintLinter.php | 50 +++++++++++++++++++ src/lint/linter/nolint/__init__.php | 12 +++++ .../__tests__/ArcanistNoLintTestCase.php | 29 +++++++++++ src/lint/linter/nolint/__tests__/__init__.php | 12 +++++ 8 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 src/lint/linter/nolint/ArcanistNoLintLinter.php create mode 100644 src/lint/linter/nolint/__init__.php create mode 100644 src/lint/linter/nolint/__tests__/ArcanistNoLintTestCase.php create mode 100644 src/lint/linter/nolint/__tests__/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f9fe6907..dd5b4f0c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/lint/engine/phutil/PhutilLintEngine.php b/src/lint/engine/phutil/PhutilLintEngine.php index d923c166..cc1d25a4 100644 --- a/src/lint/engine/phutil/PhutilLintEngine.php +++ b/src/lint/engine/phutil/PhutilLintEngine.php @@ -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)); } diff --git a/src/lint/engine/phutil/__init__.php b/src/lint/engine/phutil/__init__.php index 77ce9ef9..1f5377b7 100644 --- a/src/lint/engine/phutil/__init__.php +++ b/src/lint/engine/phutil/__init__.php @@ -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'); diff --git a/src/lint/linter/generated/ArcanistGeneratedLinter.php b/src/lint/linter/generated/ArcanistGeneratedLinter.php index db739091..91e30eff 100644 --- a/src/lint/linter/generated/ArcanistGeneratedLinter.php +++ b/src/lint/linter/generated/ArcanistGeneratedLinter.php @@ -1,5 +1,21 @@ 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 index 00000000..705446ee --- /dev/null +++ b/src/lint/linter/nolint/ArcanistNoLintLinter.php @@ -0,0 +1,50 @@ +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 index 00000000..65ac5d66 --- /dev/null +++ b/src/lint/linter/nolint/__init__.php @@ -0,0 +1,12 @@ +