json_serializable_lints 0.1.0
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
Requiresfactory ClassName.fromJson(Map<String, dynamic> json)on@JsonSerializable()classes.require_json_serializable_to_json
RequiresMap<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.