dart_style icon indicating copy to clipboard operation
dart_style copied to clipboard

support the ability to configure the formatting line length from within the file

Open devoncarew opened this issue 1 year ago • 5 comments

This is a feature request to support the ability to configure the formatting line length from within the target file.

The use case here is that I have a project that's generating very large dart source files; they're generated from wasm files and replicate the operations specified in those files. Roughly, each generated source line corresponds to a wasm instruction. This works well (is readable) except in cases where there's significant nested control flow. In those cases, the indent pushes the contents past the 80-char boundary, and the generated operations start re-flowing into new lines (generally not doing good things for the readability).

To address this I'm experimenting with formatting the files - as the last step of codegen - with a longer line length; ~100 - ~120 chars. That generally works even for the most nested files. However, there are two issues:

  • if somebody ever goes into that file and hits save in an editor, the file will be re-formatted using a different line length
  • if people use dart format --output=none --set-exit-if-changed as part of a CI, it'll fail on these files

The feature request is for a way to configure the line length that a file should be formatted at from within the file itself. So, something like:

// Generated from foo/bar/...
// @format.length=120

...

devoncarew avatar Jan 05 '23 00:01 devoncarew