Skip to content

Unexpected new_line after function call with ternary condition #1218

Open

Description

@Shohoo

I do not know how can i resolve this.
When I set ls_code_width = true, it does not add new line but ternary condition is splited then and I do not want that. I would be very pleased if you could help me resolve this problem.
Here goes codes.

debug:
https://pastebin.com/2ywmS4B0
file:

if (1)
    test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
                   aaaaaaaaaaaaaaaaaa[i].bbbbbb ? AAAAAAAA : BBBBBBBBBBBBBB);
else
    test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
                   DDDDDDDDDDDDDDD);
if (1)
    test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
                   aaaaaaaaaaaaaaaaaa[i].bbbbbb);
else
    test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
                   DDDDDDDDDDDDDDD);

result:

if (1)
	test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
		       aaaaaaaaaaaaaaaaaa[i].bbbbbb ? AAAAAAAA : BBBBBBBBBBBBBB);

else
	test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
		       DDDDDDDDDDDDDDD);
if (1)
	test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
		       aaaaaaaaaaaaaaaaaa[i].bbbbbb);
else
	test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
		       DDDDDDDDDDDDDDD);

expected:

if (1)
	test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
		       aaaaaaaaaaaaaaaaaa[i].bbbbbb ? AAAAAAAA : BBBBBBBBBBBBBB);
else
	test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
		       DDDDDDDDDDDDDDD);
if (1)
	test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
		       aaaaaaaaaaaaaaaaaa[i].bbbbbb);
else
	test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
		       DDDDDDDDDDDDDDD);

version: 0.64

Activity

  1. CDanU commented on Jun 23, 2017

    @CDanU
    Collaborator

    The ternary condition is not splitted in your result, but there is an extra newline. So I assume that is your problem? Yes, its right there in the title that I skipped reading.

    The newline is (wrongly) added by

    # Try to limit code width to N number of columns
    code_width                      = 80       # unsigned number

    Interestingly enough that does not happen when the expression is not inside the if block. So this seems to be related to the virtual if close brace. I will take a look.

    If

    # Whether to split lines as close to code_width as possible and ignore some groupings
    ls_code_width                   = true     # false/true

    is added (which, as you wrote, you don't want to use), then the ternary is broken up:

    if (1)
    	test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
    	               aaaaaaaaaaaaaaaaaa[i].bbbbbb ? AAAAAAAA :
    	               BBBBBBBBBBBBBB);
    else
    	test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
    	               DDDDDDDDDDDDDDD);
    if (1)
    	test_attribute(j, (aaaaaaaaaaaaaaaaaaa + i),
    	               aaaaaaaaaaaaaaaaaa[i].bbbbbb);
    else
    	test_attribute(j, (aaaaaaaaaaaaaaaaaaaa + i),
    	               DDDDDDDDDDDDDDD);

    The break up happens too soon as the semicolon is not above col pos 80 as specified (it is at col (input) 78, after processing (tabs) 73)

  2. Shohoo commented on Jun 23, 2017

    @Shohoo
    Author

    The break up happens too soon as the semicolon is not above col pos 80 as specified (it is at col 78)

    Well so it seems to be deeper problem then.
    As I understand ls_code_width = true results in ignoring groupings am I correct?
    So I have such a scenerio.

    debug: https://pastebin.com/i02ePEEE
    file:

    ffffffff("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaaaaaa, bbbbb->bbbb.bbbbb.bbbb.bbb,ccccc->cccc.ccccc.cccc);
    ffffffff("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);
    

    results:

    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaaaaaa, bbbbb->bbbb.bbbbb.bbbb.bbb,
    	ccccc->cccc.ccccc.cccc);
    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
    	aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);
    

    expected:

    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
    	aaaaaaaaaaaa, bbbbb->bbbb.bbbbb.bbbb.bbb, ccccc->cccc.ccccc.cccc);
    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
    	aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);
    

    Sometimes it breakes only last argument (first case) and sometimes it starts breaking at first argument (second case). Little confusing. Hope so it will provide something more to the problem.

  3. CDanU commented on Jun 23, 2017

    @CDanU
    Collaborator

    The problem is that Uncrustify by default indents with 8 chars, the tab width by default is also set to 8, with that in mind the semicolon is actually at col 81 (not 73).
    Set

    # The number of columns to indent per level.
    # Usually 2, 3, 4, or 8. Default=8
    indent_columns                  = 4        # unsigned number

    and it should work as expected.

    The default 8 is fairly confusing as most editors have it set to something other than that, this caused the miscalculation in my last comment.

    Related:

    # The original size of tabs in the input. Default=8
    input_tab_size                  = 8        # unsigned number

    Not (here) related (only used if ...):

    # The size of tabs in the output (only used if align_with_tabs=true). Default=8
    output_tab_size                 = 8        # unsigned number

    Adding this to your config:

    # The number of columns to indent per level.
    # Usually 2, 3, 4, or 8. Default=8
    indent_columns                  = 4        # unsigned number
    
    # Whether to split lines as close to code_width as possible and ignore some groupings
    ls_code_width                   = true     # false/true

    Creates this output for your new examples:

    ffffffff(
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
        aaaaaaaaaaaa, bbbbb->bbbb.bbbbb.bbbb.bbb, ccccc->cccc.ccccc.cccc);
    ffffffff(
        "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
        aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);

    If input_tab_size = 4 tabs will be used for the indention.

  4. Shohoo commented on Jun 26, 2017

    @Shohoo
    Author

    I think you did not understand. In my opinion result:

    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
    	aaaaaaaaaaaa, bbbbb->bbbb.bbbbb.bbbb.bbb, ccccc->cccc.ccccc.cccc);
    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
    	aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);
    

    should occur even if ls_code_width = false. When I set it to true it breakes as expected but it will ruin my previous goal. And in description of that setting it is written that if true it is ignoring groupings.

    And indenting with 4 is not my goal, I need 8.

  5. Shohoo commented on Jun 26, 2017

    @Shohoo
    Author

    I have added third case to previous two:

    //1 case
    ffffffff("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaaaaaa, bbbbb->bbbb.bbbbb.bbbb.bbb,ccccc->cccc.ccccc.cccc);
    //2 case
    ffffffff("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);
    //3 case
    ffffffff("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);
    

    results in:

    /* 1 case */
    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaaaaaa, bbbbb->bbbb.bbbbb.bbbb.bbb,
    	ccccc->cccc.ccccc.cccc);
    /* 2 case */
    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
    	aaaaaaaa, bbbbbbbb, cccccccc, ddddddddd);
    /* 3 case */
    ffffffff(
    	"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", aaaaaaaa, bbbbbbbb, cccccccc,
    	ddddddddd);
    

    The difference between 2 and 3 case is that I made string as long as in 1 case. And as you see in 3 case arguments are breaking inproperly.

  6. CDanU commented on Jun 26, 2017

    @CDanU
    Collaborator

    Yes, you are right I had mixed up the two problems a bit. I am going to see why the breaks are happening this way.

  7. CDanU commented on Jun 26, 2017

    @CDanU
    Collaborator

    Ok here is what is currently happening with case 3:
    With the 'xxxx...' string chunk, it is determined that its token is too long and the function split_line proceeds to cut the line properly.

    In round two like previously in the do_code_width function, the function is_past_width - L142 determines that the comma after the string is problematic, the split_line function is called which itself calls the split_fcn_params function.
    Inside it first the opening parenthesis - L636-L643 of the function call is searched, then the first comma above max col - L654-L683 (the one that was deemed to be problematic) and finally a comma before the problematic comma is tried to be found.
    There is none, but a newline (the one that was inserted in the first run) is found which breaks the loop - L693. The prev var (which should have been either a comma or a closing parenthesis) at this point is that loop breaking newline and so the line is not broken up in L719-L728
    That goes on this way until the closing parenthesis is also deemed to be problematic. In that case instead of the split_fcn_params function the split_before_chunk function is called, resulting that ddddddddd); is on a new line.

  8. Shohoo commented on Jun 28, 2017

    @Shohoo
    Author

    Ok, so it is a bug.
    I would live with that but there is my original problem with newline after ternary condition.
    Tell me, can you do sth with that or how things going here?

  9. CDanU commented on Jun 28, 2017

    @CDanU
    Collaborator

    Your original problem with the extra newline should be fixed once the first PR (1219) for this issue is merged, the other problems will also be fixed soon with a new PR. It will take a while though until the PRs are actually getting merged in.

    You can always integrate those earlier in your local repo if you want to.

  10. guy-maurel commented on Feb 28, 2018

    @guy-maurel
    Contributor

    May we close ?

  11. CDanU commented on Feb 28, 2018

    @CDanU
    Collaborator

    No

  12. guy-maurel commented on Dec 16, 2021

    @guy-maurel
    Contributor

    The current git version works pretty fine under Linux Mint.
    https://github.com/uncrustify/uncrustify
    Please test it and report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions