Dart-code: How to stop formatter wrapping at 80 characters?

Created on 16 May 2019  路  11Comments  路  Source: Dart-Code/Dart-Code

VSCode Version 1.33.1 (1.33.1)
Dart 3.02

Whenever code formatting is invoked, it wraps my dart code even though I checked all settings I could find
I don't think it's a general VSCode issue because the same code in an .m file does not get wrapped.

{
    "dart.flutterSdkPath": "/Applications/flutter",
    "workbench.colorTheme": "Visual Studio Light",
    "editor.formatOnSave": true,
    "editor.minimap.enabled": false,
    "editor.codeLens": false,
    "editor.folding": false,
    "editor.highlightActiveIndentGuide": false,
    "editor.insertSpaces": false,
    "editor.lightbulb.enabled": true,
    "editor.renderIndentGuides": false,
    "editor.overviewRulerBorder": true,
    "editor.hideCursorInOverviewRuler": true,
    "editor.wordWrapColumn": 999,
    "editor.formatOnType": true,
    "editor.wrappingIndent": "none",
    "[dart]": {
        "editor.rulers": [
            0
        ]
    },
}
      final existingEvents = (await deviceCalendar.retrieveEvents(calendar.id, RetrieveEventsParams())).data;
      final newEvents = list.where((x)=>existingEvents.firstWhere((y)=>y.title == x['text']) == null);

Becomes

      final existingEvents = (await deviceCalendar.retrieveEvents(
              calendar.id, RetrieveEventsParams()))
          .data;
      final newEvents = list.where((x) =>
          existingEvents.firstWhere((y) => y.title == x['text']) == null);
is question

Most helpful comment

You're right, this is a Dart setting. For formatting, we use the SDK-supplied dart_style library which wraps lines at 80 characters, but you can control this with the "dart.lineLength" setting.

Let me know if this doesn't work for you.

All 11 comments

You're right, this is a Dart setting. For formatting, we use the SDK-supplied dart_style library which wraps lines at 80 characters, but you can control this with the "dart.lineLength" setting.

Let me know if this doesn't work for you.

@DanTup

  1. Is there any way to configure this per-project?
    I.e. keep wrapping at 80 for flutter & flutter/plugins forks but wrap at 200 for everything else?
    Specifically, in Android Studio.
  2. Where is this setting in Android Studio? I can't find it anywhere. The flutter fork wraps at 200 which will surely fail formatting test for my PR.
    image

@duzenko It's possible in VS Code with "Workspace Settings" but I'm not familiar with config in Android Studio. Maybe @pq knows if this can be set per-project?

I don't believe this is configurable currently in IDEA.

@alexander-doroshko @jwren may know more?

That's the only code style setting that survived but it's there.
image

Ah! I was looking in the wrong place. Excellent. Thanks @alexander-doroshko!

Wish this setting could be shared with teammates.

We use editorconfig, however the line length defined in screenshot above overrides property in .editorconfig file.

Have tried such config:

[*]
max_line_length = 120

or

[*.dart]
max_line_length = 120

None is functional.

Is there anything to do to make editorconfig configuration take precedence over dart editor setting ?
Any alternative way to share this setting ?

Thanks ;)

We use editorconfig, however the line length defined in screenshot above overrides property in .editorconfig file.

I don't think it's being overridden - the issue is likely that the Dart formatter does not support editorconfig and therefore what you're setting in your editorconfig is just not being read at all by the Dart formatter. There's a related issue at https://github.com/Dart-Code/Dart-Code/issues/914.

In the meantime, you should be able to set dart.lineLength and commit it to your .vscode/settings.json file if you want to share it in the repo.

I forgot to mention explicitely that we are using Android Studio ^^ thanks anyway ;)

Oh, gotcha! I'm afraid I don't know much about AS so don't know how you would share settings there. Perhaps someone above may jump in if there's a way though!

@emri99 In IntelliJ IDEA and Android Studio, to share code style settings with teammates through Version Control System, you'll need to commit .idea/codeStyles/codeStyleConfig.xml and .idea/codeStyles/Project.xml files.

But first, make sure that you are using project-level code style settings (Scheme: Project in Settings/Preferences -> Editor -> Code Style):
image

Contents of these files will be like this:

<component name="ProjectCodeStyleConfiguration">
  <state>
    <option name="USE_PER_PROJECT_SETTINGS" value="true" />
  </state>
</component>
<component name="ProjectCodeStyleConfiguration">
  <code_scheme name="Project" version="173">
    <codeStyleSettings language="Dart">
      <option name="RIGHT_MARGIN" value="120" />
    </codeStyleSettings>
  </code_scheme>
</component>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

atreeon picture atreeon  路  5Comments

shamrin picture shamrin  路  5Comments

awfin picture awfin  路  3Comments

jascodes picture jascodes  路  4Comments

DanTup picture DanTup  路  4Comments