Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15413132
D14165.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D14165.diff
View Options
diff --git a/src/lint/ArcanistLintMessage.php b/src/lint/ArcanistLintMessage.php
--- a/src/lint/ArcanistLintMessage.php
+++ b/src/lint/ArcanistLintMessage.php
@@ -90,6 +90,23 @@
}
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;
}
diff --git a/src/lint/engine/ArcanistLintEngine.php b/src/lint/engine/ArcanistLintEngine.php
--- a/src/lint/engine/ArcanistLintEngine.php
+++ b/src/lint/engine/ArcanistLintEngine.php
@@ -217,6 +217,8 @@
foreach ($runnable as $linter) {
foreach ($linter->getLintMessages() as $message) {
+ $this->validateLintMessage($linter, $message);
+
if (!$this->isSeverityEnabled($message->getSeverity())) {
continue;
}
@@ -598,5 +600,18 @@
$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)));
+ }
+ }
}
diff --git a/src/lint/linter/ArcanistPhpcsLinter.php b/src/lint/linter/ArcanistPhpcsLinter.php
--- a/src/lint/linter/ArcanistPhpcsLinter.php
+++ b/src/lint/linter/ArcanistPhpcsLinter.php
@@ -109,15 +109,17 @@
$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;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 20, 5:06 PM (10 h, 26 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7713481
Default Alt Text
D14165.diff (2 KB)
Attached To
Mode
D14165: Improve validation of 'name' and 'code' parameters for lint messages
Attached
Detach File
Event Timeline
Log In to Comment