diff --git a/src/lint/engine/base/ArcanistLintEngine.php b/src/lint/engine/base/ArcanistLintEngine.php index 6f98259b..0cc6c043 100644 --- a/src/lint/engine/base/ArcanistLintEngine.php +++ b/src/lint/engine/base/ArcanistLintEngine.php @@ -68,6 +68,7 @@ abstract class ArcanistLintEngine { private $minimumSeverity = ArcanistLintSeverity::SEVERITY_DISABLED; private $changedLines = array(); + private $textChanges = array(); private $commitHookMode = false; public function __construct() { @@ -101,6 +102,15 @@ abstract class ArcanistLintEngine { return idx($this->changedLines, $path); } + public function setTextChange($path) { + $this->textChanges[$path] = true; + return $this; + } + + public function isTextChange($path) { + return idx($this->textChanges, $path, false); + } + public function setFileData($data) { $this->fileData = $data + $this->fileData; return $this; @@ -193,11 +203,14 @@ abstract class ArcanistLintEngine { if (!ArcanistLintSeverity::isAtLeastAsSevere($message, $minimum)) { continue; } - // When a user runs "arc diff", we default to raising only warnings on + // When a user runs "arc lint", we default to raising only warnings on // lines they have changed (errors are still raised anywhere in the // file). + $text_change = $this->isTextChange($message->getPath()); $changed = $this->getPathChangedLines($message->getPath()); - if ($changed !== null && !$message->isError()) { + if ($text_change === true && + $changed !== null && + !$message->isError()) { if (empty($changed[$message->getLine()])) { continue; } diff --git a/src/workflow/base/ArcanistBaseWorkflow.php b/src/workflow/base/ArcanistBaseWorkflow.php index 9bf75f58..d0008fec 100644 --- a/src/workflow/base/ArcanistBaseWorkflow.php +++ b/src/workflow/base/ArcanistBaseWorkflow.php @@ -754,6 +754,11 @@ class ArcanistBaseWorkflow { return $bundle; } + protected function isTextChange($path) { + $change = $this->getChange($path); + return $change->getFileType() == ArcanistDiffChangeType::FILE_TEXT; + } + protected function getChangedLines($path, $mode) { if (is_dir($path)) { return array(); diff --git a/src/workflow/base/__init__.php b/src/workflow/base/__init__.php index a596254a..b59c83a1 100644 --- a/src/workflow/base/__init__.php +++ b/src/workflow/base/__init__.php @@ -13,6 +13,7 @@ phutil_require_module('arcanist', 'exception/usage/userabort'); phutil_require_module('arcanist', 'parser/bundle'); phutil_require_module('arcanist', 'parser/diff'); phutil_require_module('arcanist', 'parser/diff/change'); +phutil_require_module('arcanist', 'parser/diff/changetype'); phutil_require_module('phutil', 'conduit/client'); phutil_require_module('phutil', 'console'); diff --git a/src/workflow/lint/ArcanistLintWorkflow.php b/src/workflow/lint/ArcanistLintWorkflow.php index c98d6a26..ccb1c3ed 100644 --- a/src/workflow/lint/ArcanistLintWorkflow.php +++ b/src/workflow/lint/ArcanistLintWorkflow.php @@ -169,12 +169,20 @@ EOTEXT $engine->setMinimumSeverity(ArcanistLintSeverity::SEVERITY_WARNING); } + // Propagate information about which lines changed to the lint engine. + // This is used so that the lint engine can drop messages concerning + // lines that weren't in the change. $engine->setPaths($paths); if (!$should_lint_all) { foreach ($paths as $path) { - $engine->setPathChangedLines( - $path, - $this->getChangedLines($path, 'new')); + // Explicitly flag text changes, as line information doesn't apply + // to non-text files. + if ($this->isTextChange($path)) { + $engine->setTextChange($path); + $engine->setPathChangedLines( + $path, + $this->getChangedLines($path, 'new')); + } } }