Apply pedantic lints
This commit is contained in:
parent
642a7d98a8
commit
447f479747
5 changed files with 30 additions and 18 deletions
|
@ -53,12 +53,14 @@ Expression convertObject(DartObject o) {
|
|||
if (o.toBoolValue() != null) return literalBool(o.toBoolValue());
|
||||
if (o.toIntValue() != null) return literalNum(o.toIntValue());
|
||||
if (o.toDoubleValue() != null) return literalNum(o.toDoubleValue());
|
||||
if (o.toSymbolValue() != null)
|
||||
if (o.toSymbolValue() != null) {
|
||||
return CodeExpression(Code('#' + o.toSymbolValue()));
|
||||
}
|
||||
if (o.toStringValue() != null) return literalString(o.toStringValue());
|
||||
if (o.toTypeValue() != null) return convertTypeReference(o.toTypeValue());
|
||||
if (o.toListValue() != null)
|
||||
if (o.toListValue() != null) {
|
||||
return literalList(o.toListValue().map(convertObject));
|
||||
}
|
||||
if (o.toMapValue() != null) {
|
||||
return literalMap(o
|
||||
.toMapValue()
|
||||
|
@ -80,8 +82,9 @@ String dartObjectToString(DartObject v) {
|
|||
if (v.toDoubleValue() != null) return v.toDoubleValue().toString();
|
||||
if (v.toSymbolValue() != null) return '#' + v.toSymbolValue();
|
||||
if (v.toTypeValue() != null) return v.toTypeValue().name;
|
||||
if (v.toListValue() != null)
|
||||
if (v.toListValue() != null) {
|
||||
return 'const [' + v.toListValue().map(dartObjectToString).join(', ') + ']';
|
||||
}
|
||||
if (v.toMapValue() != null) {
|
||||
return 'const {' +
|
||||
v.toMapValue().entries.map((entry) {
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'package:analyzer/dart/constant/value.dart';
|
|||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:angel_model/angel_model.dart';
|
||||
import 'package:angel_serialize/angel_serialize.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
|
|
@ -6,8 +6,9 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
@override
|
||||
Future<String> generateForAnnotatedElement(
|
||||
Element element, ConstantReader annotation, BuildStep buildStep) async {
|
||||
if (element.kind != ElementKind.CLASS)
|
||||
if (element.kind != ElementKind.CLASS) {
|
||||
throw 'Only classes can be annotated with a @Serializable() annotation.';
|
||||
}
|
||||
|
||||
var ctx = await buildContext(element as ClassElement, annotation, buildStep,
|
||||
await buildStep.resolver, true);
|
||||
|
@ -138,9 +139,9 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
b.defaultTo = Code(dartObjectToString(existingDefault));
|
||||
}
|
||||
|
||||
if (!isListOrMapType(field.type))
|
||||
if (!isListOrMapType(field.type)) {
|
||||
b.toThis = true;
|
||||
else {
|
||||
} else {
|
||||
b.type = convertTypeReference(field.type);
|
||||
}
|
||||
|
||||
|
@ -153,9 +154,10 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
|
||||
if (ctx.constructorParameters.isNotEmpty) {
|
||||
if (!shouldBeConstant(ctx) ||
|
||||
ctx.clazz.unnamedConstructor?.isConst == true)
|
||||
ctx.clazz.unnamedConstructor?.isConst == true) {
|
||||
constructor.initializers.add(Code(
|
||||
'super(${ctx.constructorParameters.map((p) => p.name).join(',')})'));
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -209,16 +211,18 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
if (type.typeParameters.length == 1) {
|
||||
var eq = generateEquality(type.typeArguments[0]);
|
||||
return 'ListEquality<${type.typeArguments[0].name}>($eq)';
|
||||
} else
|
||||
} else {
|
||||
return 'ListEquality()';
|
||||
}
|
||||
} else if (const TypeChecker.fromRuntime(Map)
|
||||
.isAssignableFromType(type)) {
|
||||
if (type.typeParameters.length == 2) {
|
||||
var keq = generateEquality(type.typeArguments[0]),
|
||||
veq = generateEquality(type.typeArguments[1]);
|
||||
return 'MapEquality<${type.typeArguments[0].name}, ${type.typeArguments[1].name}>(keys: $keq, values: $veq)';
|
||||
} else
|
||||
} else {
|
||||
return 'MapEquality()';
|
||||
}
|
||||
}
|
||||
|
||||
return nullable ? null : 'DefaultEquality<${type.name}>()';
|
||||
|
@ -228,8 +232,9 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
}
|
||||
|
||||
static String Function(String, String) generateComparator(DartType type) {
|
||||
if (type is! InterfaceType || type.name == 'dynamic')
|
||||
if (type is! InterfaceType || type.name == 'dynamic') {
|
||||
return (a, b) => '$a == $b';
|
||||
}
|
||||
var eq = generateEquality(type, true);
|
||||
if (eq == null) return (a, b) => '$a == $b';
|
||||
return (a, b) => '$eq.equals($a, $b)';
|
||||
|
|
|
@ -8,8 +8,9 @@ class SerializerGenerator extends GeneratorForAnnotation<Serializable> {
|
|||
@override
|
||||
Future<String> generateForAnnotatedElement(
|
||||
Element element, ConstantReader annotation, BuildStep buildStep) async {
|
||||
if (element.kind != ElementKind.CLASS)
|
||||
if (element.kind != ElementKind.CLASS) {
|
||||
throw 'Only classes can be annotated with a @Serializable() annotation.';
|
||||
}
|
||||
|
||||
var ctx = await buildContext(element as ClassElement, annotation, buildStep,
|
||||
await buildStep.resolver, autoSnakeCaseNames != false);
|
||||
|
@ -147,8 +148,9 @@ class ${pascal}Decoder extends Converter<Map, ${pascal}> {
|
|||
}
|
||||
|
||||
// Serialize dates
|
||||
else if (dateTimeTypeChecker.isAssignableFromType(type))
|
||||
else if (dateTimeTypeChecker.isAssignableFromType(type)) {
|
||||
serializedRepresentation = 'model.${field.name}?.toIso8601String()';
|
||||
}
|
||||
|
||||
// Serialize model classes via `XSerializer.toMap`
|
||||
else if (isModelClass(type)) {
|
||||
|
@ -266,10 +268,11 @@ class ${pascal}Decoder extends Converter<Map, ${pascal}> {
|
|||
var name =
|
||||
MirrorSystem.getName(ctx.fieldInfo[field.name].deserializer);
|
||||
deserializedRepresentation = "$name(map['$alias'])";
|
||||
} else if (dateTimeTypeChecker.isAssignableFromType(type))
|
||||
} else if (dateTimeTypeChecker.isAssignableFromType(type)) {
|
||||
deserializedRepresentation = "map['$alias'] != null ? "
|
||||
"(map['$alias'] is DateTime ? (map['$alias'] as DateTime) : DateTime.parse(map['$alias'].toString()))"
|
||||
" : $defaultValue";
|
||||
}
|
||||
|
||||
// Serialize model classes via `XSerializer.toMap`
|
||||
else if (isModelClass(type)) {
|
||||
|
|
|
@ -29,8 +29,9 @@ class TypeScriptDefinitionBuilder implements Builder {
|
|||
};
|
||||
|
||||
types.forEach((t, tsType) {
|
||||
if (TypeChecker.fromRuntime(t).isAssignableFromType(type))
|
||||
if (TypeChecker.fromRuntime(t).isAssignableFromType(type)) {
|
||||
typeScriptType = tsType;
|
||||
}
|
||||
});
|
||||
|
||||
if (type is InterfaceType) {
|
||||
|
@ -67,9 +68,9 @@ class TypeScriptDefinitionBuilder implements Builder {
|
|||
..writeln('}'));
|
||||
} else if (const TypeChecker.fromRuntime(List)
|
||||
.isAssignableFromType(type)) {
|
||||
if (type.typeArguments.isEmpty)
|
||||
if (type.typeArguments.isEmpty) {
|
||||
typeScriptType = 'any[]';
|
||||
else {
|
||||
} else {
|
||||
var arg = await compileToTypeScriptType(
|
||||
ctx, fieldName, type.typeArguments[0], refs, ext, buildStep);
|
||||
typeScriptType = '$arg[]';
|
||||
|
@ -139,8 +140,9 @@ class TypeScriptDefinitionBuilder implements Builder {
|
|||
}
|
||||
|
||||
for (var element in elements) {
|
||||
if (element.element.kind != ElementKind.CLASS)
|
||||
if (element.element.kind != ElementKind.CLASS) {
|
||||
throw 'Only classes can be annotated with a @Serializable() annotation.';
|
||||
}
|
||||
|
||||
var annotation = element.annotation;
|
||||
|
||||
|
|
Loading…
Reference in a new issue