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

Unwanted newline with nl_if_brace=remove #2889

Closed
rkta opened this issue Aug 8, 2020 · 5 comments
Closed

Unwanted newline with nl_if_brace=remove #2889

rkta opened this issue Aug 8, 2020 · 5 comments

Comments

@rkta
Copy link

rkta commented Aug 8, 2020

Version:

  Uncrustify_d-0.71.0-118-e1a2c2a5

Command:

~/code/uncrustify/build/uncrustify --show-config > default.cfg
~/code/uncrustify/build/uncrustify -p debug.txt -c default.cfg --set nl_if_brace=remove -f main.c

main.c:

int main(void)
{
        if (true) {
                return 0;
        } else {
                return 1;
        }
}

Output:

int main(void)
{
        if (true) {
                return 0;
        }
        else {
                return 1;
        }
}

Expected:

int main(void)
{
        if (true) {
                return 0;
        } else {
                return 1;
        }
}

With --set nl_if_brace=ignore it works as expected (nothing happens).

debug.txt

@rkta rkta changed the title Unwanted newline with nl_if_remove Unwanted newline with nl_if_brace=remove Aug 18, 2020
@guy-maurel
Copy link
Contributor

You need to use the option:

# Add or remove newline between '}' and 'else'.
nl_brace_else=remove

@rkta
Copy link
Author

rkta commented Aug 24, 2020

Using nl_brace_else=remove will remove all newline before an else - that is not what I want. I'd like to remove newline before the curly bracket after an if and leave newlines before else untouched? Is this possible?

@guy-maurel
Copy link
Contributor

This is NOT correct. Please, have a look:
Description=Add or remove newline between '}' and 'else'.

@rkta
Copy link
Author

rkta commented Aug 24, 2020

I'm not sure if I understand you correctly.
Given the following code:

int main(void)
{
        if (true)
        {
                return 0;
        }
        else if (false) {
                return 1;
        } else {
                return 1;
        }
}

This is the result:

% ~/code/uncrustify/build/uncrustify -p debug.txt -c default.cfg \
--set nl_if_brace=remove --set nl_brace_else=remove -f main.c
Parsing: main.c as language C
int main(void)
{
        if (true) {
                return 0;
        }else if (false)  {
                return 1;
        }else {
                return 1;
        }
}

Or with nl_brace_else=ignore:

% ~/code/uncrustify/build/uncrustify -p debug.txt -c default.cfg \
--set nl_if_brace=remove --set nl_brace_else=ignore -f main.c
Parsing: main.c as language C
int main(void)
{
        if (true) {
                return 0;
        }
        else if (false) {
                return 1;
        }
        else {
                return 1;
        }
}

My expected output is:

int main(void)
{
        if (true) {
                return 0;
        }
        else if (false) {
                return 1;
        } else {
                return 1;
        }
}

Opening curly braces should always be one the same line as the if, newlines before else should be ignored. That's what I was expecting when using --set nl_if_brace=remove and --set nl_brace_else=ignore.

@guy-maurel
Copy link
Contributor

Thanks for the mail.

@gmaurel gmaurel closed this as completed Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants