Skip to content

Commit 7a01454

Browse files
Merge pull request #14 from Workiva/dart2_upgrade_codemod
AF-3911 Finish the Dart 2 Upgrade codemod
2 parents 799b786 + 2b04d4a commit 7a01454

File tree

46 files changed

+1769
-583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1769
-583
lines changed

README.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,29 @@ pub global activate over_react_codemod
1818
Once you've activated this package, you should be able to run whichever codemods
1919
you need via `pub global run`.
2020

21-
## Dart 1 to Dart 2 Codemods
21+
## Dart 1 to Dart 2 Codemod
22+
23+
This package provides a `dart2_upgrade` codemod that will modify existing
24+
over_react component code to be compatible with Dart 2 and the over_react
25+
builder.
2226

2327
Depending on your needs, you may be able to upgrade directly from Dart 1 to
2428
Dart 2, or you may need to take an intermediary step and provide a version of
25-
your codebase that is both forwards- and backwards-compatible.
26-
27-
This package provides three codemod executables:
28-
29-
- `pub global run over_react_codemod:dart1_to_dart2`
29+
your codebase that is both forwards- and backwards-compatible. Both of these
30+
options are supported by this codemod.
3031

31-
Use this codemod if you want to migrate directly from Dart 1 compatibile
32-
code to Dart 2 compatible code and do not need to provide a version that is
33-
compatible with both.
34-
35-
_Still in progress; coming soon._
36-
37-
- `pub global run over_react_codemod:dart1_to_dart1_and_dart2`
32+
- `pub global run over_react_codemod:dart2_upgrade --backwards-compat`
3833

3934
Use this codemod to migrate your over_react code to a format that is both
4035
forwards-compatible with Dart 2 and backwards-compatible with Dart 1.
4136

42-
- `pub global run over_react_codemod:dart1_and_dart2_to_dart2`
43-
44-
Use this codemod to migrate over_react code that has previously been
45-
migrated via the `dart1_to_dart1_and_dart2` codemod to the form that is only
46-
compatible with Dart 2. In other words, use this when you're ready to drop
47-
Dart 1 support.
37+
- `pub global run over_react_codemod:dart2_upgrade`
4838

49-
_Still in progress; coming soon._
39+
Use this codemod if you want to migrate to Dart 2 compatible code and do not
40+
need to maintain backwards-compatability with Dart 1. You can run this to
41+
immediately upgrade from Dart 1 to Dart 2, or you can run this on code that
42+
has already been run through this codemod with the `--backwards-compat`
43+
flag once you're ready to drop Dart 1 support.
5044

5145
For more information on the transition from Dart 1 to Dart 2 and how it affects
5246
over_react, check out the [over_react Dart 2 migration guide](over_react_dart2).
@@ -69,7 +63,7 @@ checklist will prevent merging code that is not in the form that is compatible
6963
with both Dart 1 and Dart 2:
7064

7165
```bash
72-
pub global run over_react_codemod:dart1_to_dart1_and_dart2 --fail-on-changes
66+
pub global run over_react_codemod:dart2_upgrade --fail-on-changes
7367
```
7468

7569
## Ignoring Codemod Suggestions
@@ -87,8 +81,8 @@ of ending with `StateMixin`, but isn't actually an over_react state mixin:
8781
class Foo extends Object with BarStateMixin {}
8882
```
8983

90-
As is, the `dart1_to_dart1_and_dart2` codemod would find this code and attempt
91-
to change it to:
84+
As is, the `dart2_upgrade --backwards-compat` codemod would find this code and
85+
attempt to change it to:
9286

9387
```dart
9488
class Foo extends Object

bin/dart1_to_dart1_and_dart2.dart renamed to bin/dart2_upgrade.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
export 'package:over_react_codemod/src/d1_to_d1_and_d2/executable.dart';
15+
export 'package:over_react_codemod/src/executables/dart2_upgrade.dart';

lib/src/constants.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ const List<String> overReactAnnotationNames = const [
3636
'StateMixin',
3737
];
3838

39+
const List<String> overReactPropsStateAnnotationNames = const [
40+
'Props',
41+
'State',
42+
'AbstractProps',
43+
'AbstractState',
44+
'PropsMixin',
45+
'StateMixin',
46+
];
47+
3948
/// Annotation names for over_react's props and state classes, excluding the
4049
/// mixin annotations.
4150
const List<String> overReactPropsStateNonMixinAnnotationNames = const [
@@ -56,3 +65,7 @@ const String propsMetaType = 'PropsMeta';
5665

5766
/// Dart type for the static meta field on state classes.
5867
const String stateMetaType = 'StateMeta';
68+
69+
/// Comment text that is attached to the props/state companion classes.
70+
const String temporaryCompanionClassComment =
71+
'This will be removed once the transition to Dart 2 is complete.';

lib/src/d1_to_d1_and_d2/executable.dart

Lines changed: 0 additions & 108 deletions
This file was deleted.

lib/src/d1_to_d1_and_d2/util.dart

Lines changed: 0 additions & 181 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/src/d1_to_d1_and_d2/suggestors/needs_over_react_library_collector.dart renamed to lib/src/dart2_suggestors/needs_over_react_library_collector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'package:analyzer/analyzer.dart';
1616
import 'package:codemod/codemod.dart';
1717
import 'package:path/path.dart' as p;
1818

19-
import '../../util.dart';
19+
import '../util.dart';
2020
import 'over_react_generated_part_directive_adder.dart';
2121

2222
/// Suggestor that collects the set of libraries that need an over_react

0 commit comments

Comments
 (0)