over_react_codemod 1.5.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 44

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
        // 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
        // orcm_ignore
        BarStateMixin {}

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

1.4.3 #

  • Revert react16_upgrade change in 1.4.0 that forced over_react to be added whenever just react was listed as a dependency

1.4.2 #

  • Ignore .g.dart files in React 16 codemods.

1.4.1 #

  • Fix a bug that would cause ErrorBoundary components with props to be wrapped in another ErrorBoundary.

1.4.0 #

  • Update Component2 ComponentWillMountMigrator to migrate the componentWillMount lifecycle code to componentDidMount
  • Add React 16 getDefaultProps & getInitialState Migrator
  • Add React 16 Post Rollout Codemod
  • Update React 16 pubspec updater to include over_react

1.3.2 #

  • Enable the use of // orcm_ignore comments when running the react16 / component2 codemods.

1.3.1 #

  • Fix a bug that would occur when parsing a pubspec version of "any"

1.3.0 #

  • Add a flag --no-partial-upgrades to component2_upgrade codemod that will prevent partial component upgrades from occurring.

  • Fix a bug that could occur when parsing a pubsec version in dependency_overrides section.

1.2.0 #

  • Add react16_upgrade codemod

    • Fix compatibility issues common in react15 code.
    • Update version upper bound of react and over_react in pubspec.yaml to allow for incoming react16 updates.
  • Add component2_upgrade codemod

    • Migrates components to UiComponent2 (coming in over_react 3.1.0)
  • Add react16_dependency_override_update codemod

    • Adds dependency overrides to pubspec.yaml for testing wip branches of React 16
  • Add react16_ci_precheck codemod

    • Checks the version ranges of over_react and react and if they are in transition will run the codemod and fail if there are unaddressed issues.

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!



$ pub global activate over_react_codemod


$ 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:

$ component2_upgrade
$ dart2_upgrade
$ react16_ci_precheck
$ react16_consumer_overlay_update
$ react16_dependency_override_update
$ react16_post_rollout_cleanup
$ react16_upgrade
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6

Health suggestions

Fix lib/src/ignoreable.dart. (-0.50 points)

Analysis of lib/src/ignoreable.dart reported 1 hint:

line 16 col 8: Unused import: 'package:path/path.dart'.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

exitCode: 255 stdout: parsing /dart-sdk/lib/async/async.dart... parsing /dart-sdk/lib/collection/collection.dart... parsing /dart-sdk/lib/internal/internal.dart... parsing /dart-sdk/lib/convert/convert.dart... parsing /dart-sdk/lib/typed_data/typed_data.dart... parsing /dart-sdk/lib/core/core.dart... parsing /dart-sdk/lib/math/math.dart... parsing /dart-sdk/lib/developer/developer.dart... parsing /dart-sdk/lib/isolate/isolate.dart... parsing /dart-sdk/lib/ffi/ffi.dart... parsing /dart-sdk/lib/html/dart2js/html_dart2js.dart... parsing /dart-sdk/lib/html/html_common/html_common_dart2js.dart... parsing /dart-sdk/lib/web_gl/dart2js/web_gl_dart2js.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/native_typed_data.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/interceptors.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/shared/embedded_names.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/js_helper.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/foreign_helper.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/js_names.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/rti.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/shared/recipe_syntax.dart... parsing /dart-sdk/lib/js_util/dart2js/js_util_dart2js.dart... parsing /dart-sdk/lib/html/html_common/metadata.dart... parsing /dart-sdk/lib/indexed_db/dart2js/indexed_db_dart2js.dart... parsing /dart-sdk/lib/svg/dart2js/svg_dart2js.dart... parsing /dart-sdk/lib/web_audio/dart2js/web_audio_dart2js.dart... parsing /dart-sdk/lib/web_sql/dart2js/web_sql_dart2js.dart... parsing /dart-sdk/lib/_http/http.dart... parsing /dart-sdk/lib/io/io.dart... parsing /dart-sdk/lib/js/dart2js/js_dart2js.dart... parsing /dart-sdk/lib/js/_js.dart... parsing /dart-sdk/lib/mirrors/mirrors.dart... parsing /dart-sdk/lib/html/dartium/nativewrappers.dart... parsing /dart-sdk/lib/cli/cli.dart... parsing /dart-sdk/lib/wasm/wasm.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/js_primitives.dart... parsing /dart-sdk/lib/_internal/js_runtime/lib/shared/async_await_error_codes.dart... Initialized dartdoc with 37 libraries in 29.1 seconds documenting over_react_codemod Validating docs... no issues found Documented 0 public libraries in 1.5 seconds stderr: Documenting over_react_codemod... Unhandled exception: dartdoc could not find any libraries to document #0 Dartdoc.generateDocs (package:dartdoc/dartdoc.dart:196:7)

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (analyzer, codemod).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
analyzer >=0.37.0 <0.39.0 0.38.5 0.39.6
args ^1.5.1 1.6.0
codemod ^0.1.5 0.1.5 0.2.0
logging ^0.11.3+2 0.11.4
meta ^1.1.7 1.1.8
path ^1.6.2 1.6.4
pub_semver ^1.4.2 1.4.4
source_span ^1.4.1 1.7.0
yaml ^2.1.16 2.2.0
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
front_end 0.1.27 0.1.29
glob 1.2.0
html 0.14.0+3
io 0.3.4
js 0.6.1+1
kernel 0.3.27 0.3.29
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.9.3
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+14
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 1.9.0
react ^4.6.1
test ^1.5.1