diff --git a/src/lint/linter/ArcanistTextLinter.php b/src/lint/linter/ArcanistTextLinter.php --- a/src/lint/linter/ArcanistTextLinter.php +++ b/src/lint/linter/ArcanistTextLinter.php @@ -15,6 +15,7 @@ const LINT_EOF_WHITESPACE = 9; private $maxLineLength = 80; + private $parser; public function getInfoName() { return pht('Basic Text Linter'); @@ -88,6 +89,11 @@ ); } + public function willLintPaths(array $paths) { + $root = $this->getEngine()->getWorkingCopy()->getProjectRoot(); + $this->parser = new PhutilEditorConfig($root); + } + public function lintPath($path) { if (!strlen($this->getData($path))) { // If the file is empty, don't bother; particularly, don't require @@ -117,6 +123,12 @@ } protected function lintNewlines($path) { + if (!$this->parser->getConfig( + $this->getEngine()->getFilePathOnDisk($path), + 'end_of_line') == 'lf') { + return; + } + $data = $this->getData($path); $pos = strpos($this->getData($path), "\r"); @@ -135,6 +147,12 @@ } protected function lintTabs($path) { + if (!$this->parser->getConfig( + $this->getEngine()->getFilePathOnDisk($path), + 'indent_style') == 'tabs') { + return; + } + $pos = strpos($this->getData($path), "\t"); if ($pos !== false) { $this->raiseLintAtOffset( @@ -166,6 +184,12 @@ } protected function lintEOFNewline($path) { + if (!$this->parser->getConfig( + $this->getEngine()->getFilePathOnDisk($path), + 'insert_final_newline')) { + return; + } + $data = $this->getData($path); if (!strlen($data) || $data[strlen($data) - 1] != "\n") { $this->raiseLintAtOffset( @@ -180,6 +204,12 @@ protected function lintCharset($path) { $data = $this->getData($path); + if (!$this->parser->getConfig( + $this->getEngine()->getFilePathOnDisk($path), + 'charset') != 'utf-8') { + return; + } + $matches = null; $bad = '[^\x09\x0A\x20-\x7E]'; $preg = preg_match_all( @@ -212,6 +242,12 @@ protected function lintTrailingWhitespace($path) { $data = $this->getData($path); + if (!$this->parser->getConfig( + $this->getEngine()->getFilePathOnDisk($path), + 'trim_trailing_whitespace')) { + return; + } + $matches = null; $preg = preg_match_all( '/ +$/m', @@ -240,6 +276,12 @@ protected function lintBOFWhitespace($path) { $data = $this->getData($path); + if (!$this->parser->getConfig( + $this->getEngine()->getFilePathOnDisk($path), + 'trim_trailing_whitespace')) { + return; + } + $matches = null; $preg = preg_match( '/^\s*\n/', @@ -265,6 +307,12 @@ protected function lintEOFWhitespace($path) { $data = $this->getData($path); + if (!$this->parser->getConfig( + $this->getEngine()->getFilePathOnDisk($path), + 'trim_trailing_whitespace')) { + return; + } + $matches = null; $preg = preg_match( '/(?<=\n)\s+$/',