Skip to content

Commit

Permalink
Merge pull request #26 from Workiva/reorder_suggestors
Browse files Browse the repository at this point in the history
CPLAT-4451 Reorder suggestors and improve the UI factory ignore remover
  • Loading branch information
rmconsole7-wk authored Feb 26, 2019
2 parents 78252b1 + ef8ccf9 commit 9969860
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ class UiFactoryIgnoreCommentRemover extends RecursiveAstVisitor
if (_ignoreLines.contains(initializerLineNum)) {
final currentFactory = sourceFile
.span(
node.offset,
node.metadata.beginToken.offset,
node.end,
)
.text;
final updatedFactory = currentFactory.replaceFirst(ignorePattern, '');
yieldPatch(
node.offset,
node.metadata.beginToken.offset,
node.end,
updatedFactory,
);
Expand Down
71 changes: 40 additions & 31 deletions lib/src/executables/dart2_upgrade.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,51 +83,60 @@ void main(List<String> args) {
}

final needsOverReactLibraryCollector = NeedsOverReactLibraryCollector();
final phaseTwoSuggestors = <Suggestor>[
needsOverReactLibraryCollector,
UiFactoryInitializer(includeIgnore: backwardsCompat),
ComponentDefaultPropsMigrator(),
DollarPropsMigrator(),
DollarPropKeysMigrator(),
PropsAndStateClassesRenamer(renameMixins: !backwardsCompat),
]..addAll(backwardsCompat
? [

final suggestorSequence = <Suggestor>[
AggregateSuggestor(
<Suggestor>[
needsOverReactLibraryCollector,
UiFactoryInitializer(includeIgnore: backwardsCompat),
ComponentDefaultPropsMigrator(),
DollarPropsMigrator(),
DollarPropKeysMigrator(),
PropsAndStateClassesRenamer(renameMixins: !backwardsCompat),
].map((s) => Ignoreable(s)),
),
GeneratedPartDirectiveAdder(
needsOverReactLibraryCollector,
),
];

if (backwardsCompat) {
suggestorSequence.add(
AggregateSuggestor(
<Suggestor>[
PropsAndStateCompanionClassAdder(commentPrefix: commentPrefix),
PropsAndStateMixinMetaAdder(),
PropsAndStateMixinUsageDoubler(),
]
: [
].map((s) => Ignoreable(s)),
),
);
} else {
suggestorSequence.addAll([
AggregateSuggestor(
// These suggestors mainly clean up the transitional boilerplate
// introduced by the backwards-compat suggestors. As such, they do not
// need to be ignoreable.
<Suggestor>[
GeneratedPartDirectiveIgnoreRemover(),
UiFactoryIgnoreCommentRemover(),
PropsAndStateMixinMetaRemover(),
PropsAndStateMixinUsageConsolidator(),
GeneratedPartDirectiveIgnoreRemover(),
OrcmIgnoreRemover(),
]);

final phaseThreeSuggestors = <Suggestor>[
Ignoreable(
GeneratedPartDirectiveAdder(
needsOverReactLibraryCollector,
PropsAndStateCompanionClassRemover(),
],
),
),
];
if (!backwardsCompat) {
phaseThreeSuggestors.add(PropsAndStateCompanionClassRemover());
// The orcm_ignore comments could be anywhere in the source, which makes
// them a high-risk for producing overlapping patches with other
// suggestors. For that reason, we run it by itself and not in aggregate.
OrcmIgnoreRemover(),
]);
}

exitCode = runInteractiveCodemodSequence(
FileQuery.dir(
pathFilter: isDartFile,
recursive: true,
),
[
AggregateSuggestor(
phaseTwoSuggestors.map((s) => Ignoreable(s)),
),
AggregateSuggestor(
phaseThreeSuggestors.map((s) => Ignoreable(s)),
)
],
suggestorSequence,
args: args,
defaultYes: true,
changesRequiredOutput: _changesRequiredOutput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ UiFactory Foo =
UiFactory<_CustomColorInputProps> _CustomColorInput = _$_CustomColorInput;
<<<
@Factory()
UiFactory<_CustomColorInputProps> _CustomColorInput = _$_CustomColorInput;
UiFactory<_CustomColorInputProps> _CustomColorInput = _$_CustomColorInput;


>>> factory with doc comment (patches 1)
/// Doc comment.
/// Line 2.
/// Line 3.
@Factory()
UiFactory Foo =
// ignore: undefined_identifier
_$Foo;
<<<
/// Doc comment.
/// Line 2.
/// Line 3.
@Factory()
UiFactory Foo =
_$Foo;

0 comments on commit 9969860

Please sign in to comment.