Skip to content

Commit cc36448

Browse files
Merge pull request #438 from Workiva/hackFastFormat-support-organizeDirectives
FEDX-1727: Support `organizeDirectives` config via `hackFastFormat`
2 parents 7390f2d + 08f7f3d commit cc36448

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Diff for: lib/src/tools/over_react_format_tool.dart

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ class OverReactFormatTool extends DevTool {
1313
/// Default is 80.
1414
int? lineLength;
1515

16+
/// Whether or not to organize import/export directives.
17+
///
18+
/// Default is false.
19+
bool? organizeDirectives;
20+
1621
@override
1722
String? description =
1823
'Format dart files in this package with over_react_format.';
@@ -31,7 +36,8 @@ class OverReactFormatTool extends DevTool {
3136
final args = [
3237
'run',
3338
'over_react_format',
34-
if (lineLength != null) '--line-length=$lineLength'
39+
if (lineLength != null) '--line-length=$lineLength',
40+
if (organizeDirectives == true) '--organize-directives',
3541
];
3642
final process = ProcessDeclaration(exe.dart, [...args, ...paths],
3743
mode: ProcessStartMode.inheritStdio);

Diff for: lib/src/utils/format_tool_builder.dart

+30
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ class FormatToolBuilder extends GeneralizingAstVisitor<void> {
8888
logWarningMessageFor(KnownErrorOutcome.failedToParseFormatterArgs);
8989
}
9090
}
91+
92+
final organizeDirectives = getCascadeByProperty('organizeDirectives');
93+
if (organizeDirectives != null) {
94+
final valueExpression = organizeDirectives.rightHandSide;
95+
if (valueExpression is BooleanLiteral) {
96+
typedFormatDevTool.organizeDirectives = valueExpression.value;
97+
} else {
98+
logWarningMessageFor(
99+
KnownErrorOutcome.failedToParseOrganizeDirective);
100+
}
101+
}
91102
} else if (typedFormatDevTool is OverReactFormatTool) {
92103
final lineLengthAssignment = getCascadeByProperty('lineLength');
93104
if (lineLengthAssignment != null) {
@@ -98,6 +109,18 @@ class FormatToolBuilder extends GeneralizingAstVisitor<void> {
98109
logWarningMessageFor(KnownErrorOutcome.failedToParseLineLength);
99110
}
100111
}
112+
113+
final organizeDirectivesAssignment =
114+
getCascadeByProperty('organizeDirectives');
115+
if (organizeDirectivesAssignment != null) {
116+
final valueExpression = organizeDirectivesAssignment.rightHandSide;
117+
if (valueExpression is BooleanLiteral) {
118+
typedFormatDevTool.organizeDirectives = valueExpression.value;
119+
} else {
120+
logWarningMessageFor(
121+
KnownErrorOutcome.failedToParseOrganizeDirective);
122+
}
123+
}
101124
}
102125
}
103126
}
@@ -108,6 +131,7 @@ enum KnownErrorOutcome {
108131
failedToReconstructFormatterArgs,
109132
failedToParseFormatterArgs,
110133
failedToParseLineLength,
134+
failedToParseOrganizeDirective,
111135
}
112136

113137
void logWarningMessageFor(KnownErrorOutcome outcome) {
@@ -137,6 +161,12 @@ This is likely because the list is not a ListLiteral.
137161
errorMessage = '''Failed to parse the line-length configuration.
138162
139163
This is likely because assignment does not use an IntegerLiteral.
164+
''';
165+
break;
166+
case KnownErrorOutcome.failedToParseOrganizeDirective:
167+
errorMessage = '''Failed to parse the organizeDirectives configuration.
168+
169+
This is likely because assignment does not use an BooleanLiteral.
140170
''';
141171
break;
142172
}

0 commit comments

Comments
 (0)