Formatter
DCM provides a configurable formatter that supports project-wide configuration.
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 we provide this formatter.
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.