Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistTextLinter.php
| Show All 10 Lines | final class ArcanistTextLinter extends ArcanistLinter { | ||||
| const LINT_TAB_LITERAL = 2; | const LINT_TAB_LITERAL = 2; | ||||
| const LINT_LINE_WRAP = 3; | const LINT_LINE_WRAP = 3; | ||||
| const LINT_EOF_NEWLINE = 4; | const LINT_EOF_NEWLINE = 4; | ||||
| const LINT_BAD_CHARSET = 5; | const LINT_BAD_CHARSET = 5; | ||||
| const LINT_TRAILING_WHITESPACE = 6; | const LINT_TRAILING_WHITESPACE = 6; | ||||
| const LINT_NO_COMMIT = 7; | const LINT_NO_COMMIT = 7; | ||||
| private $maxLineLength = 80; | private $maxLineLength = 80; | ||||
| private $badCharsetsAllowed = false; | |||||
| public function setMaxLineLength($new_length) { | public function setMaxLineLength($new_length) { | ||||
| $this->maxLineLength = $new_length; | $this->maxLineLength = $new_length; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function willLintPaths(array $paths) { | public function willLintPaths(array $paths) { | ||||
| return; | return; | ||||
| } | } | ||||
| public function setBadCharsetsAllowed($allowed) { | |||||
| $this->allowBadCharsets = $allowed; | |||||
| return $this; | |||||
| } | |||||
| public function isBadCharsetsAllowed() { | |||||
| return $this->allowBadCharsets; | |||||
| } | |||||
| public function getLinterName() { | public function getLinterName() { | ||||
| return 'TXT'; | return 'TXT'; | ||||
| } | } | ||||
| public function getLintSeverityMap() { | public function getLintSeverityMap() { | ||||
| return array( | return array( | ||||
| self::LINT_LINE_WRAP => ArcanistLintSeverity::SEVERITY_WARNING, | self::LINT_LINE_WRAP => ArcanistLintSeverity::SEVERITY_WARNING, | ||||
| self::LINT_TRAILING_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX, | self::LINT_TRAILING_WHITESPACE => ArcanistLintSeverity::SEVERITY_AUTOFIX, | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (!strlen($data) || $data[strlen($data) - 1] != "\n") { | ||||
| self::LINT_EOF_NEWLINE, | self::LINT_EOF_NEWLINE, | ||||
| "Files must end in a newline.", | "Files must end in a newline.", | ||||
| '', | '', | ||||
| "\n"); | "\n"); | ||||
| } | } | ||||
| } | } | ||||
| protected function lintCharset($path) { | protected function lintCharset($path) { | ||||
| if ($this->allowBadCharsets) { | |||||
| return; | |||||
| } | |||||
| $data = $this->getData($path); | $data = $this->getData($path); | ||||
| $matches = null; | $matches = null; | ||||
| $bad = '[^\x09\x0A\x20-\x7E]'; | $bad = '[^\x09\x0A\x20-\x7E]'; | ||||
| $preg = preg_match_all( | $preg = preg_match_all( | ||||
| "/{$bad}(.*{$bad})?/", | "/{$bad}(.*{$bad})?/", | ||||
| $data, | $data, | ||||
| $matches, | $matches, | ||||
| ▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines | |||||