简体   繁体   中英

Change Dart Formatting style

Okay, so the title may be slightly misleading, This is simply my end goal.

So, I'm just getting into the world of Dart. So far it seems great, but my biggest issue with it is the stupid default formatter. In particular that you can't get rid of it. I'm using WebStorm mainly because of how customisable these things tend to be. But I haven't found any way to change the formatter for dart (see attached screenshot). The Dart formatter enforces 2-space indentations and many other infuriating code styles which are only enforced by it.

Is it possible to somehow change either the configuration options or the formatter all together? If the change has to be made to source, that's doable, or simply playing around with some WebStorm configurations, that's fine also, I just want to change this.

Thanks

如您所见,除了行长之外没有其他任何方法可以配置

You can't change the formatting style used by dartfmt and that was a very intentional design decision. If you look at the FAQ for package:dart_style you'll find the following under the "Why can't I configure it?" section:

The formatter supports very few tweakable settings, by design. If you look up at the list of priorities above, you'll see configurability goes directly against the first two priorities, and halfway against the third (you have to think about it, but not apply it).

This may be surprising, but the goal of dartfmt is not to automatically make your code look the way you like. It's to make everyone's Dart code look the same. The primary goal of dartfmt is to improve the quality of the Dart ecosystem. That transitively improves the live's of each Dart developer as well—you get more code to reuse, more consistent code, it's easier to read and contribute to each other's code, etc. But it does that at the expense of individual preference.

The Dart formatter respects linter style rules as laid out in the "analysis_options.yaml" file. A description of the file can be found here . A complete list of linter rules can be found here .

You can also subscribe to common style guides, such as pedantic , a package with the style guide used internally by Google, or lint , another package that enables all the rules that aren't either contradictory or opinionated.

That being said, I don't think you can change things like the two-space indentation. There are certain style choices that dartfmt enforces in the interest of maintaining as much style consistency between Dart codebases as possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM