dart-lang / dart_style

An opinionated formatter/linter for Dart code
https://pub.dev/packages/dart_style
BSD 3-Clause "New" or "Revised" License
650 stars 121 forks source link

Allow a comment in code to explicitly configure the page width. #1574

Closed munificent closed 1 month ago

munificent commented 1 month ago

If the code being formatted contains a comment anywhere in it like:

// dart format width=123

Then the code is formatted at that width instead of the default width.

The intent is that tools that generate code and then format it will put this comment in the generated code. That way, the tool doesn't have to handle the complex logic to find a surrounding analysis_options.yaml file and get the user's project-wide page width configuration.

End users may also want to use this comment in rare cases. For example, maybe they have a library that contains a large value of data that looks better as a big wide table but they don't want their entire project to have a wider page width.