json_serializable disregards the page_width setting in analysis_options.yaml and uses the default value of 80. Therefore, if a different page_width is specified in the project's analysis_options.yaml, a separate formatting step is required after running build_runner build.
|
String defaultFormatOutput(String code, Version languageVersion) => |
|
DartFormatter(languageVersion: languageVersion).format(code); |
Steps to Reproduce
This behavior can be reproduced in the json_serializable.dart project.
- Set a
page_width value other than 80 in /analysis_options.yaml:
formatter:
page_width: 120
- Navigate to the
/example.
- Run
dart run build_runner build -d.
- The generated code is formatted with page_width
80.
- Run
dart format lib/.
- The generated code is formatted with page_width
120.
- Run
dart run build_runner build -d.
- The generated code is formatted with page_width
80.
Proposal
How about adding the line // dart format width=80 to the generated code?
https://github.com/dart-lang/dart_style/blob/bacc9bf8fcec6fffc15ad7e9257b7faba5298ea9/CHANGELOG.md#300
Trailing comma
As reported in #1486, the trailing commas option is also not reflected. However, since commas are removed when formatted with TrailingCommas.automate, I cannot think of any cases where additional formatting would be necessary.
json_serializable disregards the
page_widthsetting inanalysis_options.yamland uses the default value of 80. Therefore, if a differentpage_widthis specified in the project'sanalysis_options.yaml, a separate formatting step is required after runningbuild_runner build.json_serializable.dart/json_serializable/lib/src/json_part_builder.dart
Lines 113 to 114 in 83e7905
Steps to Reproduce
This behavior can be reproduced in the
json_serializable.dartproject.page_widthvalue other than 80 in/analysis_options.yaml:/example.dart run build_runner build -d.80.dart format lib/.120.dart run build_runner build -d.80.Proposal
How about adding the line
// dart format width=80to the generated code?https://github.com/dart-lang/dart_style/blob/bacc9bf8fcec6fffc15ad7e9257b7faba5298ea9/CHANGELOG.md#300
Trailing comma
As reported in #1486, the trailing commas option is also not reflected. However, since commas are removed when formatted with
TrailingCommas.automate, I cannot think of any cases where additional formatting would be necessary.