mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Add @nocommit and tests to Text linter.
Summary: Test Plan: Reviewers: CC:
This commit is contained in:
parent
2354d544e3
commit
ba6091f945
9 changed files with 81 additions and 1 deletions
|
@ -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',
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
14
src/lint/linter/text/__tests__/__init__.php
Normal file
14
src/lint/linter/text/__tests__/__init__.php
Normal file
|
@ -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');
|
|
@ -0,0 +1,8 @@
|
|||
@nocommit
|
||||
~~~~~~~~~~
|
||||
error:1:1
|
||||
~~~~~~~~~~
|
||||
~~~~~~~~~~
|
||||
{
|
||||
"hook" : true
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
@nocommit
|
||||
~~~~~~~~~~
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue