Page MenuHomePhabricator

D12120.id30104.diff
No OneTemporary

D12120.id30104.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
@@ -89,6 +89,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',
@@ -289,6 +291,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,67 @@
+<?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() {
+ return 'go';
+ }
+ public function getInstallInstructions() {
+ return pht('Install Go vet using `go get golang.org/x/tools/cmd/vet`.');
+ }
+
+ public function shouldExpectCommandErrors() {
+ return true;
+ }
+
+ protected function canCustomizeLintSeverities() {
+ return true;
+ }
+
+ protected function getMandatoryFlags() {
+ return ['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/', null, 'go');
+ }
+
+}
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
@@ -28,7 +28,7 @@
*/
public function executeTestsInDirectory(
$root,
- ArcanistLinter $linter = null) {
+ ArcanistLinter $linter = null, $temp_file_suffix = null) {
if (!$linter) {
$linter = $this->getLinter();
@@ -41,7 +41,7 @@
$test_count = 0;
foreach ($files as $file) {
- $this->lintFile($root.$file, $linter);
+ $this->lintFile($root.$file, $linter, $temp_file_suffix);
$test_count++;
}
@@ -50,7 +50,8 @@
pht('Expected to find some .lint-test tests in directory %s!', $root));
}
- private function lintFile($file, ArcanistLinter $linter) {
+ private function lintFile($file, ArcanistLinter $linter,
+ $temp_file_suffix = null) {
$linter = clone $linter;
$contents = Filesystem::readFile($file);
@@ -91,6 +92,9 @@
try {
$tmp = new TempFile($basename);
+ if ($temp_file_suffix !== null) {
+ $tmp .= '.'.$temp_file_suffix;
+ }
Filesystem::writeFile($tmp, $data);
$full_path = (string)$tmp;
diff --git a/src/lint/linter/__tests__/coffeelint/duplicate_key.lint-test b/src/lint/linter/__tests__/coffeelint/duplicate_key.lint-test
--- a/src/lint/linter/__tests__/coffeelint/duplicate_key.lint-test
+++ b/src/lint/linter/__tests__/coffeelint/duplicate_key.lint-test
@@ -14,5 +14,5 @@
config =
foo: 1
~~~~~~~~~~
-error:8:
+error:7:
error:9:
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,9 @@
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("%d", 1)
+}
+~~~~~~~~~~
+warning:6:

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 1:34 PM (14 h, 5 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6782906
Default Alt Text
D12120.id30104.diff (5 KB)

Event Timeline