You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there doesn't seem to be any way to automatically format a Pkl file. This means that we cannot enforce a standard style when collaborating in a team, nor automatically flag violations in PRs.
Proposed Solution
Something like pkl format, replicating the CLI of Prettier. Examples:
# Take in a file from stdin, and output it as formatted Pkl code to stdout
$ pkl format <<EOF
> foo { bar = 1; baz = 2 }
> EOFfoo { bar = 1 baz = 2}
# Take a filename, read its contents and output it as formatted Pkl code to stdout
$ echo"foo { bar = 1; baz = 2 }"> foo.pkl
$ pkl format foo.pklfoo { bar = 1 baz = 2}
# Take a filename, read its contents and write it as formatted Pkl code to the specified file
$ pkl format foo.pkl --output=formatted.pkl # or -o
$ cat formatted.pklfoo { bar = 1 baz = 2}
# Take one or more filenames, and exit with 0 if it is correctly formatted, or 1 otherwise
$ pkl format --check formatted.pkl;echo$?0
$ pkl format --check foo.pkl;echo$?Error: foo.pkl is not correctly formatted1
$ pkl format --check foo.pkl formatted.pkl;echo$?Error: foo.pkl is not correctly formatted1
# Take one or more filenames, format them and write to the original files
$ pkl format --write foo.pkl formatted.pklFormatted foo.pklformatted.pkl was already formatted
$ cat foo.pklfoo { bar = 1 baz = 2}
Open Questions
Should it be configurable? (I'm personally fond of the "nobody's favorite" approach to code formatting lately.)
When to use multiple lines, and when to use a single line with ; separators?
Default indentation width? (Suggestion: 2 as used in the documentation)
Tabs or spaces? (Suggestion: Spaces as used in the documentation)
there doesn't seem to be any way to automatically format a Pkl file
This isn't technically true; pkl-intellij has a formatter. Sadly, that's far too deeply integrated with the IDE SDKs to use in CI and VCS hooks and such.
The current front-end is slightly too deeply integrated with the interpreter. We're working on improving that, so that this kind of tool is easier to build/maintain. It's certainly on our radar.
Problem Statement
Currently, there doesn't seem to be any way to automatically format a Pkl file. This means that we cannot enforce a standard style when collaborating in a team, nor automatically flag violations in PRs.
Proposed Solution
Something like
pkl format
, replicating the CLI of Prettier. Examples:Open Questions
;
separators?Relevant Links
Discussion in February: #174
The text was updated successfully, but these errors were encountered: