puppetlabs / puppet-lint

Check that your Puppet manifests conform to the style guide
https://puppetlabs.github.io/puppet-lint/
MIT License
18 stars 12 forks source link

Support formatting from a text editor #168

Closed lassik closed 4 months ago

lassik commented 8 months ago

Use Case

I maintain an Emacs package that can format source code in 50+ languages by calling out to external programs.

We'd like to call puppet-lint to format a file as it is being edited. A common use case (but not the only one) is to format on save.

Editor users should be able to format both saved and unsaved files.

Describe the Solution You Would Like

The robust way to call formatters from editors is to use stdin, stdout, and stderr. Using temporary files is messy and not reliable.

The support we would need from puppet-lint is a way to call it like this:

puppet-lint --format --stdin <input-file >output-file

Specifically:

I do not use Puppet myself, so you know better than I what specific fixes the --format flag should do to the manifest. I assume it should do a subset of what --fix now does.

The precise set of command line flags (and what their names are) does not matter to us. We can easily use whatever flags you prefer, as long as the functionality is as above. --format --stdin is just a suggestion.

Describe Alternatives You've Considered

#! /bin/sh
t=$(mktemp)
cat >$t
puppet-lint --fix $t | egrep -v "^(FIXED|WARNING|ERROR):"
cat $t
rm -f $t

Additional Context

https://github.com/lassik/emacs-format-all-the-code/pull/243

https://github.com/lassik/emacs-format-all-the-code/issues/240

jordanbreen28 commented 4 months ago

@lassik puppet-editor-services, which is our puppet language server, should fit your needs for this. I'll go ahead and close, if this isn't suitable - please do re-open!