Description
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 AssetId
s).