json_serializable_lints 0.1.0 copy "json_serializable_lints: ^0.1.0" to clipboard
json_serializable_lints: ^0.1.0 copied to clipboard

Dart custom lint rules for json_serializable package.

json_serializable_lints #

Small analysis server plugin with focused lints for json_serializable models.

Rules #

  • require_json_serializable_from_json
    Requires factory ClassName.fromJson(Map<String, dynamic> json) on @JsonSerializable() classes.
  • require_json_serializable_to_json
    Requires Map<String, dynamic> toJson() on @JsonSerializable() classes.

These rules are skipped when you explicitly disable generation with createFactory: false or createToJson: false.

Usage #

Add the package to your Dart or Flutter project:

# pubspec.yaml
dev_dependencies:
  json_serializable_lints:

Enable the plugin:

# analysis_options.yaml
analyzer:
  plugins:
    - json_serializable_lints

Minimal example:

import 'package:json_annotation/json_annotation.dart';

part 'user.g.dart';

@JsonSerializable()
class User {
  final String name;

  User(this.name);

  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
  Map<String, dynamic> toJson() => _$UserToJson(this);
}

Ignoring rules #

Ignore a single violation:

// ignore: require_json_serializable_to_json
@JsonSerializable()
class LegacyUser {
  LegacyUser();

  factory LegacyUser.fromJson(Map<String, dynamic> json) => LegacyUser();
}

Ignore for a whole file:

// ignore_for_file: require_json_serializable_from_json, require_json_serializable_to_json

More info #

Contributing #

Contributions, issues, and pull requests are welcome.

1
likes
0
points
158
downloads

Publisher

verified publisherleithmail.org

Weekly Downloads

Dart custom lint rules for json_serializable package.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analysis_server_plugin, analyzer

More

Packages that depend on json_serializable_lints