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

Allow configuring project-wide page width using a surrounding analysis_options.yaml file #1571

Merged
merged 7 commits into from
Oct 7, 2024

Conversation

munificent
Copy link
Member

When using the dart format CLI (and not the library API), if the user doesn't specify a page width using --line-length, then the formatter will walk the directories surrounding each formatted file looking for an analysis_options.yaml file. If one is found, then it looks for a configured page width like:

formatter:
  page_width: 123

If found, then the file is formatted at that page width. If any sort of failure occurs, the default page width is used instead.

This is hidden behind the "tall-style" experiment flag and the intent is to ship this when the rest of the new tall style ships.

This is a fairly large change. To try to make it easier to review, I broke it into a series of hopefully more digestible commits. You might want to review those separately.

Fix #833.

cc @mit-mit

This can find, read, and merge them. It handles `include` inside the
file.

It works using an abstraction over the file system so that (in theory at
least), this code could be harvested and made reusable by other tools
that need to work with analysis_options.yaml files but don't want to
work directly with files on disk.

It also includes an implementation of that abstraction using dart:io.

Right now, this is all just private inside dart_style, but is organized
so that it would be easy to pull out into a separate package later if we
want.
It was getting pretty huge. I didn't want to stuff more tests in there
for CLI integration of analysis_options, so splitting it up into smaller
files first.

There are no meaningful changes here, just moving code around.
When formatting from the CLI using files or stdin with a --stdin-name
option, looks in the surrounding directories for an
analysis_options.yaml file. If found and the file specifies a formatter
page width, uses that.

Handles includes and merging as well. Doesn't handle "package:" includes
yet.
lib/src/analysis_options/analysis_options_file.dart Outdated Show resolved Hide resolved
lib/src/analysis_options/io_file_system.dart Outdated Show resolved Hide resolved
@munificent munificent merged commit 9c17d3b into main Oct 7, 2024
7 checks passed
@munificent munificent deleted the analysis-options branch October 7, 2024 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rethink the 80 characters line limit
3 participants