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

Add newlines between functions in translate.go #27

Merged
merged 6 commits into from
Nov 19, 2024
Merged

Conversation

Neved4
Copy link
Contributor

@Neved4 Neved4 commented Nov 15, 2024

Fixes #26

Chose a strategy to add newlines between functions, while ensuring no newline is added on the last one.

   1   #!/bin/sh
   2   function f
   3     echo 'This is the f function'
   4   end
   5   
   6   function g
   7     echo 'This is the g function'
   8   end
   9   
  10   function h
  11     echo 'This is the h function'
  12   end

@JoaoCostaIFG
Copy link
Contributor

Hi @Neved4!
Looks good to me, but needs to update the tests. I've generated the following patch if you want to apply it:

function_newline_tests.patch.txt

@Neved4
Copy link
Contributor Author

Neved4 commented Nov 15, 2024

Done!

@bouk
Copy link
Owner

bouk commented Nov 18, 2024

Could you change this to use the Stmt Pos and End methods to determine whether the original code had an extra newline: https://pkg.go.dev/mvdan.cc/sh/v3/syntax#Stmt.End

Then we can make it actually whitespace preserving 🙂

@Neved4
Copy link
Contributor Author

Neved4 commented Nov 18, 2024

@bouk Sounds great! Wasn't familiar with mvdan/sh internals

Pushed two commits, please lmk if that's how you intended it, it's my first time with parsers

Cheers!

@bouk
Copy link
Owner

bouk commented Nov 18, 2024

You'll just have to update the test now, but looks good!

@Neved4
Copy link
Contributor Author

Neved4 commented Nov 18, 2024

Even if b15c764 is simpler, it adds extra newlines between commands. To minimize changes to the current tests and output, I reverted it in favor of 915fb09. Updated tests accordingly.

If you need anything else, just give me a shout, cheers!

@bouk bouk merged commit 21aad16 into bouk:master Nov 19, 2024
1 check passed
@bouk
Copy link
Owner

bouk commented Nov 19, 2024

thx!

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

Successfully merging this pull request may close these issues.

Emit empty newlines between functions
3 participants