Page MenuHomePhabricator

D12120.id30555.diff
No OneTemporary

D12120.id30555.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -86,6 +86,8 @@
'ArcanistGoLintLinterTestCase' => 'lint/linter/__tests__/ArcanistGoLintLinterTestCase.php',
'ArcanistGoTestResultParser' => 'unit/parser/ArcanistGoTestResultParser.php',
'ArcanistGoTestResultParserTestCase' => 'unit/parser/__tests__/ArcanistGoTestResultParserTestCase.php',
+ 'ArcanistGoVetLinter' => 'lint/linter/ArcanistGoVetLinter.php',
+ 'ArcanistGoVetLinterTestCase' => 'lint/linter/__tests__/ArcanistGoVetLinterTestCase.php',
'ArcanistHLintLinter' => 'lint/linter/ArcanistHLintLinter.php',
'ArcanistHLintLinterTestCase' => 'lint/linter/__tests__/ArcanistHLintLinterTestCase.php',
'ArcanistHelpWorkflow' => 'workflow/ArcanistHelpWorkflow.php',
@@ -279,6 +281,8 @@
'ArcanistGoLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistGoTestResultParser' => 'ArcanistTestResultParser',
'ArcanistGoTestResultParserTestCase' => 'ArcanistTestCase',
+ 'ArcanistGoVetLinter' => 'ArcanistExternalLinter',
+ 'ArcanistGoVetLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistHLintLinter' => 'ArcanistExternalLinter',
'ArcanistHLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistHelpWorkflow' => 'ArcanistWorkflow',
diff --git a/src/lint/linter/ArcanistGoVetLinter.php b/src/lint/linter/ArcanistGoVetLinter.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/ArcanistGoVetLinter.php
@@ -0,0 +1,81 @@
+<?php
+
+final class ArcanistGoVetLinter extends ArcanistExternalLinter {
+
+ public function getInfoName() {
+ return 'Go Vet';
+ }
+
+ public function getInfoURI() {
+ return 'https://godoc.org/golang.org/x/tools/cmd/vet';
+ }
+
+ public function getInfoDescription() {
+ return pht(
+ 'Vet examines Go source code and reports suspicious constructs.');
+ }
+
+ public function getLinterName() {
+ return 'GOVET';
+ }
+
+ public function getLinterConfigurationName() {
+ return 'govet';
+ }
+
+ public function getDefaultBinary() {
+ $binary = 'go';
+ if (Filesystem::binaryExists($binary)) {
+ // Vet is only accessible through 'go vet' or 'go tool vet'
+ // Let's manually try to find out if it's installed.
+ list($err, $stdout, $stderr) = exec_manual('go tool vet');
+ if ($err === 3) {
+ throw new ArcanistMissingLinterException(
+ sprintf(
+ "%s\n%s",
+ pht(
+ 'Unable to locate "go vet" to run linter %s. You may need '.
+ 'to install the binary, or adjust your linter configuration.',
+ get_class($this)),
+ pht(
+ 'TO INSTALL: %s',
+ $this->getInstallInstructions())));
+ }
+ }
+
+ return $binary;
+ }
+
+ public function getInstallInstructions() {
+ return pht(
+ 'Install Go vet using `%s`.',
+ 'go get golang.org/x/tools/cmd/vet');
+ }
+
+ protected function getMandatoryFlags() {
+ return array('tool', 'vet');
+ }
+
+ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+ $lines = phutil_split_lines($stderr, false);
+
+ $messages = array();
+ foreach ($lines as $line) {
+ $matches = explode(':', $line, 3);
+
+ if (count($matches) === 3) {
+ $message = new ArcanistLintMessage();
+ $message->setPath($path);
+ $message->setLine($matches[1]);
+ $message->setCode($this->getLinterName());
+ $message->setDescription(ucfirst(trim($matches[2])));
+ $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
+
+ $messages[] = $message;
+ }
+ }
+
+ return $messages;
+ }
+
+}
diff --git a/src/lint/linter/__tests__/ArcanistGoVetLinterTestCase.php b/src/lint/linter/__tests__/ArcanistGoVetLinterTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/ArcanistGoVetLinterTestCase.php
@@ -0,0 +1,9 @@
+<?php
+
+final class ArcanistGoVetLinterTestCase extends ArcanistExternalLinterTestCase {
+
+ public function testLinter() {
+ $this->executeTestsInDirectory(dirname(__FILE__).'/govet/');
+ }
+
+}
diff --git a/src/lint/linter/__tests__/ArcanistLinterTestCase.php b/src/lint/linter/__tests__/ArcanistLinterTestCase.php
--- a/src/lint/linter/__tests__/ArcanistLinterTestCase.php
+++ b/src/lint/linter/__tests__/ArcanistLinterTestCase.php
@@ -80,6 +80,7 @@
'path' => 'optional string',
'mode' => 'optional string',
'stopped' => 'optional bool',
+ 'file_extension' => 'optional string',
));
$exception = null;
@@ -89,7 +90,11 @@
$caught_exception = false;
try {
+ $file_extension = idx($config, 'file_extension', '');
$tmp = new TempFile($basename);
+ if (!empty($file_extension)) {
+ $tmp .= '.'.$file_extension;
+ }
Filesystem::writeFile($tmp, $data);
$full_path = (string)$tmp;
diff --git a/src/lint/linter/__tests__/govet/fmt.lint-test b/src/lint/linter/__tests__/govet/fmt.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/govet/fmt.lint-test
@@ -0,0 +1,12 @@
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("%d", 1)
+}
+~~~~~~~~~~
+warning:6:
+~~~~~~~~~~
+~~~~~~~~~~
+{"file_extension": "go"}

File Metadata

Mime Type
text/plain
Expires
Sun, May 12, 4:36 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6289096
Default Alt Text
D12120.id30555.diff (5 KB)

Event Timeline