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 page_width from analysis_options in builders #1653

Open
schultek opened this issue Feb 20, 2025 · 0 comments
Open

Support page_width from analysis_options in builders #1653

schultek opened this issue Feb 20, 2025 · 0 comments

Comments

@schultek
Copy link

Not sure if this is better opened here or in the build repository. Please move where you prefer it.

I'd like to update my build_runner packages to use the new project-wide page_width setting for generated Dart code. Currently packages either generate unformatted code, or need to hardcode a page-width value or use a proprietary configuration.
Using the new project wide formatter configuration would enable all build_runner packages to always generate correctly formatted code based on the users preference.


For example, I'm using a custom build options property 'lineLength':

var pageWidth = options.lineLength;

var formatter = DartFormatter(
  languageVersion: Version(3, 7, 0),
  pageWidth: pageWidth,
);

await buildStep.writeAsString(outputId, formatter.format(source));

What I'd like to do is this:

var pageWidth = options.lineLength;

if (pageWidth == null) {
  // This doesn't exist.
 pageWidth = DartFormatter.findPageWidthFromAnalysisOptions();
}

var formatter = DartFormatter(
  languageVersion: Version(3, 7, 0),
  pageWidth: pageWidth,
);

await buildStep.writeAsString(outputId, formatter.format(source));

However I didn't find any way to do it.

Looking through this packages source, I found the ConfigCache().findPageWidth(...) method, but this accepts a File and build strongly discourages any file based io, mainly by not giving me any file paths I could use here (it only has AssetIds).

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

No branches or pull requests

1 participant