Page MenuHomePhabricator

D11798.diff
No OneTemporary

D11798.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
@@ -12,6 +12,7 @@
'ArcanistAliasWorkflow' => 'workflow/ArcanistAliasWorkflow.php',
'ArcanistAmendWorkflow' => 'workflow/ArcanistAmendWorkflow.php',
'ArcanistAnoidWorkflow' => 'workflow/ArcanistAnoidWorkflow.php',
+ 'ArcanistAnsibleLintLinter' => 'lint/linter/ArcanistAnsibleLintLinter.php',
'ArcanistBackoutWorkflow' => 'workflow/ArcanistBackoutWorkflow.php',
'ArcanistBaseCommitParser' => 'parser/ArcanistBaseCommitParser.php',
'ArcanistBaseCommitParserTestCase' => 'parser/__tests__/ArcanistBaseCommitParserTestCase.php',
@@ -224,6 +225,7 @@
'ArcanistAliasWorkflow' => 'ArcanistWorkflow',
'ArcanistAmendWorkflow' => 'ArcanistWorkflow',
'ArcanistAnoidWorkflow' => 'ArcanistWorkflow',
+ 'ArcanistAnsibleLintLinter' => 'ArcanistExternalLinter',
'ArcanistBackoutWorkflow' => 'ArcanistWorkflow',
'ArcanistBaseCommitParserTestCase' => 'ArcanistTestCase',
'ArcanistBaseUnitTestEngine' => 'ArcanistUnitTestEngine',
diff --git a/src/lint/linter/ArcanistAnsibleLintLinter.php b/src/lint/linter/ArcanistAnsibleLintLinter.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/ArcanistAnsibleLintLinter.php
@@ -0,0 +1,99 @@
+<?php
+
+final class ArcanistAnsibleLintLinter extends ArcanistExternalLinter {
+ public function getInfoName() {
+ return 'Ansible-Lint';
+ }
+
+ public function getInfoURI() {
+ return 'https://pypi.python.org/pypi/ansible-lint';
+ }
+
+ public function getInfoDescription() {
+ return pht(
+ 'Uses `ansible-lint` to check Ansible playbooks for practices '.
+ 'and behaviour that could potentially be improved.');
+ }
+
+ public function getLinterName() {
+ return 'ansible-lint';
+ }
+
+ public function getLinterConfigurationName() {
+ return 'ansible-lint';
+ }
+
+ public function getDefaultBinary() {
+ return 'ansible-lint';
+ }
+
+ /*
+ protected function getDefaultFlags() {
+ return ['-q',];
+ }
+ */
+
+ public function getInstallInstructions() {
+ return pht('Install ansible-lint using `pip install ansible-lint`.');
+ }
+
+ public function shouldExpectCommandErrors() {
+ return true;
+ }
+
+ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+ /* example output:
+[ANSIBLE0002] Trailing whitespace
+/home/michel/tools/playbooks/roles/gradle/tasks/main.yml:34
+
+
+[ANSIBLE0006] git used in place of git module
+/home/michel/tools/playbooks/roles/migrate-repos/tasks/main.yml:0
+Task/Handler: tv -- check origin path
+
+ */
+ $lints = preg_split('/\[/', $stdout, -1, PREG_SPLIT_NO_EMPTY);
+
+ $messages = array();
+
+ foreach ($lints as $lint) {
+ $matches = null;
+ $regexp = '/^(\S+)\]\h+(.+)\n(.+):(\d+)\n(.*)$/s';
+ if (!preg_match($regexp, $lint, $matches)) {
+ var_dump($lint);
+ continue;
+ }
+ foreach ($matches as $key => $match) {
+ $matches[$key] = trim($match);
+ }
+
+ /* bug in ansible-lint fixed in pull request #46:
+ https://github.com/willthames/ansible-lint/pull/46
+
+ if ($matches[3] == 0) {
+ continue;
+ }
+ */
+
+ $message = new ArcanistLintMessage();
+ $message->setPath($path);
+ $message->setLine($matches[4]);
+ $message->setChar(1);
+
+ $message->setCode($matches[1]);
+ $message->setName($matches[2]);
+ $message->setDescription($matches[3]);
+ // $message->setDescription("Hello");
+ // $message->setSeverity($this->getLintMessageSeverity($matches[1]));
+ $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING);
+
+ $messages[] = $message;
+ }
+
+ if ($err && !$messages) {
+ return false;
+ }
+
+ return $messages;
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Mar 17, 10:33 PM (3 d, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7689747
Default Alt Text
D11798.diff (3 KB)

Event Timeline