Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Feature request] support for Puppet #240

Open
rolandmas opened this issue Oct 13, 2023 · 3 comments
Open

[Feature request] support for Puppet #240

rolandmas opened this issue Oct 13, 2023 · 3 comments

Comments

@rolandmas
Copy link

It would be nice to support formatting Puppet code. The best formatter I found for that task is puppet-lint -f. I'd propose a pull request to add it, but unfortunately that tool doesn't work as a pipe/filter, it can only read a file and replace it with a fixed version. I could of course write a shell wrapper that reads stdin, saves it, applies puppet-lint, then prints the results to its stdout, but I guess a pure Lisp implementation would be cleaner. However, it goes beyond my skills…

@rolandmas
Copy link
Author

rolandmas commented Oct 15, 2023

I went on to write a wrapper script, which I attach in the hope it can be useful to someone.

Date: Sun, 15 Oct 2023 12:17:13 +0200
Subject: Add support for Puppet manifests

---
 format-all.el       | 10 +++++++++-
 puppet-lint-wrapper |  7 +++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 puppet-lint-wrapper

diff --git a/format-all.el b/format-all.el
index 77c9bc1..aa0cd81 100644
--- a/format-all.el
+++ b/format-all.el
@@ -63,6 +63,7 @@
 ;; - Perl (perltidy)
 ;; - PHP (prettier plugin)
 ;; - Protocol Buffers (clang-format)
+;; - Puppet (puppet-lint)
 ;; - PureScript (purty)
 ;; - Python (black, yapf)
 ;; - R (styler)
@@ -154,6 +155,7 @@
     ("Perl" perltidy)
     ("PHP" prettier)
     ("Protocol Buffer" clang-format)
+    ("Puppet" puppet-lint)
     ("PureScript" purty)
     ("Python" black)
     ("R" styler)
@@ -919,6 +921,12 @@ Consult the existing formatters for examples of BODY."
     (let ((ignore-file (format-all--locate-file ".prettierignore")))
       (when ignore-file (list "--ignore-path" ignore-file))))))
 
+(define-format-all-formatter puppet-lint
+  (:executable "puppet-lint-wrapper")
+  (:install "gem install --global puppet-lint")
+  (:languages "Puppet")
+  (:format (format-all--buffer-easy executable "-f")))
+
 (define-format-all-formatter purty
   (:executable "purty")
   (:install "npm install --global purty")
@@ -933,7 +941,7 @@ Consult the existing formatters for examples of BODY."
    (format-all--buffer-easy
     executable "format" "-stdin"
     (let ((ext (if (not (buffer-file-name)) ""
-                   (file-name-extension (buffer-file-name)))))
+                 (file-name-extension (buffer-file-name)))))
       (concat "." (if (equal ext "") "res" ext))))))
 
 (define-format-all-formatter rubocop
diff --git a/puppet-lint-wrapper b/puppet-lint-wrapper
new file mode 100644
index 0000000..842f01d
--- /dev/null
+++ b/puppet-lint-wrapper
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+t=$(mktemp)
+cat >$t
+puppet-lint -f $t | egrep -v "^(FIXED|WARNING|ERROR):"
+cat $t
+rm -f $t

@anarcat
Copy link

anarcat commented Oct 16, 2023

that looks pretty good! could you make a merge request out of this?

@rolandmas
Copy link
Author

@anarcat See #243

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants