Skip to content

Support formatting from a text editor #168

@lassik

Description

@lassik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions