2011-01-09 15:22:25 -08:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 11:36:08 -08:00
|
|
|
/**
|
|
|
|
* Message emitted by a linter, like an error or warning.
|
|
|
|
*
|
|
|
|
* @group lint
|
|
|
|
*/
|
2012-01-31 12:07:05 -08:00
|
|
|
final class ArcanistLintMessage {
|
2011-01-09 15:22:25 -08:00
|
|
|
|
|
|
|
protected $path;
|
|
|
|
protected $line;
|
|
|
|
protected $char;
|
|
|
|
protected $code;
|
|
|
|
protected $severity;
|
|
|
|
protected $name;
|
|
|
|
protected $description;
|
|
|
|
protected $originalText;
|
|
|
|
protected $replacementText;
|
|
|
|
protected $appliedToDisk;
|
|
|
|
protected $dependentMessages = array();
|
2013-01-10 15:03:33 -08:00
|
|
|
protected $otherLocations = array();
|
2011-01-09 20:40:13 -08:00
|
|
|
protected $obsolete;
|
2012-11-21 18:38:24 -08:00
|
|
|
protected $uncacheable;
|
2011-01-09 15:22:25 -08:00
|
|
|
|
|
|
|
public static function newFromDictionary(array $dict) {
|
|
|
|
$message = new ArcanistLintMessage();
|
|
|
|
|
|
|
|
$message->setPath($dict['path']);
|
|
|
|
$message->setLine($dict['line']);
|
|
|
|
$message->setChar($dict['char']);
|
|
|
|
$message->setCode($dict['code']);
|
|
|
|
$message->setSeverity($dict['severity']);
|
|
|
|
$message->setName($dict['name']);
|
|
|
|
$message->setDescription($dict['description']);
|
|
|
|
if (isset($dict['original'])) {
|
|
|
|
$message->setOriginalText($dict['original']);
|
|
|
|
}
|
|
|
|
if (isset($dict['replacement'])) {
|
|
|
|
$message->setReplacementText($dict['replacement']);
|
|
|
|
}
|
2013-01-10 15:03:33 -08:00
|
|
|
$message->setOtherLocations(idx($dict, 'locations', array()));
|
2011-01-09 15:22:25 -08:00
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
2012-11-05 20:23:38 -08:00
|
|
|
public function toDictionary() {
|
|
|
|
return array(
|
|
|
|
'path' => $this->getPath(),
|
|
|
|
'line' => $this->getLine(),
|
|
|
|
'char' => $this->getChar(),
|
|
|
|
'code' => $this->getCode(),
|
|
|
|
'severity' => $this->getSeverity(),
|
|
|
|
'name' => $this->getName(),
|
|
|
|
'description' => $this->getDescription(),
|
2012-11-20 16:43:10 -08:00
|
|
|
'original' => $this->getOriginalText(),
|
|
|
|
'replacement' => $this->getReplacementText(),
|
2013-01-10 15:03:33 -08:00
|
|
|
'locations' => $this->getOtherLocations(),
|
2012-11-05 20:23:38 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function setPath($path) {
|
|
|
|
$this->path = $path;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPath() {
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setLine($line) {
|
|
|
|
$this->line = $line;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLine() {
|
|
|
|
return $this->line;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setChar($char) {
|
|
|
|
$this->char = $char;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChar() {
|
|
|
|
return $this->char;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCode($code) {
|
|
|
|
$this->code = $code;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCode() {
|
|
|
|
return $this->code;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setSeverity($severity) {
|
|
|
|
$this->severity = $severity;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSeverity() {
|
|
|
|
return $this->severity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDescription($description) {
|
|
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDescription() {
|
|
|
|
return $this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOriginalText($original) {
|
|
|
|
$this->originalText = $original;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOriginalText() {
|
|
|
|
return $this->originalText;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setReplacementText($replacement) {
|
|
|
|
$this->replacementText = $replacement;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReplacementText() {
|
|
|
|
return $this->replacementText;
|
|
|
|
}
|
|
|
|
|
2013-01-10 15:03:33 -08:00
|
|
|
/**
|
|
|
|
* @param dict Keys 'path', 'line', 'char', 'original'.
|
|
|
|
*/
|
|
|
|
public function setOtherLocations(array $locations) {
|
2013-01-11 20:12:01 -08:00
|
|
|
assert_instances_of($locations, 'array');
|
2013-01-10 15:03:33 -08:00
|
|
|
$this->otherLocations = $locations;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOtherLocations() {
|
|
|
|
return $this->otherLocations;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function isError() {
|
|
|
|
return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isWarning() {
|
|
|
|
return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_WARNING;
|
|
|
|
}
|
|
|
|
|
2012-04-06 12:23:19 -07:00
|
|
|
public function isAutofix() {
|
|
|
|
return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_AUTOFIX;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function hasFileContext() {
|
|
|
|
return ($this->getLine() !== null);
|
|
|
|
}
|
|
|
|
|
2011-01-09 20:40:13 -08:00
|
|
|
public function setObsolete($obsolete) {
|
|
|
|
$this->obsolete = $obsolete;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getObsolete() {
|
|
|
|
return $this->obsolete;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function isPatchable() {
|
Fix an obscure dependency issue in Arcanist + libphutil
Summary:
The module analyzer reads "phutil_require_module" in the source of a module as a
dependency, and tries to regenerate __init__.php if symbols from that module
aren't actually used. This creates patches which don't actually resolve the
problem, since changing __init__.php won't change the dependency.
Instead, trust that anyone using phutil_require_module in the source of a module
knows what they're doing and don't mark it as a dependency.
We currently have an issue with this in phabricator's Setup process since I load
some other libraries' modules just to test if they can be loaded
@lesha, this might be the issue you reported a while ago.
Test Plan: Ran "arc lint" on a module which pulls in another module explicitly
in the source, didn't get a no-op lint error.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran, lesha
CC: aran, epriestley, jungejason
Differential Revision: 770
2011-07-29 09:12:24 -07:00
|
|
|
return ($this->getReplacementText() !== null) &&
|
|
|
|
($this->getReplacementText() !== $this->getOriginalText());
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function didApplyPatch() {
|
|
|
|
if ($this->appliedToDisk) {
|
2012-04-04 12:46:42 -07:00
|
|
|
return $this;
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
$this->appliedToDisk = true;
|
|
|
|
foreach ($this->dependentMessages as $message) {
|
|
|
|
$message->didApplyPatch();
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isPatchApplied() {
|
|
|
|
return $this->appliedToDisk;
|
|
|
|
}
|
|
|
|
|
2012-11-21 18:38:24 -08:00
|
|
|
public function setUncacheable($bool) {
|
|
|
|
$this->uncacheable = $bool;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isUncacheable() {
|
|
|
|
return $this->uncacheable;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function setDependentMessages(array $messages) {
|
2012-03-28 21:36:37 -07:00
|
|
|
assert_instances_of($messages, 'ArcanistLintMessage');
|
2011-01-09 15:22:25 -08:00
|
|
|
$this->dependentMessages = $messages;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|