Summary: Ref T9145. Fixes T9316. We now require "name" and "code" has a maximum length (currently, this is 32, but the next diff will raise it to 128).
Test Plan:
- Installed PHPCS.
- Hit both the "name" and "code" issues.
- Applied this patch.
- Got better errors sooner.
Reviewers: chad
Reviewed By: chad
Subscribers: aik099
Maniphest Tasks: T9145, T9316
Differential Revision: https://secure.phabricator.com/D14165
}
public function setCode($code) {
+ $code = (string)$code;
+
+ $maximum_bytes = 128;
+ $actual_bytes = strlen($code);
+
+ if ($actual_bytes > $maximum_bytes) {
+ throw new Exception(
+ pht(
+ 'Parameter ("%s") passed to "%s" when constructing a lint message '.
+ 'must be a scalar with a maximum string length of %s bytes, but is '.
+ '%s bytes in length.',
+ $code,
+ 'setCode()',
+ new PhutilNumber($maximum_bytes),
+ new PhutilNumber($actual_bytes)));
+ }
+
$this->code = $code;
return $this;
}
foreach ($runnable as $linter) {
foreach ($linter->getLintMessages() as $message) {
+ $this->validateLintMessage($linter, $message);
+
if (!$this->isSeverityEnabled($message->getSeverity())) {
continue;
}
$this->endLintServiceCall($call_id);
}
+ private function validateLintMessage(
+ ArcanistLinter $linter,
+ ArcanistLintMessage $message) {
+
+ $name = $message->getName();
+ if (!strlen($name)) {
+ throw new Exception(
+ pht(
+ 'Linter "%s" generated a lint message that is invalid because it '.
+ 'does not have a name. Lint messages must have a name.',
+ get_class($linter)));
+ }
+ }
}
$prefix = 'W';
}
- $code = 'PHPCS.'.$prefix.'.'.$child->getAttribute('source');
-
- $message = new ArcanistLintMessage();
- $message->setPath($path);
- $message->setLine($child->getAttribute('line'));
- $message->setChar($child->getAttribute('column'));
- $message->setCode($code);
- $message->setDescription($child->nodeValue);
- $message->setSeverity($this->getLintMessageSeverity($code));
+ $source = $child->getAttribute('source');
+ $code = 'PHPCS.'.$prefix.'.'.$source;
+
+ $message = id(new ArcanistLintMessage())
+ ->setPath($path)
+ ->setName($source)
+ ->setLine($child->getAttribute('line'))
+ ->setChar($child->getAttribute('column'))
+ ->setCode($code)
+ ->setDescription($child->nodeValue)
+ ->setSeverity($this->getLintMessageSeverity($code));
$messages[] = $message;
}