Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode set width for code formatting of arrays etc

If my array goes over a certain length:

const List hts = [200, 195, 190, 185, 180, 175, 170, 165, 160, 155, 150, 145];

VSCode formats it like this:

const List hts = [
  200,
  195,
  190,
  185,
  180,
  175,
  170,
  165,
  160,
  155,
  150,
  145,
  140
];

I'd rather it didn't since it makes a short array take up half the page. How can I change this?

Also I get even weirder formatting like this which means if I comment out a line it only comments out half the line:

This:

   Text('RESULTS', style: kMainText),
   Text('Additional', textAlign: TextAlign.center, style: kSmallText),

Gets formatted as this:

   Text('RESULTS', style: kMainText),
   Text('Additional',
          textAlign: TextAlign.center, style: kSmallText),

The second line is one line but I have to comment it out as two lines. It seems like there's some kind of 'length' setting somewhere that I could alter to avoid this. How can I edit all this behaviour?

like image 468
Hasen Avatar asked Oct 28 '22 11:10

Hasen


1 Answers

The Dart VS Code extension uses dart_style for formatting, which ships in the Dart SDK.

There is a setting called "maximum line length" which can be configured in your VS Code settings in the Dart section which will allow lines to be longer before they wrap (though note that this applies to all lines, not just lists).

There's an issue requesting an alternative (more customisable) formatter in VS Code here:

https://github.com/Dart-Code/Dart-Code/issues/914

Please add a 👍 to the issue if it's something you'd like to see.

like image 122
Danny Tuppeny Avatar answered Nov 10 '22 14:11

Danny Tuppeny