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

Inconsistent indentation of list literal between variable and getter declarations. #624

Closed
lrhn opened this issue Apr 26, 2017 · 5 comments · Fixed by #1618
Closed

Inconsistent indentation of list literal between variable and getter declarations. #624

lrhn opened this issue Apr 26, 2017 · 5 comments · Fixed by #1618

Comments

@lrhn
Copy link
Member

lrhn commented Apr 26, 2017

var x = [                                       
  "long value that won't fit everywhere",       
  "long value that won't fit everywhere",       
  "long value that won't fit everywhere"        
];                                              
                                                
get y => [                                      
      "long value that won't fit everywhere",   
      "long value that won't fit everywhere",   
      "long value that won't fit everywhere"    
    ];                                          

In the var declaration, the list is indented by two, in the getter, it's indented by six.
I'd prefer if they both used the var indentation.

@matanlurey
Copy link
Contributor

Same issue with map literals

@munificent
Copy link
Member

This is (more or less) intentional. It naturally falls out of how => works, but I could have made it handle this case specifically to match variables. I didn't because I think it's useful to make these visually distinct. With a variable, the collection initializer is evaluated once. With a getter, it's evaluated each time. They really are different concepts, and I think it's OK for them to format differently.

@greglittlefield-wf
Copy link

greglittlefield-wf commented Feb 11, 2019

For this case, I often find myself changing to block-style function bodies in order to increase readability, which is unfortunate (I want that nice, clean, arrow syntax 😄)

get y {
  return [                                      
    ...
  ];
}

Or, I'm temped to use comments as a hack to force the opening bracket to match the indentation of the closing one.

Myself and other members of my team think that starting the literal on the next line makes it easier to tell at a glance that the subsequent lines are within a list (when compared to the current formatting shown in the description).

get y => //
    [                                      
      ...
    ];

Same for list-returning lambdas in argument lists with trailing-comma; I would prefer for the list to not have that continuation indent, similar to list arguments. Note the difference:

new FooWidget(
  y: () => [
        ... 
      ],
  z: [
    ...
  ],
);

Any chance this issue could be revisited?

Also is that argument list case a different enough code path that I should open a separate issue for it?

@munificent munificent reopened this Feb 12, 2019
@dcharkes
Copy link

dcharkes commented Aug 6, 2023

This is (more or less) intentional. It naturally falls out of how => works, but I could have made it handle this case specifically to match variables. I didn't because I think it's useful to make these visually distinct. With a variable, the collection initializer is evaluated once. With a getter, it's evaluated each time. They really are different concepts, and I think it's OK for them to format differently.

I've also been running into this recently in multiple projects. One of them being Flutter where we have this pattern and are manually formatting to not use the extra indentation on =>:

  @override
  List<Source> get outputs => const <Source>[
    Source.pattern('{OUTPUT_DIR}/vm_snapshot_data'),
    Source.pattern('{OUTPUT_DIR}/isolate_snapshot_data'),
    Source.pattern('{OUTPUT_DIR}/kernel_blob.bin'),
  ];

  @override
  List<String> get depfiles => <String>[
    'flutter_assets.d',
  ];

https://github.com/flutter/flutter/blob/310e911466945aede7515d5ad288bf4048b4a601/packages/flutter_tools/lib/src/build_system/targets/common.dart#L41-L51

Any chance this issue could be revisited?

I second this.

munificent added a commit that referenced this issue Dec 7, 2024
This is doing what users want in the new tall style. \o/

Close #624.
@munificent
Copy link
Member

Good news: The new tall style does what's being requested here. I have a PR out to add a regression test but the tall style formatter is already doing this so the bug is fixed.

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

Successfully merging a pull request may close this issue.

5 participants