over_react_codemod 1.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 50

Over React Codemods #

Pub Build Status

Built with dart_codemod.

Codemods to help consumers of over_react automate the migration of UI component code. Currently, the only use cases are around upgrading from Dart 1 to Dart 2.

Installation #

Note: this package requires Dart SDK version 2.1.0 to run, but the codemods themselves are designed to run on code that is written for Dart 1.x or 2.x.

pub global activate over_react_codemod

Once you've activated this package, you should be able to run whichever codemods you need via pub global run.

Dart 1 to Dart 2 Codemod #

This package provides a dart2_upgrade codemod that will modify existing over_react component code to be compatible with Dart 2 and the over_react builder.

Depending on your needs, you may be able to upgrade directly from Dart 1 to Dart 2, or you may need to take an intermediary step and provide a version of your codebase that is both forwards- and backwards-compatible. Both of these options are supported by this codemod.

  • pub global run over_react_codemod:dart2_upgrade --backwards-compat

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

  • pub global run over_react_codemod:dart2_upgrade

    Use this codemod if you want to migrate to Dart 2 compatible code and do not need to maintain backwards-compatability with Dart 1. You can run this to immediately upgrade from Dart 1 to Dart 2, or you can run this on code that has already been run through this codemod with the --backwards-compat flag once you're ready to drop Dart 1 support.

For more information on the transition from Dart 1 to Dart 2 and how it affects over_react, check out the over_react Dart 2 migration guide. It includes sample diffs of the changes that these codemods will introduce.

Checking for Regressions #

Especially in the case where a forwards- and backwards-compatible version of your code is necessary, it can be helpful to be able to check automatically for regressions after having initially migrated your code. Doing so will help prevent accidentally merging code that doesn't meet your compatability expectations.

Each of these codemods can be run in a --fail-on-changes mode that will count the number of changes that would have been suggested and exit with a non-zero exit code if that number is greater than 0.

As an example, adding the following command to your CI process or pre-merge checklist will prevent merging code that is not in the form that is compatible with both Dart 1 and Dart 2:

pub global run over_react_codemod:dart2_upgrade --fail-on-changes

Ignoring Codemod Suggestions #

Some of the changes provided by the codemods in this package are based on imperfect heuristics (e.g. looking for a specific naming convention) and consequently may be susceptible to false positives. If you hit such a case in your codebase, you can tell the codemod to ignore a certain line by attaching an ignore comment either on the same line or the immediately preceding line.

For example, consider a mixin usage that happens to match the naming convention of ending with StateMixin, but isn't actually an over_react state mixin:

class Foo extends Object with BarStateMixin {}

As is, the dart2_upgrade --backwards-compat codemod would find this code and attempt to change it to:

class Foo extends Object
    with
        BarStateMixin,
        // ignore: mixin_of_non_class, undefined_class
        $BarStateMixin {}

But if BarStateMixin isn't actually an over_react state mixin, then this updated code will fail. To avoid this problem, simply add an // orcm_ignore comment to the mixin type that should be ignored:

class Foo extends Object
    with
        // orcm_ignore
        BarStateMixin {}

This ignore mechanism works with any of the changes that the codemods in this package will try to suggest.

1.1.0 #

  • Two additional changes are now made by the dart2_upgrade codemod when running without the --backwards-compat flag:

    • // orcm_ignore comments are removed
    • // ignore: uri_has_not_been_generated comments that precede a .over_react.g.dart part directive are removed
  • Fix a bug that could result in overlapping patches being suggested, which would cause the dart2_upgrade codemod to exit early unsuccessfully.

1.0.2 #

  • Provide additional output from the dart2_upgrade codemod in the following two scenarios:

    • When running with the -h|--help flag
    • When running with the --fail-on-changes flag

1.0.1 #

  • Fix a bug with removing the // ignore: undefined_identifier comment from UI Factories when running over_react_codemod:dart2_upgrade without the --backwards-compat flag.

1.0.0 #

  • Initial release!

example/README.md

Installation:

$ pub global activate over_react_codemod

Usage:

$ pub global run over_react_codemod:dart2_upgrade

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate over_react_codemod

2. Use it

The package has the following executables:


$ dart2_upgrade
Version Uploaded Documentation Archive
1.1.0 Feb 26, 2019 Go to the documentation of over_react_codemod 1.1.0 Download over_react_codemod 1.1.0 archive
1.0.2 Feb 6, 2019 Go to the documentation of over_react_codemod 1.0.2 Download over_react_codemod 1.0.2 archive
1.0.1 Jan 29, 2019 Go to the documentation of over_react_codemod 1.0.1 Download over_react_codemod 1.0.1 archive
1.0.0 Jan 23, 2019 Go to the documentation of over_react_codemod 1.0.0 Download over_react_codemod 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Apr 25, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer ^0.33.6+1 0.33.6+1 0.36.2
args ^1.5.1 1.5.1
codemod ^0.1.3 0.1.3
path ^1.6.2 1.6.2
pub_semver ^1.4.2 1.4.2
source_span ^1.4.1 1.5.5
Transitive dependencies
async 2.2.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
crypto 2.0.6
csslib 0.16.0
front_end 0.1.6+9 0.1.17
glob 1.1.7
html 0.14.0+2
io 0.3.3
kernel 0.3.6+9 0.3.17
logging 0.11.3+2
meta 1.1.7
package_config 1.0.5
plugin 0.2.0+3
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+10
yaml 2.1.15
Dev dependencies
dart_dev ^2.0.1
dart_style ^1.2.0
dependency_validator ^1.2.3
mockito ^4.0.0
pedantic ^1.4.0
test ^1.5.1