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 two new printer options: -knl and -bnl #463

Merged
merged 1 commit into from
Feb 17, 2020

Conversation

MorganAntonsson
Copy link
Contributor

Hi,

I have added two new printer options for a less compact style.

-knl (keyword new line) will put keywords like "then" and "do" on a new line.

Example:

if foo
then
    bar
fi

-bnl (brace new line) will put braces on new lines.

Example:

foo()
{
    bar
}

It would be great if you would accept the patch. Let me know if there is anything I need to change.

Regards,
Morgan

@mvdan
Copy link
Owner

mvdan commented Dec 27, 2019

Thanks for the patch. It's clear that you spent some effort here, which puts me in a difficult position because this feature was brought up and rejected in #229.

In the future, I'd strongly encourage you to raise an issue or talk to upstream developers before writing new features, especially if they mean new APIs or command line flags. Those changes tend to be delicate and require careful consideration, so jumping straight to a patch forces upstream's hand to merge or reject.

For now, I'll reopen the issue, as there was another person interested in this feature recently. And as said before, I don't think I'll be merging this PR until there's at least some consensus in #229.

Edit: I had originally linked the wrong issue here, apologies.

Copy link
Owner

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Rejecting" the PR to remind myself that this is blocked by the discussion on the issue.

@MorganAntonsson
Copy link
Contributor Author

No worries. I should have done some research before submitting the code. Thanks for re-opening the issue.

@mvdan
Copy link
Owner

mvdan commented Jan 22, 2020

Could you please trim down this PR to follow option 2 in #229 (comment)? That is, -fn to keep function declaration opening braces in a separate line.

We also need more test cases - for example, inputs like the following (imagine tabs for indentation):

foo()

{

    bar
}

function foo {
    bar
}

foo()
{ bar; }

@MorganAntonsson
Copy link
Contributor Author

Sure, it's on my todo-list. I am a bit busy at the moment, but within a week or two I should have time.

@MorganAntonsson
Copy link
Contributor Author

Hi. I have made the update. Let me know if it's OK. :)

Copy link
Owner

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll squash-merge to adapt the commit message to the usual format, if that's okay. Just some minor comments.

@@ -91,6 +92,7 @@ Printer options:
-ci switch cases will be indented
-sr redirect operators will be followed by a space
-kp keep column alignment paddings
-fn place function braces on a new line
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function opening braces are placed on a separate line

@@ -962,6 +968,7 @@ func (p *Printer) command(cmd Command, redirs []*Redirect) (startRedirs int) {
case *Block:
p.WriteByte('{')
p.wantSpace = true
p.wantNewline = p.wantNewline || p.functionNewLine
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment, like:

// Forbid "foo()\n{ bar; }"

@MorganAntonsson
Copy link
Contributor Author

Updated. Sure, feel free to edit the commit message. Thanks for accepting the change!

@mvdan mvdan merged commit c3b7a40 into mvdan:master Feb 17, 2020
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.

2 participants