Dart-code: Support for `dartfmt`?

Created on 6 May 2018  Â·  8Comments  Â·  Source: Dart-Code/Dart-Code

Hello, does this extension support dartfmt? I ask because if I run dartfmt alone it gives me different output than simply saving a .dart file with this extension installed. Thanks.

Most helpful comment

No worries; maybe it's not obvious enough :)

I've started a "Recommended Settings" page for the website because there are a couple of things in VS Code that I think are bad defaults (but I don't wanna just force them on people in the extension!). Hopefully can finish it soon :-)

All 8 comments

Saving in the extension essentially does the same thing (the analysis server - which uses the same code as dartfmt - provides the edits for us to apply in the editor).

My guess would be that there's a difference in versions or something. Can you provide an example of the difference in formatting as well as confirm the versions - the one the extension is using is shown in the status bar and "dart --version" on the terminal you're running dartfmt from should give that version.

@DanTup thanks again for the quick reply.

Here's my code file. Note the deliberate overly indented Map values:

import 'dart:core';

class CalColor {
  String name;
  String hex;

  Map foobar = {
          'hi': 'there',
          'we': 'care',
          'over': 'there',
        };
}

I save the file and nothing happens.

Here's the output of dartfmt:

dartfmt --version
1.0.10
➜  dartfmt lib/models/cal_color.dart
import 'dart:core';

class CalColor {
  String name;
  String hex;

  Map foobar = {
    'hi': 'there',
    'we': 'care',
    'over': 'there',
  };
}

...another example:

Code:

import 'dart:core';

class CalColor {
  String name;
  String hex;

  Map foobar = {
          'hi': 'there'
        };
}

Output:

dartfmt lib/models/cal_color.dart
import 'dart:core';

class CalColor {
  String name;
  String hex;

  Map foobar = {'hi': 'there'};
}

If I paste your first sample in to a file and hit save, it gets formatted (the extra indents disappear).

Have you enabled editor.formatOnSave? I can't remember if it's on by default, but worth checking your settings.

If you open dev tools (Help -> Toggle Dev Tools) and repro, are there any errors/warnings written?

If none of those help, can you try enabling the analysis server logging and attach or email the file to me? https://dartcode.org/docs/logging/#analyzer

Ugh I'm such an idiot - didn't even think of trying that setting.

It works now with editor.formatOnSave.

Thanks for helping with an awesome IDE for Flutter.

No worries; maybe it's not obvious enough :)

I've started a "Recommended Settings" page for the website because there are a couple of things in VS Code that I think are bad defaults (but I don't wanna just force them on people in the extension!). Hopefully can finish it soon :-)

Awesome sounds good.

Sounds good. That'd be nice actually.

On Tue, May 8, 2018 at 1:39 PM, Danny Tuppeny notifications@github.com
wrote:

No worries; maybe it's not obvious enough :)

I've started a "Recommended Settings" page for the website
https://dartcode.org/ because there are a couple of things in VS Code
that I think are bad defaults (but I don't wanna just force them on people
in the extension!). Hopefully can finish it soon :-)

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/Dart-Code/Dart-Code/issues/878#issuecomment-387345451,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEoOS2Mq5rYysJsbcnRWxJesTJtT91uks5twWfAgaJpZM4Tz_7Y
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

partounian picture partounian  Â·  4Comments

shamrin picture shamrin  Â·  5Comments

rgb1380 picture rgb1380  Â·  3Comments

DanTup picture DanTup  Â·  3Comments

mayorbyrne picture mayorbyrne  Â·  5Comments