Skip to content

Instantly share code, notes, and snippets.

@yjbanov
Last active February 4, 2016 18:34
Show Gist options
  • Save yjbanov/04436939b02f1f190504 to your computer and use it in GitHub Desktop.
Save yjbanov/04436939b02f1f190504 to your computer and use it in GitHub Desktop.
trailing commas for tree-like code in Dart
// frameworks such as Flutter and UIX encourage users to express their
// UI using tree-like syntaxes.
// unfortunately dartfmt will format this code:
main() {
var componentTree = new MyButton(
title: 'Save',
onClick: () {
doSomthing();
},
icon: new Image(
src: '/images/save.png',
width: 10
)
);
}
// to this:
main() {
var componentTree = new MyButton(title: 'Save', onClick: () {
doSomthing();
}, icon: new Image(src: '/images/save.png', width: 10));
}
// what if Dart allowed trailing commas in function/method/constructor calls and
// dartfmt treated them as a signal that the closing paren must go on the next line?
main() {
var componentTree = new MyButton(
title: 'Save',
onClick: () {
doSomthing();
},
icon: new Image(
src: '/images/save.png',
width: 10, // <-- trailing comma
), // <-- trailing comma
);
}
// problem solved?
@Hixie
Copy link

Hixie commented Feb 4, 2016

(I understand that what I'm proposing is incompatible with dartfmt's current goals. I think dartfmt's goals should change.)

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