Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
devoncarew opened this issue Jan 5, 2023 · 5 comments

Comments

@devoncarew
Copy link
Member

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
Copy link
Member Author

devoncarew commented Jan 5, 2023

Some configuration prior art are the analyzer ignore_for_file directives:

// ignore_for_file: unused_local_variable

and the dart language directive:

// @dart = 2.12

@munificent
Copy link
Member

Phew. This is a thing we could do. But given how incredibly heated discussions of line length get, I worry that if we do this, everyone will start configuring the line lengths of all of their files. And then when you're bouncing between Dart files in different packages, it will get much harder to decide how to configure the window size in your IDE.

@TimWhiting
Copy link

Isn't being able to make sense of code more important than having to deal with resizing windows?

Sure, it'd be pretty impossible to make sure every potential piece of code is formatted optimally for readability. So dart format has to do a best effort, which for most cases is wonderful. It is subjective whether 80 vs 100 vs 120 character lines for a particular file is most readable and people will have their own opinions. However, like @devoncarew, I've found that especially for generated files 80 characters is just too little. I know some people have similar feelings about files with lots of flutter widgets with their build methods with lots of nested widgets.

@dnfield
Copy link

dnfield commented Mar 3, 2023

I would personally prefer to see #918 implemented, which I think would solve this (just put your generated files in a package that configure the line length for all of them to 120).

@acauquil
Copy link

acauquil commented Apr 5, 2024

@dnfield it would be useful for files defining configs or constants where you often see maps with entries having different length. In this case, having one entry per line is better for readability, meanwhile increasing the line length for the whole package is not worth considering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants