Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider generating code compliant with implicit-dynamic: false #278

Closed
knaeckeKami opened this issue Dec 13, 2019 · 2 comments
Closed

Consider generating code compliant with implicit-dynamic: false #278

knaeckeKami opened this issue Dec 13, 2019 · 2 comments

Comments

@knaeckeKami
Copy link
Contributor

knaeckeKami commented Dec 13, 2019

Context:

A dart project can contain an analysis_options.yaml file that enables stricter type checking.
One of these options is
implicit-dynamic: false
which will prevent the compiler from inferring dynamic unless it's explicitly annotated.

I propose changes to make the moor generator compatible with these stricter type checks.
They might be enabled by default in the future, anyway.
A somewhat related option
implicit-casts: false will be enabled by default, when NNBD lands. ( see dart-lang/sdk#31410 (comment) ).

Projects that use implicit-dynamic: false and moor_generator currently need to exclude generated files from this rule ( e.g. by using exclude: [ lib/**/*.g.dart] in their analysis_options.yaml).
If this rule becomes the default in the future, all users of moor_generator would need to exclude thee files generated by moor_generator.

The steps needed to make the code compliant would be.

  1. change the generated == methods from
bool operator ==(other) {

to

bool operator ==(Object other) {
  1. change the generated toJson() methods from
@override
Map<String, dynamic> toJson(
      {ValueSerializer serializer = const ValueSerializer.defaults()}) {
    return {
      'key': serializer.toJson<String>(key),
      ...
    };
}

to

@override
Map<String, dynamic> toJson(
      {ValueSerializer serializer = const ValueSerializer.defaults()}) {
    return <String, dynamic>{
      'key': serializer.toJson<String>(key),
      ...
    };
}
@simolus3
Copy link
Owner

Thanks for the request and the detailed description. With the next generator release, the code will be compliant with implicit-dynamic: false. See also #268.

@knaeckeKami
Copy link
Contributor Author

Oh, sorry for the duplicate, I missed #268 somehow, even though it's worded nearly identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants