Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support formatting from a text editor #168

Closed
lassik opened this issue Oct 18, 2023 · 1 comment
Closed

Support formatting from a text editor #168

lassik opened this issue Oct 18, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@lassik
Copy link

lassik commented Oct 18, 2023

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:

  • Read a manifest from standard input.
  • Write the formatted manifest to standard output.
  • Write any and all warning and error messages to standard error. (Not to standard output.)
  • Exit code is non-zero in case of error, zero if there were no errors.
  • If the exit code is non-zero, the caller will ignore everything you wrote to standard output.

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

lassik/emacs-format-all-the-code#243

lassik/emacs-format-all-the-code#240

@lassik lassik added the enhancement New feature or request label Oct 18, 2023
@jordanbreen28
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants