Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/ArcanistAnsibleLintLinter.php
- This file was added.
| <?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.'); | |||||
joshuaspence: Prefer to write this as `pht('Uses ```%s``` to check Ansible playbooks for practices and… | |||||
| } | |||||
| public function getLinterName() { | |||||
| return 'ansible-lint'; | |||||
joshuaspenceUnsubmitted Done Inline ActionsThese are conventionally uppercase, so perhaps ANSIBLE? joshuaspence: These are conventionally uppercase, so perhaps `ANSIBLE`? | |||||
| } | |||||
| public function getLinterConfigurationName() { | |||||
| return 'ansible-lint'; | |||||
| } | |||||
| public function getDefaultBinary() { | |||||
| return 'ansible-lint'; | |||||
| } | |||||
| /* | |||||
| protected function getDefaultFlags() { | |||||
| return ['-q',]; | |||||
| } | |||||
| */ | |||||
joshuaspenceUnsubmitted Done Inline ActionsRemove commented-out code. joshuaspence: Remove commented-out code. | |||||
| public function getInstallInstructions() { | |||||
| return pht('Install ansible-lint using `pip install ansible-lint`.'); | |||||
| } | |||||
joshuaspenceUnsubmitted Done Inline ActionsPrefer to write this as pht('Install ansible-lint using `%s`.', 'pip install ansible-lint'). joshuaspence: Prefer to write this as `pht('Install ansible-lint using ```%s```.', 'pip install ansible… | |||||
| public function shouldExpectCommandErrors() { | |||||
| return true; | |||||
| } | |||||
joshuaspenceUnsubmitted Done Inline ActionsThis is the default implementation, don't bother implementing this explicitly. joshuaspence: This is the default implementation, don't bother implementing this explicitly. | |||||
| 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 | |||||
| */ | |||||
joshuaspenceUnsubmitted Done Inline ActionsDrop this. joshuaspence: Drop this. | |||||
| $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); | |||||
joshuaspenceUnsubmitted Done Inline ActionsStray debugging code? joshuaspence: Stray debugging code? | |||||
| 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; | |||||
| } | |||||
| */ | |||||
joshuaspenceUnsubmitted Done Inline ActionsThis pull request has been merged, so presumably this code can be activated now? joshuaspence: This pull request has been merged, so presumably this code can be activated now? | |||||
| $message = new ArcanistLintMessage(); | |||||
| $message->setPath($path); | |||||
| $message->setLine($matches[4]); | |||||
| $message->setChar(1); | |||||
joshuaspenceUnsubmitted Done Inline ActionsDon't set a character offset if it's wrong. joshuaspence: Don't set a character offset if it's wrong. | |||||
| $message->setCode($matches[1]); | |||||
| $message->setName($matches[2]); | |||||
| $message->setDescription($matches[3]); | |||||
| // $message->setDescription("Hello"); | |||||
| // $message->setSeverity($this->getLintMessageSeverity($matches[1])); | |||||
joshuaspenceUnsubmitted Done Inline ActionsRemove commented out code joshuaspence: Remove commented out code | |||||
| $message->setSeverity(ArcanistLintSeverity::SEVERITY_WARNING); | |||||
joshuaspenceUnsubmitted Done Inline ActionsPrefer to use getLintMessageSeverity so that the severity is customizable. joshuaspence: Prefer to use `getLintMessageSeverity` so that the severity is customizable. | |||||
| $messages[] = $message; | |||||
| } | |||||
| if ($err && !$messages) { | |||||
| return false; | |||||
| } | |||||
| return $messages; | |||||
| } | |||||
| } | |||||
Prefer to write this as pht('Uses `%s` to check Ansible playbooks for practices and behaviour that could potentially be improved.', 'ansible-lint').
Also, use US English (so "behavior" instead of "behaviour").