1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-28 09:42:40 +01:00

Added ArcanistTextLinter::LINT_BOF_WHITESPACE and ArcanistTextLinter::LINT_EOF_WHITESPACE

Summary: This might not be universally desireable, but I found myself writing an additional linter (which I had called `WhitespaceTextLinter`) for the sake of these two linter tests. I figured it may be of use upstream, and so I decided to submit it as a diff. I won't be offended if it is rejected however.

Test Plan: `arc lint` and `arc unit` are both okay with it.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D7957
This commit is contained in:
Joshua Spence 2014-01-13 18:05:42 -08:00 committed by epriestley
parent dd12b72f9a
commit d62bd48a81
11 changed files with 77 additions and 10 deletions

View file

@ -20,4 +20,3 @@
["DivinerXHPEngine", {}]
]
}

View file

@ -1,3 +1,2 @@
@echo off
php -f "%~dp0..\scripts\arcanist.php" -- %*

View file

@ -624,4 +624,3 @@ function reenter_if_this_is_arcanist_or_libphutil(
exit($err);
}

View file

@ -57,5 +57,3 @@ abstract class ArcanistLicenseLinter extends ArcanistLinter {
}
}
}

View file

@ -14,6 +14,8 @@ final class ArcanistTextLinter extends ArcanistLinter {
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;
private $maxLineLength = 80;
@ -38,6 +40,8 @@ final class ArcanistTextLinter extends ArcanistLinter {
return array(
self::LINT_LINE_WRAP => ArcanistLintSeverity::SEVERITY_WARNING,
self::LINT_TRAILING_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX,
self::LINT_BOF_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX,
self::LINT_EOF_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX,
);
}
@ -50,6 +54,8 @@ final class ArcanistTextLinter extends ArcanistLinter {
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'),
);
}
@ -77,6 +83,9 @@ final class ArcanistTextLinter extends ArcanistLinter {
$this->lintEOFNewline($path);
$this->lintTrailingWhitespace($path);
$this->lintBOFWhitespace($path);
$this->lintEOFWhitespace($path);
if ($this->getEngine()->getCommitHookMode()) {
$this->lintNoCommit($path);
}
@ -194,6 +203,54 @@ final class ArcanistTextLinter extends ArcanistLinter {
}
}
protected function lintBOFWhitespace($path) {
$data = $this->getData($path);
$matches = null;
$preg = preg_match(
'/^\s*\n/',
$data,
$matches,
PREG_OFFSET_CAPTURE);
if (!$preg) {
return;
}
list($string, $offset) = $matches[0];
$this->raiseLintAtOffset(
$offset,
self::LINT_BOF_WHITESPACE,
'This file contains leading whitespace at the beginning of the file. ' .
'This is unnecessary and should be avoided when possible.',
$string,
'');
}
protected function lintEOFWhitespace($path) {
$data = $this->getData($path);
$matches = null;
$preg = preg_match(
'/(?<=\n)\s+$/',
$data,
$matches,
PREG_OFFSET_CAPTURE);
if (!$preg) {
return;
}
list($string, $offset) = $matches[0];
$this->raiseLintAtOffset(
$offset,
self::LINT_EOF_WHITESPACE,
'This file contains trailing whitespace at the end of the file. This ' .
'is unnecessary and should be avoided when possible.',
$string,
'');
}
private function lintNoCommit($path) {
$data = $this->getData($path);
@ -210,5 +267,4 @@ final class ArcanistTextLinter extends ArcanistLinter {
}
}
}

View file

@ -0,0 +1,9 @@
The quick brown fox jumps over the lazy dog.
~~~~~~~~~~
autofix:1:1
~~~~~~~~~~
The quick brown fox jumps over the lazy dog.

View file

@ -0,0 +1,2 @@
The quick brown fox jumps over the lazy dog.
~~~~~~~~~~

View file

@ -0,0 +1,9 @@
The quick brown fox jumps over the lazy dog.
~~~~~~~~~~
autofix:2:1
~~~~~~~~~~
The quick brown fox jumps over the lazy dog.

View file

@ -284,5 +284,3 @@ final class CSharpToolsTestEngine extends XUnitTestEngine {
return $reports;
}
}

View file

@ -181,4 +181,3 @@ EOTEXT
}
}

View file

@ -35,4 +35,3 @@ EOTEXT
$console->writeOut("Please use arc backout instead.\n");
}
}