From 4e3df805844cb35bb6f500c3bf0c2a9cfe872ea3 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Sun, 4 Jan 2015 16:20:31 +1100 Subject: [PATCH] Move `LINT_NO_COMMIT` from `ArcanistTextLinter` to a new linter Summary: I don't feel that this linter rule belongs in the `ArcanistTextLinter`. In fact, this linter rule is quite similar to the rules provided by `ArcanistGeneratedLinter` and `ArcanistNoLintLinter` and these classes could possibly be consolidated. I have moved this linter rule to a standalone `ArcanistCommitLinter` class (which could possibly do additional lints in the future). Test Plan: Moved existing test cases. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D10473 --- src/__phutil_library_map__.php | 4 ++ src/lint/linter/ArcanistCommitLinter.php | 56 +++++++++++++++++++ src/lint/linter/ArcanistTextLinter.php | 23 -------- .../ArcanistCommitLinterTestCase.php | 12 ++++ .../{text => commit}/nocommit-hook.lint-test | 4 +- .../nocommit-nohook.lint-test | 0 6 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 src/lint/linter/ArcanistCommitLinter.php create mode 100644 src/lint/linter/__tests__/ArcanistCommitLinterTestCase.php rename src/lint/linter/__tests__/{text => commit}/nocommit-hook.lint-test (76%) rename src/lint/linter/__tests__/{text => commit}/nocommit-nohook.lint-test (100%) diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index fb5819df..f07b2bfb 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -40,6 +40,8 @@ phutil_register_library_map(array( 'ArcanistCoffeeLintLinterTestCase' => 'lint/linter/__tests__/ArcanistCoffeeLintLinterTestCase.php', 'ArcanistCommentRemover' => 'parser/ArcanistCommentRemover.php', 'ArcanistCommentRemoverTestCase' => 'parser/__tests__/ArcanistCommentRemoverTestCase.php', + 'ArcanistCommitLinter' => 'lint/linter/ArcanistCommitLinter.php', + 'ArcanistCommitLinterTestCase' => 'lint/linter/__tests__/ArcanistCommitLinterTestCase.php', 'ArcanistCommitWorkflow' => 'workflow/ArcanistCommitWorkflow.php', 'ArcanistCompilerLikeLintRenderer' => 'lint/renderer/ArcanistCompilerLikeLintRenderer.php', 'ArcanistConduitLinter' => 'lint/linter/ArcanistConduitLinter.php', @@ -241,6 +243,8 @@ phutil_register_library_map(array( 'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter', 'ArcanistCoffeeLintLinterTestCase' => 'ArcanistArcanistLinterTestCase', 'ArcanistCommentRemoverTestCase' => 'ArcanistTestCase', + 'ArcanistCommitLinter' => 'ArcanistLinter', + 'ArcanistCommitLinterTestCase' => 'ArcanistArcanistLinterTestCase', 'ArcanistCommitWorkflow' => 'ArcanistWorkflow', 'ArcanistCompilerLikeLintRenderer' => 'ArcanistLintRenderer', 'ArcanistConduitLinter' => 'ArcanistLinter', diff --git a/src/lint/linter/ArcanistCommitLinter.php b/src/lint/linter/ArcanistCommitLinter.php new file mode 100644 index 00000000..17648335 --- /dev/null +++ b/src/lint/linter/ArcanistCommitLinter.php @@ -0,0 +1,56 @@ + pht('Explicit %s', '@no'.'commit'), + ); + } + + public function lintPath($path) { + if ($this->getEngine()->getCommitHookMode()) { + $this->lintNoCommit($path); + } + } + + 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, + pht( + 'This file is explicitly marked as "%s", which blocks commits.', + $deadly), + $deadly); + } + } + +} diff --git a/src/lint/linter/ArcanistTextLinter.php b/src/lint/linter/ArcanistTextLinter.php index e1b9f6c2..78d86a40 100644 --- a/src/lint/linter/ArcanistTextLinter.php +++ b/src/lint/linter/ArcanistTextLinter.php @@ -11,7 +11,6 @@ final class ArcanistTextLinter extends ArcanistLinter { const LINT_EOF_NEWLINE = 4; const LINT_BAD_CHARSET = 5; const LINT_TRAILING_WHITESPACE = 6; - const LINT_NO_COMMIT = 7; const LINT_BOF_WHITESPACE = 8; const LINT_EOF_WHITESPACE = 9; @@ -84,7 +83,6 @@ final class ArcanistTextLinter extends ArcanistLinter { self::LINT_EOF_NEWLINE => pht('File Does Not End in Newline'), self::LINT_BAD_CHARSET => pht('Bad Charset'), self::LINT_TRAILING_WHITESPACE => pht('Trailing Whitespace'), - self::LINT_NO_COMMIT => pht('Explicit %s', '@no'.'commit'), self::LINT_BOF_WHITESPACE => pht('Leading Whitespace at BOF'), self::LINT_EOF_WHITESPACE => pht('Trailing Whitespace at EOF'), ); @@ -116,10 +114,6 @@ final class ArcanistTextLinter extends ArcanistLinter { $this->lintBOFWhitespace($path); $this->lintEOFWhitespace($path); - - if ($this->getEngine()->getCommitHookMode()) { - $this->lintNoCommit($path); - } } protected function lintNewlines($path) { @@ -293,21 +287,4 @@ final 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, - pht( - 'This file is explicitly marked as "%s", which blocks commits.', - $deadly), - $deadly); - } - } - } diff --git a/src/lint/linter/__tests__/ArcanistCommitLinterTestCase.php b/src/lint/linter/__tests__/ArcanistCommitLinterTestCase.php new file mode 100644 index 00000000..293cf7cc --- /dev/null +++ b/src/lint/linter/__tests__/ArcanistCommitLinterTestCase.php @@ -0,0 +1,12 @@ +executeTestsInDirectory( + dirname(__FILE__).'/commit/', + new ArcanistCommitLinter()); + } + +} diff --git a/src/lint/linter/__tests__/text/nocommit-hook.lint-test b/src/lint/linter/__tests__/commit/nocommit-hook.lint-test similarity index 76% rename from src/lint/linter/__tests__/text/nocommit-hook.lint-test rename to src/lint/linter/__tests__/commit/nocommit-hook.lint-test index 902ef7c4..f1e6a148 100644 --- a/src/lint/linter/__tests__/text/nocommit-hook.lint-test +++ b/src/lint/linter/__tests__/commit/nocommit-hook.lint-test @@ -4,5 +4,5 @@ error:1:1 ~~~~~~~~~~ ~~~~~~~~~~ { - "hook" : true -} \ No newline at end of file + "hook": true +} diff --git a/src/lint/linter/__tests__/text/nocommit-nohook.lint-test b/src/lint/linter/__tests__/commit/nocommit-nohook.lint-test similarity index 100% rename from src/lint/linter/__tests__/text/nocommit-nohook.lint-test rename to src/lint/linter/__tests__/commit/nocommit-nohook.lint-test