Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15531094
D8418.id19991.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D8418.id19991.diff
View Options
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
@@ -122,6 +122,8 @@
'ArcanistPhutilTestTerminatedException' => 'unit/engine/phutil/testcase/ArcanistPhutilTestTerminatedException.php',
'ArcanistPhutilXHPASTLinter' => 'lint/linter/ArcanistPhutilXHPASTLinter.php',
'ArcanistPhutilXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php',
+ 'ArcanistPuppetLintLinter' => 'lint/linter/ArcanistPuppetLintLinter.php',
+ 'ArcanistPuppetLintLinterTestCase' => 'lint/linter/__tests__/ArcanistPuppetLintLinterTestCase.php',
'ArcanistPyFlakesLinter' => 'lint/linter/ArcanistPyFlakesLinter.php',
'ArcanistPyLintLinter' => 'lint/linter/ArcanistPyLintLinter.php',
'ArcanistRepositoryAPI' => 'repository/api/ArcanistRepositoryAPI.php',
@@ -272,6 +274,8 @@
'ArcanistPhutilTestTerminatedException' => 'Exception',
'ArcanistPhutilXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
'ArcanistPhutilXHPASTLinterTestCase' => 'ArcanistArcanistLinterTestCase',
+ 'ArcanistPuppetLintLinter' => 'ArcanistExternalLinter',
+ 'ArcanistPuppetLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPyFlakesLinter' => 'ArcanistLinter',
'ArcanistPyLintLinter' => 'ArcanistLinter',
'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
diff --git a/src/lint/linter/ArcanistPuppetLintLinter.php b/src/lint/linter/ArcanistPuppetLintLinter.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/ArcanistPuppetLintLinter.php
@@ -0,0 +1,111 @@
+<?php
+
+/**
+ * Uses "puppet-lint" to detect style errors in Puppet manifests.
+ * To use this linter, you must install puppet-lint
+ * http://puppet-lint.com
+ *
+ * Optional configurations in .arcconfig:
+ *
+ * lint.puppetlint.prefix
+ * lint.puppetlint.bin
+ */
+final class ArcanistPuppetLintLinter extends ArcanistExternalLinter {
+
+ public function getLinterName() {
+ return 'PuppetLint';
+ }
+
+ public function getInstallInstructions() {
+ return pht('Install puppet-lint with `gem install puppet-lint`.');
+ }
+
+ public function getLinterConfigurationName() {
+ return 'puppetlint';
+ }
+
+ public function shouldExpectCommandErrors() {
+ return true;
+ }
+
+ public function getMandatoryFlags() {
+ return '--log-format %{linenumber}:%{column}:%{kind}:%{message}';
+ }
+
+ public function getDefaultBinary() {
+ $config = $this->getEngine()->getConfigurationManager();
+ $prefix = $config->getConfigFromAnySource('lint.puppetlint.prefix');
+ $bin = $config->getConfigFromAnySource('lint.puppetlint.bin');
+
+ if ($bin === null) {
+ $bin = 'puppet-lint';
+ }
+
+ if ($prefix !== null) {
+ $bin = $prefix.'/'.$bin;
+
+ if (!Filesystem::pathExists($bin)) {
+ throw new ArcanistUsageException(
+ "Unable to find puppet-lint binary in a specified directory. Make sure".
+ "that 'lint.puppetlint.prefix' and 'lint.puppetlint.bin' keys are set".
+ "correctly.");
+ }
+ }
+
+ if (!Filesystem::binaryExists($bin)) {
+ throw new ArcanistUsageException(
+ "Puppet-lint does not appear to be installed on this system. Install".
+ "it (e.g., with 'gem install puppet-lint') or configure".
+ "'lint.puppetlint.prefix' in your .arcconfig to point to the directory".
+ "where it resides.");
+ }
+
+ return $bin;
+ }
+
+ protected function getDefaultMessageSeverity($code) {
+ switch ($code) {
+ case 'warning':
+ return ArcanistLintSeverity::SEVERITY_WARNING;
+ break;
+ case 'fixed':
+ return ArcanistLintSeverity::SEVERITY_AUTOFIX;
+ break;
+ case 'error':
+ // Default to error
+ default:
+ return ArcanistLintSeverity::SEVERITY_ERROR;
+ break;
+ }
+ }
+
+ protected function parseLinterOutput($path, $err, $stdout, $stderr) {
+ if (!$stdout) {
+ return array();
+ }
+
+ $lines = phutil_split_lines($stdout, $retain_endings = false);
+
+ $messages = array();
+ foreach ($lines as $line) {
+ list($line, $column, $code, $desc) = explode(':', $line);
+ $message = new ArcanistLintMessage();
+ $message->setPath($path);
+ $message->setLine($line);
+ $message->setChar($column);
+ $message->setCode($code);
+ $message->setDescription($desc);
+ $message->setSeverity($this->getLintMessageSeverity($code));
+
+ $messages[] = $message;
+ }
+
+ if ($err && !$messages) {
+ return false;
+ }
+
+ return $messages;
+
+ }
+
+}
diff --git a/src/lint/linter/__tests__/ArcanistPuppetLintLinterTestCase.php b/src/lint/linter/__tests__/ArcanistPuppetLintLinterTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/ArcanistPuppetLintLinterTestCase.php
@@ -0,0 +1,12 @@
+<?php
+
+final class ArcanistPuppetLintLinterTestCase extends
+ ArcanistArcanistLinterTestCase {
+
+ public function testPuppetLintLint() {
+ return $this->executeTestsInDirectory(
+ dirname(__FILE__).'/puppet-lint/',
+ new ArcanistPuppetLintLinter());
+ }
+
+}
diff --git a/src/lint/linter/__tests__/puppet-lint/basics.lint-test b/src/lint/linter/__tests__/puppet-lint/basics.lint-test
new file mode 100644
--- /dev/null
+++ b/src/lint/linter/__tests__/puppet-lint/basics.lint-test
@@ -0,0 +1,9 @@
+class test {
+ $a = 'abc';
+ b
+}
+
+~~~~~~~~~~
+warning:1:1
+error:1:7
+error:3:4
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 24, 9:37 AM (14 h, 20 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7590252
Default Alt Text
D8418.id19991.diff (5 KB)
Attached To
Mode
D8418: Add puppet-lint linter
Attached
Detach File
Event Timeline
Log In to Comment