mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-03-26 03:00:44 +01:00
Summary: There is one big decision: How to get linters version. I've created `getCacheVersion()` which is supposed to be bumped every time engine or any linter is changed. This is not very nice but the other alternative (detect this automatically) seems worse: - The engine may be outside repo and may or may not be under version control so getting its version through something like `git log` may not be even possible. - If it is in the same repo then every rebase will obsolete the whole cache. Even though bumping the version manually is PITA I still think it's a better solution. Test Plan: $ time arc lint --cache 1 # verified file $ arc arc lint --cache 1 # added some debug output to see the cached results # also observed better time (.57 s instead of 2.19 s) Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2036 Differential Revision: https://secure.phabricator.com/D4006
188 lines
4.1 KiB
PHP
188 lines
4.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Message emitted by a linter, like an error or warning.
|
|
*
|
|
* @group lint
|
|
*/
|
|
final class ArcanistLintMessage {
|
|
|
|
protected $path;
|
|
protected $line;
|
|
protected $char;
|
|
protected $code;
|
|
protected $severity;
|
|
protected $name;
|
|
protected $description;
|
|
protected $originalText;
|
|
protected $replacementText;
|
|
protected $appliedToDisk;
|
|
protected $dependentMessages = array();
|
|
protected $obsolete;
|
|
|
|
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']);
|
|
}
|
|
return $message;
|
|
}
|
|
|
|
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(),
|
|
'original' => $this->getOriginalText(),
|
|
'replacement' => $this->getReplacementText(),
|
|
);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public function isError() {
|
|
return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_ERROR;
|
|
}
|
|
|
|
public function isWarning() {
|
|
return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_WARNING;
|
|
}
|
|
|
|
public function isAutofix() {
|
|
return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_AUTOFIX;
|
|
}
|
|
|
|
public function hasFileContext() {
|
|
return ($this->getLine() !== null);
|
|
}
|
|
|
|
public function setObsolete($obsolete) {
|
|
$this->obsolete = $obsolete;
|
|
return $this;
|
|
}
|
|
|
|
public function getObsolete() {
|
|
return $this->obsolete;
|
|
}
|
|
|
|
public function isPatchable() {
|
|
return ($this->getReplacementText() !== null) &&
|
|
($this->getReplacementText() !== $this->getOriginalText());
|
|
}
|
|
|
|
public function didApplyPatch() {
|
|
if ($this->appliedToDisk) {
|
|
return $this;
|
|
}
|
|
$this->appliedToDisk = true;
|
|
foreach ($this->dependentMessages as $message) {
|
|
$message->didApplyPatch();
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
public function isPatchApplied() {
|
|
return $this->appliedToDisk;
|
|
}
|
|
|
|
public function setDependentMessages(array $messages) {
|
|
assert_instances_of($messages, 'ArcanistLintMessage');
|
|
$this->dependentMessages = $messages;
|
|
return $this;
|
|
}
|
|
|
|
}
|