mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
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
This commit is contained in:
parent
821ebcdd07
commit
4e3df80584
6 changed files with 74 additions and 25 deletions
|
@ -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',
|
||||
|
|
56
src/lint/linter/ArcanistCommitLinter.php
Normal file
56
src/lint/linter/ArcanistCommitLinter.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class ArcanistCommitLinter extends ArcanistLinter {
|
||||
|
||||
const LINT_NO_COMMIT = 1;
|
||||
|
||||
public function getInfoName() {
|
||||
return pht('Commit Linter');
|
||||
}
|
||||
|
||||
public function getInfoDescription() {
|
||||
return pht('Ensures that specially marked files are not committed.');
|
||||
}
|
||||
|
||||
public function getLinterPriority() {
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
public function getLinterName() {
|
||||
return 'COMMIT';
|
||||
}
|
||||
|
||||
public function getLinterConfigurationName() {
|
||||
return 'commit';
|
||||
}
|
||||
|
||||
public function getLintNameMap() {
|
||||
return array(
|
||||
self::LINT_NO_COMMIT => 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
12
src/lint/linter/__tests__/ArcanistCommitLinterTestCase.php
Normal file
12
src/lint/linter/__tests__/ArcanistCommitLinterTestCase.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class ArcanistCommitLinterTestCase
|
||||
extends ArcanistArcanistLinterTestCase {
|
||||
|
||||
public function testCommitLint() {
|
||||
$this->executeTestsInDirectory(
|
||||
dirname(__FILE__).'/commit/',
|
||||
new ArcanistCommitLinter());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue