-
Notifications
You must be signed in to change notification settings - Fork 755
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
Add formatter for .talon files to pre-commit #947
Conversation
This appears to remove all empty lines from .talon files, which I'm strongly against - it should be possible to separate commands into groups by using empty lines. It also appears to make all single-line commands into multi-line-with-indent, which I also dislike. I'd be okay with doing this for long lines (and/or collapsing commands into a single line when it would be short enough). |
That’s just the default. I've set a max line width of 80 so |
What do you feel should happen with blank lines? |
I would argue that any sequence of blank lines should be collapsed into a single blank line. And any whitespace on the blank line should be removed |
Super minor, but it would be nice if comments had a space after the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if empty lines were simply left alone (with whitespace removed), but combining adjacent empty lines would also be ok.
I'm against changing comments by adding a leading space, though. Comments are for expressing human intent so I think that autoformatters should leave them alone.
The PR looks much better now that it tries to put things on a single line where possible. It is removing the nice horizontal alignment some .talon files have, though. I remember there was some discussion on the corresponding issue of the right way to do this to avoid large diffs - how does talonfmt handle alignment?
I think it's pretty common for autoformatters to collapse adjacent empty lines, unless the spec calls for them (eg before a function in Python) One place I'd be tempted to remove empty lines is before / after the I would also be tempted to remove empty lines if they appear after the rule but before the body of a command
I guess I don't feel too strongly here. I'm pretty sure both other autoformatters that we use do this, though. And I'm not sure I see what intent one would be expressing by not including a space between the But again, I don't feel strongly, and it's easier to leave them untouched |
@pokey @rntz What about "1 blank line is left alone, 2 or more blank lines become 2 blank lines" at the top level, but all blank lines in the context header, after the "-", and at the start of a command body are removed? That way you can group commands but there's still some consistency. |
@rntz I think that while all code formatting expresses human intent, the purpose of a formatter is to enforce some measure of consistency. However, I've added a "--no-format-comments" flag, so we can at least not hardcode this behaviour. |
I think the best option would be to use, e.g., comment_formatter on blocks of comments. Outsource it, but ideally find something that respects indented blocks. |
Changes:
|
This looks great. I find the horizontal alignment inside of existing Talon files to be a bit distracting, so I'm fan of the way they currently look in the PR. |
@phillco do you have any ideas how to resolve the issues with pre-commit.ci? It currently doesn't have C++ build tools, which breaks |
I'm not sure. If they don't support it out of the box I'm guessing we might have to move to Github Actions. |
Works locally, it's just not working with the CI. |
Maybe you could have a branch of talonfmt where you check in the compiled code so that it doesn't need to compile? |
Was considering that, yes. The downside is that it's part of a different package, |
Hmm. Looks like OS-specific native code builds for Python are still pretty painful today Could maybe use wasm with wasmer? |
Unfortunately, the |
873e7d8
to
6a49b97
Compare
Set pre-commit to skip |
I took a look at a pre-commit.ci run, the build tools run fine, but the package tries to write to the installation directory at runtime, which is a big no-no since the virtual environment is immutable once installed. If this will require a C++ compiler at runtime, this will be very annoying for people on Windows, as having Visual Studio installed is a lot more rare than having a C++ toolchain on UNIX systems. |
Added blank lines after the match context, as requested. |
I have no strong opinion on that case.
…On Thu, 18 Aug 2022, 17:28 Wen Kokke, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In misc/extensions.talon
<#947 (comment)>:
> @@ -1 +1,2 @@
+-
Do you all want to keep the - if it's already there, even if it's not
needed?
—
Reply to this email directly, view it on GitHub
<#947 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAD6DYVJFSTQ7TGJC3VRXTVZZQCHANCNFSM55IPZEBA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Latest version:
I've also switched all the defaults over to the settings used here. |
- id: remove-tabs | ||
types: [file] | ||
files: \.talon$ | ||
args: ["--whitespaces-count=4"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, it does seem like most of our .talon files use 4 space indents. We should fix the .editorconfig to do the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened #970 for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be cool if remove-tabs respected .editorconfig. I believe prettier does
Can we merge this? I don’t think there’s still any blocking issues. |
We should probably decide at this point whether we're standardizing on 2 or 4 spaces for indentation in talon files. Per #970 we mostly use 4 spaces but the editorconfig file is set up to use 2 spaces. I prefer 2 spaces but I reckon I'm probably outvoted here :P. Still: |
upvote for 2 spaces |
upvote for 4 spaces |
Okay, it's been open to a vote for 9 days. Can we merge this now? |
🎉🎉🎉 |
Awesome! Thanks a bunch for this change, Wen. Now to merge up my fork :D |
This PR adds `talonfmt`, as well a tabs-to-spaces conversion, to pre-commit. The changes in the .talon should _absolutely_ be reviewed. Note that `talonfmt` supports alignment of context headers and one-line commands, but I've not enabled those options.
This omits the changes from talonhub#947 (446ec76) from blame for people who have the configuration set, so the reformatting changes don't affect blame.
This omits the changes from talonhub/community#947 (446ec764c9caa98973eacd7f792b6a087a1b635f) from blame for people who have the configuration set, so the reformatting changes don't affect blame.
This PR adds
talonfmt
, as well a tabs-to-spaces conversion, to pre-commit.The changes in the .talon should absolutely be reviewed.
Note that
talonfmt
supports alignment of context headers and one-line commands, but I've not enabled those options.