'ArcanistDuplicateSwitchCaseXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDuplicateSwitchCaseXHPASTLinterRule.php',
'ArcanistDynamicDefineXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistDynamicDefineXHPASTLinterRule.php',
'ArcanistElseIfUsageXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistElseIfUsageXHPASTLinterRule.php',
+ 'ArcanistEmptyFileXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistEmptyFileXHPASTLinterRule.php',
'ArcanistEmptyStatementXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistEmptyStatementXHPASTLinterRule.php',
'ArcanistEventType' => 'events/constant/ArcanistEventType.php',
'ArcanistExitExpressionXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistExitExpressionXHPASTLinterRule.php',
'ArcanistDuplicateSwitchCaseXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistDynamicDefineXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistElseIfUsageXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
+ 'ArcanistEmptyFileXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistEmptyStatementXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistEventType' => 'PhutilEventType',
'ArcanistExitExpressionXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
const LINT_TRAILING_WHITESPACE = 6;
const LINT_BOF_WHITESPACE = 8;
const LINT_EOF_WHITESPACE = 9;
+ const LINT_EMPTY_FILE = 10;
private $maxLineLength = 80;
self::LINT_TRAILING_WHITESPACE => pht('Trailing Whitespace'),
self::LINT_BOF_WHITESPACE => pht('Leading Whitespace at BOF'),
self::LINT_EOF_WHITESPACE => pht('Trailing Whitespace at EOF'),
+ self::LINT_EMPTY_FILE => pht('Empty File'),
);
}
public function lintPath($path) {
+ $this->lintEmptyFile($path);
+
if (!strlen($this->getData($path))) {
// If the file is empty, don't bother; particularly, don't require
// the user to add a newline.
return;
}
+ if ($this->didStopAllLinters()) {
+ return;
+ }
+
$this->lintNewlines($path);
$this->lintTabs($path);
$this->lintEOFWhitespace($path);
}
+ protected function lintEmptyFile($path) {
+ $data = $this->getData($path);
+
+ // It is reasonable for certain file types to be completely empty,
+ // so they are excluded here.
+ switch ($filename = basename($this->getActivePath())) {
+ case '__init__.py':
+ return;
+
+ default:
+ if (strlen($filename) && $filename[0] == '.') {
+ return;
+ }
+ }
+
+ if (preg_match('/^\s*$/', $data)) {
+ $this->raiseLintAtPath(
+ self::LINT_EMPTY_FILE,
+ pht("Empty files usually don't serve any useful purpose."));
+ $this->stopAllLinters();
+ }
+ }
+
protected function lintNewlines($path) {
$data = $this->getData($path);
$pos = strpos($this->getData($path), "\r");
--- /dev/null
+<?php
+
+final class ArcanistEmptyFileXHPASTLinterRule
+ extends ArcanistXHPASTLinterRule {
+
+ const ID = 82;
+
+ public function getLintName() {
+ return pht('Empty File');
+ }
+
+ public function getLintSeverity() {
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ }
+
+ public function process(XHPASTNode $root) {
+ $tokens = $root->getTokens();
+
+ foreach ($tokens as $token) {
+ switch ($token->getTypeName()) {
+ case 'T_OPEN_TAG':
+ case 'T_CLOSE_TAG':
+ case 'T_WHITESPACE':
+ break;
+
+ default:
+ return;
+ }
+ }
+
+ $this->raiseLintAtPath(
+ pht("Empty files usually don't serve any useful purpose."));
+ }
+
+}