protected $replacementText;
protected $appliedToDisk;
protected $dependentMessages = array();
+ protected $otherLocations = array();
protected $obsolete;
protected $uncacheable;
if (isset($dict['replacement'])) {
$message->setReplacementText($dict['replacement']);
}
+ $message->setOtherLocations(idx($dict, 'locations', array()));
return $message;
}
'description' => $this->getDescription(),
'original' => $this->getOriginalText(),
'replacement' => $this->getReplacementText(),
+ 'locations' => $this->getOtherLocations(),
);
}
return $this->replacementText;
}
+ /**
+ * @param dict Keys 'path', 'line', 'char', 'original'.
+ */
+ public function setOtherLocations(array $locations) {
+ $this->otherLocations = $locations;
+ return $this;
+ }
+
+ public function getOtherLocations() {
+ return $this->otherLocations;
+ }
+
public function isError() {
return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_ERROR;
}
abstract protected function buildLinters();
- private function isRelevantMessage($message) {
+ private function isRelevantMessage(ArcanistLintMessage $message) {
// 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). The list of $changed lines may be null, to indicate that the
// path is a directory or a binary file so we should not exclude
// warnings.
- $changed = $this->getPathChangedLines($message->getPath());
-
- if ($changed === null || $message->isError() || !$message->getLine()) {
+ if (!$this->changedLines || $message->isError()) {
return true;
}
- $last_line = $message->getLine();
- if ($message->getOriginalText()) {
- $last_line += substr_count($message->getOriginalText(), "\n");
- }
+ $locations = $message->getOtherLocations();
+ $locations[] = $message->toDictionary();
+
+ foreach ($locations as $location) {
+ $path = idx($location, 'path', $message->getPath());
+
+ if (!array_key_exists($path, $this->changedLines)) {
+ continue;
+ }
- for ($l = $message->getLine(); $l <= $last_line; $l++) {
- if (!empty($changed[$l])) {
+ $changed = $this->getPathChangedLines($path);
+
+ if ($changed === null || !$location['line']) {
return true;
}
+
+ $last_line = $location['line'];
+ if (isset($location['original'])) {
+ $last_line += substr_count($location['original'], "\n");
+ }
+
+ for ($l = $location['line']; $l <= $last_line; $l++) {
+ if (!empty($changed[$l])) {
+ return true;
+ }
+ }
}
return false;
* 'name'
* 'description'
* 'original' & 'replacement' => optional patch information
+ * 'locations' => other locations of the same error (in the same format)
*
* This class is intended for customization via instantiation, not via
* subclassing.
return $this->messages;
}
+ protected function newLintAtLine($line, $char, $code, $desc) {
+ return id(new ArcanistLintMessage())
+ ->setPath($this->getActivePath())
+ ->setLine($line)
+ ->setChar($char)
+ ->setCode($this->getLintMessageFullCode($code))
+ ->setSeverity($this->getLintMessageSeverity($code))
+ ->setName($this->getLintMessageName($code))
+ ->setDescription($desc);
+ }
+
protected function raiseLintAtLine(
$line,
$char,
$original = null,
$replacement = null) {
- $dict = array(
- 'path' => $this->getActivePath(),
- 'line' => $line,
- 'char' => $char,
- 'code' => $this->getLintMessageFullCode($code),
- 'severity' => $this->getLintMessageSeverity($code),
- 'name' => $this->getLintMessageName($code),
- 'description' => $desc,
- );
-
- if ($original !== null) {
- $dict['original'] = $original;
- }
- if ($replacement !== null) {
- $dict['replacement'] = $replacement;
- }
+ $message = $this->newLintAtLine($line, $char, $code, $desc)
+ ->setOriginalText($original)
+ ->setReplacementText($replacement);
- return $this->addLintMessage(ArcanistLintMessage::newFromDictionary($dict));
+ return $this->addLintMessage($message);
}
protected function raiseLintAtPath(