Formatter
DCM provides a configurable formatter that supports project-wide config.
The configuration is used by both the IDE and the dcm format
command.
This formatter is a modification of the dart_style library. All credit belongs to them.
Unfortunately, the authors of that library decided not to support configurability. That's the only reason this fork exists.
Configuration​
dart_code_metrics:
formatter:
indent: 0
line-length: 100
cascading-widget-extensions: true
Indent​
Specify the number of spaces per indentation-level.
The default indentation-level value is 0.
Line length​
Specify the line length that the formatter will wrap on.
The default value is 80.
For readability we recommend against using more than 120 characters.
Cascading widget extensions​
Specify whether the widget extensions inside a build
method should be formatter in a more readable way.
Before:
Widget build(BuildContext context) {
MyWidget().extensionMethod().another();
...
MyWidget()
.extensionMethod()
.another()
.andAnotherOne()
.andAnotherOne()
.andAnotherOne()
.andAnotherOne();
...
}
After:
Widget build(BuildContext context) {
MyWidget()
.extensionMethod()
.another();
...
MyWidget()
.extensionMethod()
.another()
.andAnotherOne()
.andAnotherOne()
.andAnotherOne()
.andAnotherOne();
...
}
VS Code integration​
To enable the formatter in VS Code, pick DCM
as the default formatter in the settings.json
and enable the format on save
option.
You can also use a separate command DCM: Format Current File
.
IntelliJ / AS integration​
You can format a file with the DCM: Format Current File
command.