diff --git a/lib/src/tools/over_react_format_tool.dart b/lib/src/tools/over_react_format_tool.dart index 888a559f..1e33463c 100644 --- a/lib/src/tools/over_react_format_tool.dart +++ b/lib/src/tools/over_react_format_tool.dart @@ -13,6 +13,11 @@ class OverReactFormatTool extends DevTool { /// Default is 80. int? lineLength; + /// Whether or not to organize import/export directives. + /// + /// Default is false. + bool? organizeDirectives; + @override String? description = 'Format dart files in this package with over_react_format.'; @@ -31,7 +36,8 @@ class OverReactFormatTool extends DevTool { final args = [ 'run', 'over_react_format', - if (lineLength != null) '--line-length=$lineLength' + if (lineLength != null) '--line-length=$lineLength', + if (organizeDirectives == true) '--organize-directives', ]; final process = ProcessDeclaration(exe.dart, [...args, ...paths], mode: ProcessStartMode.inheritStdio); diff --git a/lib/src/utils/format_tool_builder.dart b/lib/src/utils/format_tool_builder.dart index cb1113dd..58c55460 100644 --- a/lib/src/utils/format_tool_builder.dart +++ b/lib/src/utils/format_tool_builder.dart @@ -88,6 +88,17 @@ class FormatToolBuilder extends GeneralizingAstVisitor { logWarningMessageFor(KnownErrorOutcome.failedToParseFormatterArgs); } } + + final organizeDirectives = getCascadeByProperty('organizeDirectives'); + if (organizeDirectives != null) { + final valueExpression = organizeDirectives.rightHandSide; + if (valueExpression is BooleanLiteral) { + typedFormatDevTool.organizeDirectives = valueExpression.value; + } else { + logWarningMessageFor( + KnownErrorOutcome.failedToParseOrganizeDirective); + } + } } else if (typedFormatDevTool is OverReactFormatTool) { final lineLengthAssignment = getCascadeByProperty('lineLength'); if (lineLengthAssignment != null) { @@ -98,6 +109,18 @@ class FormatToolBuilder extends GeneralizingAstVisitor { logWarningMessageFor(KnownErrorOutcome.failedToParseLineLength); } } + + final organizeDirectivesAssignment = + getCascadeByProperty('organizeDirectives'); + if (organizeDirectivesAssignment != null) { + final valueExpression = organizeDirectivesAssignment.rightHandSide; + if (valueExpression is BooleanLiteral) { + typedFormatDevTool.organizeDirectives = valueExpression.value; + } else { + logWarningMessageFor( + KnownErrorOutcome.failedToParseOrganizeDirective); + } + } } } } @@ -108,6 +131,7 @@ enum KnownErrorOutcome { failedToReconstructFormatterArgs, failedToParseFormatterArgs, failedToParseLineLength, + failedToParseOrganizeDirective, } void logWarningMessageFor(KnownErrorOutcome outcome) { @@ -137,6 +161,12 @@ This is likely because the list is not a ListLiteral. errorMessage = '''Failed to parse the line-length configuration. This is likely because assignment does not use an IntegerLiteral. +'''; + break; + case KnownErrorOutcome.failedToParseOrganizeDirective: + errorMessage = '''Failed to parse the organizeDirectives configuration. + +This is likely because assignment does not use an BooleanLiteral. '''; break; }