mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Add an ArcanistGoLintLinter
.
Summary: Create bindings for `golint` as an external linter. Test Plan: Wrote and executed unit tests. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: epriestley, Korvin Differential Revision: https://secure.phabricator.com/D9246
This commit is contained in:
parent
85b8b2e5f8
commit
042aa2ee38
4 changed files with 94 additions and 0 deletions
|
@ -80,6 +80,8 @@ phutil_register_library_map(array(
|
|||
'ArcanistGetConfigWorkflow' => 'workflow/ArcanistGetConfigWorkflow.php',
|
||||
'ArcanistGitAPI' => 'repository/api/ArcanistGitAPI.php',
|
||||
'ArcanistGitHookPreReceiveWorkflow' => 'workflow/ArcanistGitHookPreReceiveWorkflow.php',
|
||||
'ArcanistGoLintLinter' => 'lint/linter/ArcanistGoLintLinter.php',
|
||||
'ArcanistGoLintLinterTestCase' => 'lint/linter/__tests__/ArcanistGoLintLinterTestCase.php',
|
||||
'ArcanistHelpWorkflow' => 'workflow/ArcanistHelpWorkflow.php',
|
||||
'ArcanistHgClientChannel' => 'hgdaemon/ArcanistHgClientChannel.php',
|
||||
'ArcanistHgProxyClient' => 'hgdaemon/ArcanistHgProxyClient.php',
|
||||
|
@ -258,6 +260,8 @@ phutil_register_library_map(array(
|
|||
'ArcanistGetConfigWorkflow' => 'ArcanistBaseWorkflow',
|
||||
'ArcanistGitAPI' => 'ArcanistRepositoryAPI',
|
||||
'ArcanistGitHookPreReceiveWorkflow' => 'ArcanistBaseWorkflow',
|
||||
'ArcanistGoLintLinter' => 'ArcanistExternalLinter',
|
||||
'ArcanistGoLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||
'ArcanistHelpWorkflow' => 'ArcanistBaseWorkflow',
|
||||
'ArcanistHgClientChannel' => 'PhutilProtocolChannel',
|
||||
'ArcanistHgServerChannel' => 'PhutilProtocolChannel',
|
||||
|
|
60
src/lint/linter/ArcanistGoLintLinter.php
Normal file
60
src/lint/linter/ArcanistGoLintLinter.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
final class ArcanistGoLintLinter extends ArcanistExternalLinter {
|
||||
|
||||
public function getInfoName() {
|
||||
return 'Golint';
|
||||
}
|
||||
|
||||
public function getInfoURI() {
|
||||
return 'https://github.com/golang/lint';
|
||||
}
|
||||
|
||||
public function getInfoDescription() {
|
||||
return pht('Golint is a linter for Go source code.');
|
||||
}
|
||||
|
||||
public function getLinterName() {
|
||||
return 'GOLINT';
|
||||
}
|
||||
|
||||
public function getLinterConfigurationName() {
|
||||
return 'golint';
|
||||
}
|
||||
|
||||
public function getDefaultBinary() {
|
||||
return 'golint';
|
||||
}
|
||||
|
||||
public function getInstallInstructions() {
|
||||
return pht('Install Golint using `go get github.com/golang/lint/golint`.');
|
||||
}
|
||||
|
||||
protected function canCustomizeLintSeverities() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function parseLinterOutput($path, $err, $stdout, $stderr) {
|
||||
$lines = phutil_split_lines($stdout, false);
|
||||
|
||||
$messages = array();
|
||||
foreach ($lines as $line) {
|
||||
$matches = explode(':', $line, 4);
|
||||
|
||||
if (count($matches) === 4) {
|
||||
$message = new ArcanistLintMessage();
|
||||
$message->setPath($path);
|
||||
$message->setLine($matches[1]);
|
||||
$message->setChar($matches[2]);
|
||||
$message->setCode($this->getLinterName());
|
||||
$message->setDescription(ucfirst(trim($matches[3])));
|
||||
$message->setSeverity(ArcanistLintSeverity::SEVERITY_ADVICE);
|
||||
|
||||
$messages[] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
}
|
12
src/lint/linter/__tests__/ArcanistGoLintLinterTestCase.php
Normal file
12
src/lint/linter/__tests__/ArcanistGoLintLinterTestCase.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
final class ArcanistGoLintLinterTestCase
|
||||
extends ArcanistArcanistLinterTestCase {
|
||||
|
||||
public function testGoLintLinter() {
|
||||
$this->executeTestsInDirectory(
|
||||
dirname(__FILE__).'/golint/',
|
||||
new ArcanistGoLintLinter());
|
||||
}
|
||||
|
||||
}
|
18
src/lint/linter/__tests__/golint/1.lint-test
Normal file
18
src/lint/linter/__tests__/golint/1.lint-test
Normal file
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"rand"
|
||||
)
|
||||
|
||||
type Exported string
|
||||
|
||||
func main() {
|
||||
if rand.Intn(10) > 5 {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
~~~~~~~~~~
|
||||
advice:7:6
|
||||
advice:12:12
|
Loading…
Reference in a new issue