diff --git a/.divinerconfig b/.divinerconfig index 6b02d18b..17f75d88 100644 --- a/.divinerconfig +++ b/.divinerconfig @@ -20,4 +20,3 @@ ["DivinerXHPEngine", {}] ] } - diff --git a/bin/arc.bat b/bin/arc.bat index a1fd8f6c..5ce474bf 100644 --- a/bin/arc.bat +++ b/bin/arc.bat @@ -1,3 +1,2 @@ @echo off php -f "%~dp0..\scripts\arcanist.php" -- %* - diff --git a/scripts/arcanist.php b/scripts/arcanist.php index 3c4936b8..62a67e50 100755 --- a/scripts/arcanist.php +++ b/scripts/arcanist.php @@ -624,4 +624,3 @@ function reenter_if_this_is_arcanist_or_libphutil( exit($err); } - diff --git a/src/lint/linter/ArcanistLicenseLinter.php b/src/lint/linter/ArcanistLicenseLinter.php index 1f071ddf..815e178a 100644 --- a/src/lint/linter/ArcanistLicenseLinter.php +++ b/src/lint/linter/ArcanistLicenseLinter.php @@ -57,5 +57,3 @@ abstract class ArcanistLicenseLinter extends ArcanistLinter { } } } - - diff --git a/src/lint/linter/ArcanistTextLinter.php b/src/lint/linter/ArcanistTextLinter.php index 4fdbef48..9042207e 100644 --- a/src/lint/linter/ArcanistTextLinter.php +++ b/src/lint/linter/ArcanistTextLinter.php @@ -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 { } } - } diff --git a/src/lint/linter/__tests__/text/bof-whitespace-1.lint-test b/src/lint/linter/__tests__/text/bof-whitespace-1.lint-test new file mode 100644 index 00000000..995aad6b --- /dev/null +++ b/src/lint/linter/__tests__/text/bof-whitespace-1.lint-test @@ -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. diff --git a/src/lint/linter/__tests__/text/bof-whitespace-2.lint-test b/src/lint/linter/__tests__/text/bof-whitespace-2.lint-test new file mode 100644 index 00000000..87ae7e67 --- /dev/null +++ b/src/lint/linter/__tests__/text/bof-whitespace-2.lint-test @@ -0,0 +1,2 @@ + The quick brown fox jumps over the lazy dog. +~~~~~~~~~~ diff --git a/src/lint/linter/__tests__/text/eof-whitespace.lint-test b/src/lint/linter/__tests__/text/eof-whitespace.lint-test new file mode 100644 index 00000000..b3b778c7 --- /dev/null +++ b/src/lint/linter/__tests__/text/eof-whitespace.lint-test @@ -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. diff --git a/src/unit/engine/CSharpToolsTestEngine.php b/src/unit/engine/CSharpToolsTestEngine.php index 9b85257a..d2557894 100644 --- a/src/unit/engine/CSharpToolsTestEngine.php +++ b/src/unit/engine/CSharpToolsTestEngine.php @@ -284,5 +284,3 @@ final class CSharpToolsTestEngine extends XUnitTestEngine { return $reports; } } - - diff --git a/src/workflow/ArcanistBackoutWorkflow.php b/src/workflow/ArcanistBackoutWorkflow.php index ac7c73d2..b7e0486d 100644 --- a/src/workflow/ArcanistBackoutWorkflow.php +++ b/src/workflow/ArcanistBackoutWorkflow.php @@ -181,4 +181,3 @@ EOTEXT } } - diff --git a/src/workflow/ArcanistRevertWorkflow.php b/src/workflow/ArcanistRevertWorkflow.php index ee7bc743..4b1b9491 100644 --- a/src/workflow/ArcanistRevertWorkflow.php +++ b/src/workflow/ArcanistRevertWorkflow.php @@ -35,4 +35,3 @@ EOTEXT $console->writeOut("Please use arc backout instead.\n"); } } -