Changeset View
Changeset View
Standalone View
Standalone View
src/lint/ArcanistLintMessage.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Message emitted by a linter, like an error or warning. | * Message emitted by a linter, like an error or warning. | ||||
| */ | */ | ||||
| final class ArcanistLintMessage { | final class ArcanistLintMessage { | ||||
| protected $path; | protected $path; | ||||
| protected $line; | protected $line; | ||||
| protected $char; | protected $char; | ||||
| protected $linterName; | |||||
| protected $code; | protected $code; | ||||
| protected $severity; | protected $severity; | ||||
| protected $name; | protected $name; | ||||
| protected $description; | protected $description; | ||||
| protected $originalText; | protected $originalText; | ||||
| protected $replacementText; | protected $replacementText; | ||||
| protected $appliedToDisk; | |||||
| protected $dependentMessages = array(); | |||||
| protected $otherLocations = array(); | |||||
| protected $obsolete; | |||||
| protected $granularity; | protected $granularity; | ||||
| protected $bypassChangedLineFiltering; | protected $otherLocations = array(); | ||||
| public static function newFromDictionary(array $dict) { | private $appliedToDisk; | ||||
| $message = new ArcanistLintMessage(); | private $obsolete; | ||||
| $message->setPath($dict['path']); | public static function newFromDictionary(array $dict) { | ||||
| $message->setLine($dict['line']); | return id(new ArcanistLintMessage()) | ||||
| $message->setChar($dict['char']); | ->setPath($dict['path']) | ||||
| $message->setCode($dict['code']); | ->setLine($dict['line']) | ||||
| $message->setSeverity($dict['severity']); | ->setChar($dict['char']) | ||||
| $message->setName($dict['name']); | ->setLinterName($dict['linterName']) | ||||
| $message->setDescription($dict['description']); | ->setCode($dict['code']) | ||||
| if (isset($dict['original'])) { | ->setSeverity($dict['severity']) | ||||
| $message->setOriginalText($dict['original']); | ->setName($dict['name']) | ||||
| } | ->setDescription($dict['description']) | ||||
| if (isset($dict['replacement'])) { | ->setOriginalText($dict['original']) | ||||
| $message->setReplacementText($dict['replacement']); | ->setReplacementText($dict['replacement']) | ||||
| } | ->setGranularity(idx($dict, 'granularity')) | ||||
| $message->setGranularity(idx($dict, 'granularity')); | ->setOtherLocations(idx($dict, 'locations', array())); | ||||
| $message->setOtherLocations(idx($dict, 'locations', array())); | |||||
| if (isset($dict['bypassChangedLineFiltering'])) { | |||||
| $message->bypassChangedLineFiltering($dict['bypassChangedLineFiltering']); | |||||
| } | |||||
| return $message; | |||||
| } | } | ||||
| public function toDictionary() { | public function toDictionary() { | ||||
| return array( | return array( | ||||
| 'path' => $this->getPath(), | 'path' => $this->getPath(), | ||||
| 'line' => $this->getLine(), | 'line' => $this->getLine(), | ||||
| 'char' => $this->getChar(), | 'char' => $this->getChar(), | ||||
| 'linterName' => $this->getLinterName(), | |||||
| 'code' => $this->getCode(), | 'code' => $this->getCode(), | ||||
| 'severity' => $this->getSeverity(), | 'severity' => $this->getSeverity(), | ||||
| 'name' => $this->getName(), | 'name' => $this->getName(), | ||||
| 'description' => $this->getDescription(), | 'description' => $this->getDescription(), | ||||
| 'original' => $this->getOriginalText(), | 'original' => $this->getOriginalText(), | ||||
| 'replacement' => $this->getReplacementText(), | 'replacement' => $this->getReplacementText(), | ||||
| 'granularity' => $this->getGranularity(), | 'granularity' => $this->getGranularity(), | ||||
| 'locations' => $this->getOtherLocations(), | 'locations' => $this->getOtherLocations(), | ||||
| 'bypassChangedLineFiltering' => $this->shouldBypassChangedLineFiltering(), | |||||
| ); | ); | ||||
| } | } | ||||
| public function getPath() { | |||||
| return $this->path; | |||||
| } | |||||
| public function setPath($path) { | public function setPath($path) { | ||||
| $this->path = $path; | $this->path = $path; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getPath() { | public function getLine() { | ||||
| return $this->path; | return $this->line; | ||||
| } | } | ||||
| public function setLine($line) { | public function setLine($line) { | ||||
| $this->line = $line; | $this->line = $line; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getLine() { | public function getChar() { | ||||
| return $this->line; | return $this->char; | ||||
| } | } | ||||
| public function setChar($char) { | public function setChar($char) { | ||||
| $this->char = $char; | $this->char = $char; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getChar() { | public function getLinterName() { | ||||
| return $this->char; | return $this->linterName; | ||||
| } | } | ||||
| public function setCode($code) { | public function setLinterName($linter_name) { | ||||
| $this->code = $code; | $this->linterName = $linter_name; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getCode() { | public function getCode() { | ||||
| return $this->code; | return $this->code; | ||||
| } | } | ||||
| public function setSeverity($severity) { | public function setCode($code) { | ||||
| $this->severity = $severity; | $this->code = $code; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getSeverity() { | public function getSeverity() { | ||||
| return $this->severity; | return $this->severity; | ||||
| } | } | ||||
| public function setName($name) { | public function setSeverity($severity) { | ||||
| $this->name = $name; | $this->severity = $severity; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getName() { | public function getName() { | ||||
| return $this->name; | return $this->name; | ||||
| } | } | ||||
| public function setDescription($description) { | public function setName($name) { | ||||
| $this->description = $description; | $this->name = $name; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getDescription() { | public function getDescription() { | ||||
| return $this->description; | return $this->description; | ||||
| } | } | ||||
| public function setOriginalText($original) { | public function setDescription($description) { | ||||
| $this->originalText = $original; | $this->description = $description; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getOriginalText() { | public function getOriginalText() { | ||||
| return $this->originalText; | return $this->originalText; | ||||
| } | } | ||||
| public function setReplacementText($replacement) { | public function setOriginalText($original) { | ||||
| $this->replacementText = $replacement; | $this->originalText = $original; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getReplacementText() { | public function getReplacementText() { | ||||
| return $this->replacementText; | return $this->replacementText; | ||||
| } | } | ||||
| /** | public function setReplacementText($replacement) { | ||||
| * @param dict Keys 'path', 'line', 'char', 'original'. | $this->replacementText = $replacement; | ||||
| */ | |||||
| public function setOtherLocations(array $locations) { | |||||
| assert_instances_of($locations, 'array'); | |||||
| $this->otherLocations = $locations; | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getOtherLocations() { | public function getGranularity() { | ||||
| return $this->otherLocations; | return $this->granularity; | ||||
| } | } | ||||
| public function isError() { | public function setGranularity($granularity) { | ||||
| return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_ERROR; | $this->granularity = $granularity; | ||||
| return $this; | |||||
| } | } | ||||
| public function isWarning() { | public function getOtherLocations() { | ||||
| return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_WARNING; | // TODO: This should probably be `list<ArcanistLintMessage>`. | ||||
| return $this->otherLocations; | |||||
| } | } | ||||
| public function isAutofix() { | public function setOtherLocations(array $locations) { | ||||
| return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_AUTOFIX; | assert_instances_of($locations, 'array'); | ||||
| $this->otherLocations = $locations; | |||||
| return $this; | |||||
| } | } | ||||
| public function hasFileContext() { | public function getObsolete() { | ||||
| return ($this->getLine() !== null); | return $this->obsolete; | ||||
| } | } | ||||
| public function setObsolete($obsolete) { | public function setObsolete($obsolete) { | ||||
| $this->obsolete = $obsolete; | $this->obsolete = $obsolete; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getObsolete() { | |||||
| return $this->obsolete; | |||||
| } | |||||
| public function isPatchable() { | public function isAutofix() { | ||||
| return ($this->getReplacementText() !== null) && | return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_AUTOFIX; | ||||
| ($this->getReplacementText() !== $this->getOriginalText()); | |||||
| } | } | ||||
| public function didApplyPatch() { | public function isError() { | ||||
| if ($this->appliedToDisk) { | return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_ERROR; | ||||
| return $this; | |||||
| } | |||||
| $this->appliedToDisk = true; | |||||
| foreach ($this->dependentMessages as $message) { | |||||
| $message->didApplyPatch(); | |||||
| } | |||||
| return $this; | |||||
| } | } | ||||
| public function isPatchApplied() { | public function isWarning() { | ||||
| return $this->appliedToDisk; | return $this->getSeverity() == ArcanistLintSeverity::SEVERITY_WARNING; | ||||
| } | } | ||||
| public function setGranularity($granularity) { | |||||
| $this->granularity = $granularity; | public function hasFileContext() { | ||||
| return $this; | return $this->getLine() !== null; | ||||
| } | } | ||||
| public function getGranularity() { | |||||
| return $this->granularity; | public function didApplyPatch() { | ||||
| if (!$this->appliedToDisk) { | |||||
| $this->appliedToDisk = true; | |||||
| } | } | ||||
| public function setDependentMessages(array $messages) { | |||||
| assert_instances_of($messages, __CLASS__); | |||||
| $this->dependentMessages = $messages; | |||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setBypassChangedLineFiltering($bypass_changed_lines) { | public function isPatchable() { | ||||
| $this->bypassChangedLineFiltering = $bypass_changed_lines; | return $this->getReplacementText() !== null && | ||||
| return $this; | $this->getReplacementText() !== $this->getOriginalText(); | ||||
| } | } | ||||
| public function shouldBypassChangedLineFiltering() { | public function isPatchApplied() { | ||||
| return $this->bypassChangedLineFiltering; | return $this->appliedToDisk; | ||||
| } | } | ||||
| } | } | ||||