diff --git a/packages/freezed/CHANGELOG.md b/packages/freezed/CHANGELOG.md index 886bbdb2..df7e1e73 100644 --- a/packages/freezed/CHANGELOG.md +++ b/packages/freezed/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased patch -Update docs (thanks to @lishaduck) +- Update docs (thanks to @lishaduck) +- Support Dart 3.6.0 and analyzer 6.9.0 as a minimum. ## 3.0.3 - 2025-03-02 diff --git a/packages/freezed/README.md b/packages/freezed/README.md index 17728090..4492198c 100644 --- a/packages/freezed/README.md +++ b/packages/freezed/README.md @@ -1237,6 +1237,8 @@ targets: options: # Tells Freezed to format .freezed.dart files. # This can significantly slow down code-generation. + # Disabling formatting will only work when opting into Dart 3.7 as a minimum + # in your project SDK constraints. format: true # Disable the generation of copyWith/== for the entire project copy_with: false diff --git a/packages/freezed/lib/src/ast.dart b/packages/freezed/lib/src/ast.dart index ec0e28b2..dc24bcfa 100644 --- a/packages/freezed/lib/src/ast.dart +++ b/packages/freezed/lib/src/ast.dart @@ -5,11 +5,9 @@ extension AstX on AstNode { String? get documentation { final builder = StringBuffer(); - for ( - Token? token = beginToken.precedingComments; - token != null; - token = token.next - ) { + for (Token? token = beginToken.precedingComments; + token != null; + token = token.next) { builder.writeln(token); } @@ -63,9 +61,8 @@ extension ConstructorX on ConstructorDeclaration { // ignore: deprecated_member_use, latest analyzer with enclosingElement3 not available in stable channel final classElement = declaredElement!.enclosingElement3; - var generics = classElement.typeParameters - .map((e) => '\$${e.name}') - .join(', '); + var generics = + classElement.typeParameters.map((e) => '\$${e.name}').join(', '); if (generics.isNotEmpty) { generics = '<$generics>'; } @@ -80,9 +77,8 @@ extension ConstructorX on ConstructorDeclaration { // ignore: deprecated_member_use, latest analyzer with enclosingElement3 not available in stable channel final classElement = declaredElement!.enclosingElement3; - var generics = classElement.typeParameters - .map((e) => '\$${e.name}') - .join(', '); + var generics = + classElement.typeParameters.map((e) => '\$${e.name}').join(', '); if (generics.isNotEmpty) { generics = '<$generics>'; } diff --git a/packages/freezed/lib/src/freezed_generator.dart b/packages/freezed/lib/src/freezed_generator.dart index 7244367a..ddf412a7 100644 --- a/packages/freezed/lib/src/freezed_generator.dart +++ b/packages/freezed/lib/src/freezed_generator.dart @@ -38,8 +38,7 @@ class FreezedGenerator extends ParserGenerator { if (deepCopyProperty == null || commonGetter == null) continue; yield deepCopyProperty.copyWith( - nullable: - deepCopyProperty.nullable || + nullable: deepCopyProperty.nullable || commonProperty.isNullable || commonGetter.isNullable, ); @@ -83,23 +82,21 @@ class FreezedGenerator extends ParserGenerator { Iterable _generateForData(Library globalData, Class data) sync* { if (data.options.fromJson) yield FromJson(data); - final commonCopyWith = - data.options.annotation.copyWith ?? true - ? CopyWith( - parents: data.parents, - clonedClassName: data.name, - readableProperties: data.properties.readableProperties, - cloneableProperties: data.properties.cloneableProperties, - deepCloneableProperties: - _getCommonDeepCloneableProperties( - data.constructors, - data.properties, - ).toList(), - genericsDefinition: data.genericsDefinitionTemplate, - genericsParameter: data.genericsParameterTemplate, - data: data, - ) - : null; + final commonCopyWith = data.options.annotation.copyWith ?? true + ? CopyWith( + parents: data.parents, + clonedClassName: data.name, + readableProperties: data.properties.readableProperties, + cloneableProperties: data.properties.cloneableProperties, + deepCloneableProperties: _getCommonDeepCloneableProperties( + data.constructors, + data.properties, + ).toList(), + genericsDefinition: data.genericsDefinitionTemplate, + genericsParameter: data.genericsParameterTemplate, + data: data, + ) + : null; yield Abstract( data: data, @@ -114,24 +111,21 @@ class FreezedGenerator extends ParserGenerator { constructor: constructor, commonProperties: data.properties.readableProperties, globalData: globalData, - copyWith: - data.options.annotation.copyWith ?? - constructor.parameters.allParameters.isNotEmpty - ? CopyWith( - parents: {}, - clonedClassName: constructor.redirectedName, - cloneableProperties: constructor.properties.toList(), - readableProperties: - constructor.properties - .where((e) => e.isSynthetic) - .toList(), - deepCloneableProperties: constructor.deepCloneableProperties, - genericsDefinition: data.genericsDefinitionTemplate, - genericsParameter: data.genericsParameterTemplate, - data: data, - parent: commonCopyWith, - ) - : null, + copyWith: data.options.annotation.copyWith ?? + constructor.parameters.allParameters.isNotEmpty + ? CopyWith( + parents: {}, + clonedClassName: constructor.redirectedName, + cloneableProperties: constructor.properties.toList(), + readableProperties: + constructor.properties.where((e) => e.isSynthetic).toList(), + deepCloneableProperties: constructor.deepCloneableProperties, + genericsDefinition: data.genericsDefinitionTemplate, + genericsParameter: data.genericsParameterTemplate, + data: data, + parent: commonCopyWith, + ) + : null, ); } } diff --git a/packages/freezed/lib/src/models.dart b/packages/freezed/lib/src/models.dart index cfc444ef..535037c9 100644 --- a/packages/freezed/lib/src/models.dart +++ b/packages/freezed/lib/src/models.dart @@ -114,7 +114,8 @@ class DeepCloneableProperty { nullable: parameter.type.isNullable, typeName: typeElement.name, genericParameters: GenericsParameterTemplate( - (parameter.type as InterfaceType).typeArguments + (parameter.type as InterfaceType) + .typeArguments .map((e) => e.getDisplayString()) .toList(), ), @@ -147,8 +148,7 @@ extension on FormalParameter { return switch (that) { DefaultFormalParameter() => that.parameter.typeAnnotation(), FieldFormalParameter() => that.type, - FunctionTypedFormalParameter() => - throw UnsupportedError( + FunctionTypedFormalParameter() => throw UnsupportedError( 'Parameters of format `T name()` are not supported. Use `T Function()` name.', ), SimpleFormalParameter() => that.type, @@ -275,8 +275,7 @@ When specifying fields in non-factory constructor then specifying factory constr className: declaration.name.lexeme, ); - final excludedProperties = - manualConstructor?.parameters.parameters + final excludedProperties = manualConstructor?.parameters.parameters .map((e) => e.declaredElement!.name) .toSet() ?? {}; @@ -294,11 +293,10 @@ When specifying fields in non-factory constructor then specifying factory constr ConstructorDetails( asserts: AssertAnnotation.parseAll(constructor).toList(), isSynthetic: unitsExcludingGeneratedFiles.any( - (e) => - !e.declarations - .whereType() - .map((e) => e.name.lexeme) - .contains(redirectedName), + (e) => !e.declarations + .whereType() + .map((e) => e.name.lexeme) + .contains(redirectedName), ), name: constructor.name?.lexeme ?? '', unionValue: constructor.declaredElement!.unionValue( @@ -308,41 +306,35 @@ When specifying fields in non-factory constructor then specifying factory constr fullName: constructor.fullName, escapedName: constructor.escapedName, properties: allProperties, - decorators: - constructor.metadata - .where((element) { - final elementSourceUri = - element.element?.declaration?.librarySource?.uri; - - final isFreezedAnnotation = - elementSourceUri != null && - elementSourceUri.scheme == 'package' && - elementSourceUri.pathSegments.isNotEmpty && - elementSourceUri.pathSegments.first == - 'freezed_annotation'; - - return !isFreezedAnnotation; - }) - .map((e) => e.toSource()) - .toList(), - withDecorators: - WithAnnotation.parseAll( - constructor.declaredElement!, - ).toSet().toList(), - implementsDecorators: - ImplementsAnnotation.parseAll( - constructor.declaredElement!, - ).toSet().toList(), + decorators: constructor.metadata + .where((element) { + final elementSourceUri = + element.element?.declaration?.librarySource?.uri; + + final isFreezedAnnotation = elementSourceUri != null && + elementSourceUri.scheme == 'package' && + elementSourceUri.pathSegments.isNotEmpty && + elementSourceUri.pathSegments.first == 'freezed_annotation'; + + return !isFreezedAnnotation; + }) + .map((e) => e.toSource()) + .toList(), + withDecorators: WithAnnotation.parseAll( + constructor.declaredElement!, + ).toSet().toList(), + implementsDecorators: ImplementsAnnotation.parseAll( + constructor.declaredElement!, + ).toSet().toList(), isDefault: isDefaultConstructor(constructor.declaredElement!), hasJsonSerializable: constructor.declaredElement!.hasJsonSerializable, isFallback: constructor.declaredElement!.isFallbackUnion( configs.annotation.fallbackUnion, ), - deepCloneableProperties: - DeepCloneableProperty.parseAll( - constructor.declaredElement!, - globalConfigs, - ).toList(), + deepCloneableProperties: DeepCloneableProperty.parseAll( + constructor.declaredElement!, + globalConfigs, + ).toList(), parameters: ParametersTemplate.fromParameterList( constructor.parameters.parameters, addImplicitFinal: configs.annotation.addImplicitFinal, @@ -506,8 +498,8 @@ class Class { required this.properties, required this.copyWithTarget, required ClassDeclaration node, - }) : _node = node, - assert(constructors.isNotEmpty); + }) : _node = node, + assert(constructors.isNotEmpty); final String name; final ClassConfig options; @@ -542,8 +534,7 @@ class Class { } } - final has$ClassMixin = - declaration.withClause?.mixinTypes.any( + final has$ClassMixin = declaration.withClause?.mixinTypes.any( (e) => e.isSuperMixin(declaration), ) ?? false; @@ -566,49 +557,44 @@ class Class { ); } - final properties = - PropertyList() - ..readableProperties.addAll( - _computeReadableProperties(declaration, constructors), - ) - ..cloneableProperties.addAll( - _computeCloneableProperties(declaration, constructors, configs), - ); + final properties = PropertyList() + ..readableProperties.addAll( + _computeReadableProperties(declaration, constructors), + ) + ..cloneableProperties.addAll( + _computeCloneableProperties(declaration, constructors, configs), + ); final copyWithTarget = constructors.isNotEmpty ? null : declaration.copyWithTarget; - final copyWithInvocation = - copyWithTarget == null - ? null - : CopyWithTarget( - name: copyWithTarget.name?.lexeme, - parameters: ParametersTemplate.fromParameterList( - // Only include parameters that are cloneable - copyWithTarget.parameters.parameters.where((e) { - return properties.cloneableProperties - .map((e) => e.name) - .contains(e.name!.lexeme); - }), - addImplicitFinal: configs.annotation.addImplicitFinal, - ), - ); + final copyWithInvocation = copyWithTarget == null + ? null + : CopyWithTarget( + name: copyWithTarget.name?.lexeme, + parameters: ParametersTemplate.fromParameterList( + // Only include parameters that are cloneable + copyWithTarget.parameters.parameters.where((e) { + return properties.cloneableProperties + .map((e) => e.name) + .contains(e.name!.lexeme); + }), + addImplicitFinal: configs.annotation.addImplicitFinal, + ), + ); - final superCall = - privateCtor == null - ? null - : ConstructorInvocation( - name: '_', - positional: - privateCtor.parameters.parameters - .where((e) => e.isPositional) - .map((e) => e.name!.lexeme) - .toList(), - named: - privateCtor.parameters.parameters - .where((e) => e.isNamed) - .map((e) => e.name!.lexeme) - .toList(), - ); + final superCall = privateCtor == null + ? null + : ConstructorInvocation( + name: '_', + positional: privateCtor.parameters.parameters + .where((e) => e.isPositional) + .map((e) => e.name!.lexeme) + .toList(), + named: privateCtor.parameters.parameters + .where((e) => e.isNamed) + .map((e) => e.name!.lexeme) + .toList(), + ); return Class( node: declaration, @@ -637,15 +623,13 @@ class Class { Library library, { required Freezed globalConfigs, }) { - final unitsExcludingGeneratedFiles = - units - .where( - (element) => - !element.declaredElement!.source.fullName.endsWith( - '.freezed.dart', - ), - ) - .toList(); + final unitsExcludingGeneratedFiles = units + .where( + (element) => !element.declaredElement!.source.fullName.endsWith( + '.freezed.dart', + ), + ) + .toList(); final classes = annotations.map((e) { final annotation = e.annotation; @@ -732,19 +716,15 @@ class Class { ClassDeclaration declaration, List constructorsNeedsGeneration, ) sync* { - final typesMap = - < - String, - List< + final typesMap = decorators, - })? - > - >{}; + })?>>{}; void setForName({ required String name, required TypeAnnotation? type, @@ -785,16 +765,14 @@ class Class { } for (final (index, freezedCtor) in constructorsNeedsGeneration.indexed) { - final ctor = - declaration.constructors - .where((e) => (e.name?.lexeme ?? '') == freezedCtor.name) - .first; + final ctor = declaration.constructors + .where((e) => (e.name?.lexeme ?? '') == freezedCtor.name) + .first; for (final parameter in ctor.parameters.parameters) { - final freezedParameter = - freezedCtor.parameters.allParameters - .where((e) => e.name == parameter.name?.lexeme) - .first; + final freezedParameter = freezedCtor.parameters.allParameters + .where((e) => e.name == parameter.name?.lexeme) + .first; setForName( name: parameter.name!.lexeme, @@ -846,10 +824,9 @@ class Class { final typeSources = fields.map((e) => e?.type?.toSource()).toSet(); if (typeSources.length == 1) { - type = - fields - .map((e) => e!.type?.type ?? typeProvider.dynamicType) - .first; + type = fields + .map((e) => e!.type?.type ?? typeProvider.dynamicType) + .first; // All constructors use the exact same type. No need to check lower-bounds, // and we can paste the type in the generated source directly. typeString = typeSources.single ?? type.toString(); @@ -926,18 +903,17 @@ class Class { // be present in the abstract class. if (matchingParameter == null) continue parameterLoop; - commonTypeBetweenAllUnionConstructors = library.typeSystem - .leastUpperBound( - commonTypeBetweenAllUnionConstructors, - matchingParameter.parameterElement!.type, - ); + commonTypeBetweenAllUnionConstructors = + library.typeSystem.leastUpperBound( + commonTypeBetweenAllUnionConstructors, + matchingParameter.parameterElement!.type, + ); } - final matchingParameters = - constructorsNeedsGeneration - .expand((element) => element.parameters.allParameters) - .where((element) => element.name == parameter.name) - .toList(); + final matchingParameters = constructorsNeedsGeneration + .expand((element) => element.parameters.allParameters) + .where((element) => element.name == parameter.name) + .toList(); final isFinal = matchingParameters.any( (element) => @@ -993,10 +969,9 @@ class Class { // first union case. // - num c is not allowed because num is not assignable int/double if (!didNonNullDowncast) { - final copyWithType = - didNullDowncast - ? nonNullableCommonType - : commonTypeBetweenAllUnionConstructors; + final copyWithType = didNullDowncast + ? nonNullableCommonType + : commonTypeBetweenAllUnionConstructors; result.cloneableProperties.add( Property( @@ -1055,9 +1030,8 @@ class Class { } String get escapedName { - var generics = genericsParameterTemplate.typeParameters - .map((e) => '\$$e') - .join(', '); + var generics = + genericsParameterTemplate.typeParameters.map((e) => '\$$e').join(', '); if (generics.isNotEmpty) { generics = '<$generics>'; } diff --git a/packages/freezed/lib/src/parse_generator.dart b/packages/freezed/lib/src/parse_generator.dart index 1520ac39..db96de05 100644 --- a/packages/freezed/lib/src/parse_generator.dart +++ b/packages/freezed/lib/src/parse_generator.dart @@ -19,12 +19,11 @@ abstract class ParserGenerator ) async { if (oldLibrary.classes.isEmpty) return ''; - final units = - await Stream.fromFutures( - oldLibrary.element.units.map( - (e) => buildStep.resolver.astNodeFor(e, resolve: true), - ), - ).cast().toList(); + final units = await Stream.fromFutures( + oldLibrary.element.units.map( + (e) => buildStep.resolver.astNodeFor(e, resolve: true), + ), + ).cast().toList(); final values = StringBuffer(); final datas = []; diff --git a/packages/freezed/lib/src/string.dart b/packages/freezed/lib/src/string.dart index 7b3b2216..e42002a9 100644 --- a/packages/freezed/lib/src/string.dart +++ b/packages/freezed/lib/src/string.dart @@ -14,12 +14,12 @@ extension StringX on String { } String _fixCase(String separator) => replaceAllMapped(_upperCase, (match) { - var lower = match.group(0)!.toLowerCase(); + var lower = match.group(0)!.toLowerCase(); - if (match.start > 0) { - lower = '$separator$lower'; - } + if (match.start > 0) { + lower = '$separator$lower'; + } - return lower; - }); + return lower; + }); } diff --git a/packages/freezed/lib/src/templates/abstract_template.dart b/packages/freezed/lib/src/templates/abstract_template.dart index 60e4e683..d112b9dd 100644 --- a/packages/freezed/lib/src/templates/abstract_template.dart +++ b/packages/freezed/lib/src/templates/abstract_template.dart @@ -20,20 +20,18 @@ class Abstract { @override String toString() { - final needsAbstractGetters = - data.options.toJson || + final needsAbstractGetters = data.options.toJson || copyWith != null || data.options.asString || data.options.equal; - final abstractProperties = - commonProperties - // If toJson/==/toString/copyWith are enabled, always generate a `T get field`, - // to enable those methods to use all properties. - // Otherwise only do so for fields generated by factory constructors. - .where((e) => needsAbstractGetters || e.isSynthetic) - .expand((e) => [e.abstractGetter, if (!e.isFinal) e.abstractSetter]) - .join(); + final abstractProperties = commonProperties + // If toJson/==/toString/copyWith are enabled, always generate a `T get field`, + // to enable those methods to use all properties. + // Otherwise only do so for fields generated by factory constructors. + .where((e) => needsAbstractGetters || e.isSynthetic) + .expand((e) => [e.abstractGetter, if (!e.isFinal) e.abstractSetter]) + .join(); var interfaces = [if (globalData.hasDiagnostics) 'DiagnosticableTreeMixin'].join(); diff --git a/packages/freezed/lib/src/templates/concrete_template.dart b/packages/freezed/lib/src/templates/concrete_template.dart index 4f6fe146..96ea6f9e 100644 --- a/packages/freezed/lib/src/templates/concrete_template.dart +++ b/packages/freezed/lib/src/templates/concrete_template.dart @@ -34,10 +34,10 @@ class Concrete { late final bool _hasUnionKeyProperty = (data.options.toJson || data.options.fromJson) && - data.constructors.length > 1 && - constructor.properties.every( - (e) => e.name != data.options.annotation.unionKey, - ); + data.constructors.length > 1 && + constructor.properties.every( + (e) => e.name != data.options.annotation.unionKey, + ); @override String toString() { @@ -100,10 +100,9 @@ ${copyWith?.concreteImpl(constructor.parameters) ?? ''} ); } - final correspondingProperty = - constructor.properties - .where((element) => element.name == p.name) - .first; + final correspondingProperty = constructor.properties + .where((element) => element.name == p.name) + .first; if (correspondingProperty.isSynthetic) { return ( LocalParameter.fromParameter(p), @@ -230,59 +229,55 @@ ${copyWith?.concreteImpl(constructor.parameters) ?? ''} } String get _properties { - final classProperties = constructor.properties - .where((e) => e.isSynthetic) - .expand((p) { - final annotatedProperty = p.copyWith( - decorators: [ - if (commonProperties.any((element) => element.name == p.name)) - '@override', - if (p.defaultValueSource != null && !p.hasJsonKey) '@JsonKey()', - ...p.decorators, - ], - ); + final classProperties = + constructor.properties.where((e) => e.isSynthetic).expand((p) { + final annotatedProperty = p.copyWith( + decorators: [ + if (commonProperties.any((element) => element.name == p.name)) + '@override', + if (p.defaultValueSource != null && !p.hasJsonKey) '@JsonKey()', + ...p.decorators, + ], + ); + + if (data.options.asUnmodifiableCollections) { + String? viewType; + + if (p.isDartList) { + viewType = 'EqualUnmodifiableListView'; + } else if (p.isDartMap) { + viewType = 'EqualUnmodifiableMapView'; + } else if (p.isDartSet) { + viewType = 'EqualUnmodifiableSetView'; + } + + if (viewType != null) { + // If the collection is already unmodifiable, we don't want to wrap + // it in an unmodifiable view again. + final isAlreadyUnmodifiableCheck = + 'if (_${p.name} is $viewType) return _${p.name};'; - if (data.options.asUnmodifiableCollections) { - String? viewType; - - if (p.isDartList) { - viewType = 'EqualUnmodifiableListView'; - } else if (p.isDartMap) { - viewType = 'EqualUnmodifiableMapView'; - } else if (p.isDartSet) { - viewType = 'EqualUnmodifiableSetView'; - } - - if (viewType != null) { - // If the collection is already unmodifiable, we don't want to wrap - // it in an unmodifiable view again. - final isAlreadyUnmodifiableCheck = - 'if (_${p.name} is $viewType) return _${p.name};'; - - return [ - p.copyWith(name: '_${p.name}', decorators: const []), - if (p.isNullable) - annotatedProperty.asGetter(''' { + return [ + p.copyWith(name: '_${p.name}', decorators: const []), + if (p.isNullable) annotatedProperty.asGetter(''' { final value = _${p.name}; if (value == null) return null; $isAlreadyUnmodifiableCheck // ignore: implicit_dynamic_type return $viewType(value); } -''') - else - annotatedProperty.asGetter(''' { +''') else annotatedProperty.asGetter(''' { $isAlreadyUnmodifiableCheck // ignore: implicit_dynamic_type return $viewType(_${p.name}); } '''), - ]; - } - } + ]; + } + } - return [annotatedProperty]; - }); + return [annotatedProperty]; + }); if (_hasUnionKeyProperty) { return ''' @@ -301,14 +296,14 @@ final String \$type; } String get _fromJsonArgs => fromJsonArguments( - data.genericsParameterTemplate, - data.options.genericArgumentFactories, - ); + data.genericsParameterTemplate, + data.options.genericArgumentFactories, + ); String get _fromJsonParams => fromJsonParameters( - data.genericsParameterTemplate, - data.options.genericArgumentFactories, - ); + data.genericsParameterTemplate, + data.options.genericArgumentFactories, + ); String get _concreteFromJsonConstructor { if (!data.options.fromJson) return ''; @@ -382,11 +377,10 @@ String debugFillProperties( }) { if (!globalData.hasDiagnostics || !data.options.asString) return ''; - final diagnostics = - [ - for (final e in properties) - "..add(DiagnosticsProperty('${e.name}', ${e.name}))", - ].join(); + final diagnostics = [ + for (final e in properties) + "..add(DiagnosticsProperty('${e.name}', ${e.name}))", + ].join(); return ''' @override @@ -406,10 +400,9 @@ String toStringMethod( }) { if (!data.options.asString) return ''; - final parameters = - globalData.hasDiagnostics - ? '{ DiagnosticLevel minLevel = DiagnosticLevel.info }' - : ''; + final parameters = globalData.hasDiagnostics + ? '{ DiagnosticLevel minLevel = DiagnosticLevel.info }' + : ''; final propertiesDisplayString = [ for (final p in properties) @@ -470,10 +463,9 @@ String hashCodeMethod( }) { if (!data.options.equal) return ''; - final jsonKey = - data.options.fromJson || data.options.toJson - ? '@JsonKey(includeFromJson: false, includeToJson: false)' - : ''; + final jsonKey = data.options.fromJson || data.options.toJson + ? '@JsonKey(includeFromJson: false, includeToJson: false)' + : ''; final hashedProperties = [ 'runtimeType', @@ -523,8 +515,7 @@ extension DefaultValue on ParameterElement { final source = meta.toSource(); final res = source.substring('@Default('.length, source.length - 1); - var needsConstModifier = - !declaration.type.isDartCoreString && + var needsConstModifier = !declaration.type.isDartCoreString && !res.trimLeft().startsWith('const') && (res.contains('(') || res.contains('[') || res.contains('{')); diff --git a/packages/freezed/lib/src/templates/copy_with.dart b/packages/freezed/lib/src/templates/copy_with.dart index 1b7f71e4..46655dc9 100644 --- a/packages/freezed/lib/src/templates/copy_with.dart +++ b/packages/freezed/lib/src/templates/copy_with.dart @@ -119,25 +119,24 @@ $_abstractClassName${genericsParameter.append('$clonedClassName$genericsParamete body = _copyWithMethodBody( parametersTemplate: ParametersTemplate( const [], - namedParameters: - cloneableProperties.map((e) { - return Parameter( - decorators: e.decorators, - name: e.name, - isNullable: e.isNullable, - isFinal: false, - isDartList: false, - isDartMap: false, - isDartSet: false, - showDefaultValue: false, - isRequired: false, - defaultValueSource: '', - type: e.type, - doc: e.doc, - isPossiblyDartCollection: e.isPossiblyDartCollection, - parameterElement: null, - ); - }).toList(), + namedParameters: cloneableProperties.map((e) { + return Parameter( + decorators: e.decorators, + name: e.name, + isNullable: e.isNullable, + isFinal: false, + isDartList: false, + isDartMap: false, + isDartSet: false, + showDefaultValue: false, + isRequired: false, + defaultValueSource: '', + type: e.type, + doc: e.doc, + isPossiblyDartCollection: e.isPossiblyDartCollection, + parameterElement: null, + ); + }).toList(), ), returnType: '_self.copyWith', ); @@ -209,10 +208,9 @@ ${_deepCopyMethods(isConcrete: true).join()} required List properties, required String methodName, }) { - final parameters = - properties.map((p) { - return 'Object? ${p.name} = ${_defaultValue(isNullable: p.isNullable)},'; - }).join(); + final parameters = properties.map((p) { + return 'Object? ${p.name} = ${_defaultValue(isNullable: p.isNullable)},'; + }).join(); return '\$Res $methodName({$parameters})'; } @@ -221,11 +219,9 @@ ${_deepCopyMethods(isConcrete: true).join()} required String methodName, required List properties, }) { - final parameters = properties - .map((p) { - return '${p.decorators.join()} ${p.type} ${p.name}'; - }) - .join(','); + final parameters = properties.map((p) { + return '${p.decorators.join()} ${p.type} ${p.name}'; + }).join(','); return _maybeOverride(''' @useResult @@ -259,7 +255,8 @@ ${_copyWithDocs(data.name)} String _ignoreLints( String s, [ List lints = const ['cast_nullable_to_non_nullable'], - ]) => ''' + ]) => + ''' // ignore: ${lints.join(', ')} $s'''; @@ -321,19 +318,18 @@ $s'''; return '$condition ? $thisProperty : ${parameterAssignmentFor(p)},'; } - final constructorParameters = - StringBuffer() - ..writeAll( - [ - ...parametersTemplate.requiredPositionalParameters, - ...parametersTemplate.optionalPositionalParameters, - ].map(parameterToValue), - ) - ..writeAll( - parametersTemplate.namedParameters.map( - (p) => '${p.name}: ${parameterToValue(p)}', - ), - ); + final constructorParameters = StringBuffer() + ..writeAll( + [ + ...parametersTemplate.requiredPositionalParameters, + ...parametersTemplate.optionalPositionalParameters, + ].map(parameterToValue), + ) + ..writeAll( + parametersTemplate.namedParameters.map( + (p) => '${p.name}: ${parameterToValue(p)}', + ), + ); return '''{ return _then($returnType( @@ -346,21 +342,19 @@ $constructorParameters Iterable _deepCopyMethods({required bool isConcrete}) sync* { for (final cloneableProperty in deepCloneableProperties) { - final earlyReturn = - cloneableProperty.nullable - ? ''' + final earlyReturn = cloneableProperty.nullable + ? ''' if (_self.${cloneableProperty.name} == null) { return null; } ''' - : ''; + : ''; final nullabilitySuffix = cloneableProperty.nullable ? '!' : ''; - final returnType = - cloneableProperty.nullable - ? '${_clonerInterfaceFor(cloneableProperty)}?' - : '${_clonerInterfaceFor(cloneableProperty)}'; + final returnType = cloneableProperty.nullable + ? '${_clonerInterfaceFor(cloneableProperty)}?' + : '${_clonerInterfaceFor(cloneableProperty)}'; yield ''' ${_copyWithDocs(data.name)} diff --git a/packages/freezed/lib/src/templates/from_json_template.dart b/packages/freezed/lib/src/templates/from_json_template.dart index a639ba5a..8c66d5b3 100644 --- a/packages/freezed/lib/src/templates/from_json_template.dart +++ b/packages/freezed/lib/src/templates/from_json_template.dart @@ -16,10 +16,9 @@ class FromJson { // cannot add annotations on user's behalf. if (clazz.constructors.isEmpty) return ''; - final conflictCtor = - clazz.constructors - .where((c) => c.redirectedName.public == clazz.name.public) - .firstOrNull; + final conflictCtor = clazz.constructors + .where((c) => c.redirectedName.public == clazz.name.public) + .firstOrNull; if (conflictCtor != null) { if (clazz.constructors.length == 1) return ''; @@ -40,18 +39,18 @@ Rename one or the other, such that they don't conflict. } else { final cases = clazz.constructors.where((element) => !element.isFallback).map(( - constructor, - ) { - final caseName = constructor.unionValue; - final concreteName = constructor.redirectedName; + constructor, + ) { + final caseName = constructor.unionValue; + final concreteName = constructor.redirectedName; - return ''' + return ''' case '$caseName': return $concreteName${clazz.genericsParameterTemplate}.fromJson( json${fromJsonArguments(clazz.genericsParameterTemplate, clazz.options.genericArgumentFactories)} ); '''; - }).join(); + }).join(); // TODO(rrousselGit): update logic once https://github.com/rrousselGit/freezed/pull/370 lands var defaultCase = ''' diff --git a/packages/freezed/lib/src/templates/parameter_template.dart b/packages/freezed/lib/src/templates/parameter_template.dart index 3a52bef4..f8b2ce59 100644 --- a/packages/freezed/lib/src/templates/parameter_template.dart +++ b/packages/freezed/lib/src/templates/parameter_template.dart @@ -92,11 +92,10 @@ class ParametersTemplate { return ParametersTemplate( parameters.where((p) => p.isRequiredPositional).map(asParameter).toList(), - optionalPositionalParameters: - parameters - .where((p) => p.isOptionalPositional) - .map(asParameter) - .toList(), + optionalPositionalParameters: parameters + .where((p) => p.isOptionalPositional) + .map(asParameter) + .toList(), namedParameters: parameters.where((p) => p.isNamed).map(asParameter).toList(), ); @@ -144,8 +143,7 @@ class ParametersTemplate { required bool isNamed, required bool isRequired, required int? index, - }) - cb, + }) cb, ) { final parameters = [ ...requiredPositionalParameters.mapIndexed( @@ -164,11 +162,10 @@ class ParametersTemplate { .where((e) => e.isNamed == false && e.isRequired == true) .map((e) => e.$1) .toList(), - optionalPositionalParameters: - parameters - .where((e) => e.isNamed == false && e.isRequired == false) - .map((e) => e.$1) - .toList(), + optionalPositionalParameters: parameters + .where((e) => e.isNamed == false && e.isRequired == false) + .map((e) => e.$1) + .toList(), namedParameters: parameters.where((e) => e.isNamed == true).map((e) => e.$1).toList(), ); @@ -226,22 +223,22 @@ class Parameter { }); Parameter.fromParameter(Parameter p) - : this( - name: p.name, - type: p.type, - isNullable: p.isNullable, - defaultValueSource: p.defaultValueSource, - isFinal: p.isFinal, - isRequired: p.isRequired, - isDartList: p.isDartList, - isDartMap: p.isDartMap, - isDartSet: p.isDartSet, - decorators: p.decorators, - showDefaultValue: p.showDefaultValue, - doc: p.doc, - isPossiblyDartCollection: p.isPossiblyDartCollection, - parameterElement: p.parameterElement, - ); + : this( + name: p.name, + type: p.type, + isNullable: p.isNullable, + defaultValueSource: p.defaultValueSource, + isFinal: p.isFinal, + isRequired: p.isRequired, + isDartList: p.isDartList, + isDartMap: p.isDartMap, + isDartSet: p.isDartSet, + decorators: p.decorators, + showDefaultValue: p.showDefaultValue, + doc: p.doc, + isPossiblyDartCollection: p.isPossiblyDartCollection, + parameterElement: p.parameterElement, + ); final String? type; final String name; @@ -273,23 +270,24 @@ class Parameter { bool? isDartMap, bool? isDartSet, bool? isFinal, - }) => Parameter( - type: type ?? this.type, - name: name ?? this.name, - isNullable: isNullable ?? this.isNullable, - defaultValueSource: defaultValueSource ?? this.defaultValueSource, - isRequired: isRequired ?? this.isRequired, - decorators: decorators ?? this.decorators, - showDefaultValue: showDefaultValue ?? this.showDefaultValue, - doc: doc ?? this.doc, - isDartMap: isDartMap ?? this.isDartMap, - isDartSet: isDartSet ?? this.isDartSet, - isDartList: isDartList ?? this.isDartList, - isFinal: isFinal ?? this.isFinal, - isPossiblyDartCollection: - isPossiblyDartCollection ?? this.isPossiblyDartCollection, - parameterElement: parameterElement, - ); + }) => + Parameter( + type: type ?? this.type, + name: name ?? this.name, + isNullable: isNullable ?? this.isNullable, + defaultValueSource: defaultValueSource ?? this.defaultValueSource, + isRequired: isRequired ?? this.isRequired, + decorators: decorators ?? this.decorators, + showDefaultValue: showDefaultValue ?? this.showDefaultValue, + doc: doc ?? this.doc, + isDartMap: isDartMap ?? this.isDartMap, + isDartSet: isDartSet ?? this.isDartSet, + isDartList: isDartList ?? this.isDartList, + isFinal: isFinal ?? this.isFinal, + isPossiblyDartCollection: + isPossiblyDartCollection ?? this.isPossiblyDartCollection, + parameterElement: parameterElement, + ); @override String toString() { @@ -328,21 +326,21 @@ class SuperParameter extends Parameter { }) : super(showDefaultValue: true); SuperParameter.fromParameter(Parameter p) - : this( - name: p.name, - type: p.type, - isNullable: p.isNullable, - defaultValueSource: p.defaultValueSource, - isFinal: p.isFinal, - isRequired: p.isRequired, - isDartList: p.isDartList, - isDartMap: p.isDartMap, - isDartSet: p.isDartSet, - decorators: p.decorators, - doc: p.doc, - isPossiblyDartCollection: p.isPossiblyDartCollection, - parameterElement: p.parameterElement, - ); + : this( + name: p.name, + type: p.type, + isNullable: p.isNullable, + defaultValueSource: p.defaultValueSource, + isFinal: p.isFinal, + isRequired: p.isRequired, + isDartList: p.isDartList, + isDartMap: p.isDartMap, + isDartSet: p.isDartSet, + decorators: p.decorators, + doc: p.doc, + isPossiblyDartCollection: p.isPossiblyDartCollection, + parameterElement: p.parameterElement, + ); @override String toString() { @@ -378,21 +376,21 @@ class LocalParameter extends Parameter { }) : super(showDefaultValue: true); LocalParameter.fromParameter(Parameter p) - : this( - name: p.name, - type: p.type, - isNullable: p.isNullable, - defaultValueSource: p.defaultValueSource, - isFinal: p.isFinal, - isRequired: p.isRequired, - isDartList: p.isDartList, - isDartMap: p.isDartMap, - isDartSet: p.isDartSet, - decorators: p.decorators, - doc: p.doc, - isPossiblyDartCollection: p.isPossiblyDartCollection, - parameterElement: p.parameterElement, - ); + : this( + name: p.name, + type: p.type, + isNullable: p.isNullable, + defaultValueSource: p.defaultValueSource, + isFinal: p.isFinal, + isRequired: p.isRequired, + isDartList: p.isDartList, + isDartMap: p.isDartMap, + isDartSet: p.isDartSet, + decorators: p.decorators, + doc: p.doc, + isPossiblyDartCollection: p.isPossiblyDartCollection, + parameterElement: p.parameterElement, + ); @override String toString() { diff --git a/packages/freezed/lib/src/templates/properties.dart b/packages/freezed/lib/src/templates/properties.dart index c5c5cb45..de6aa547 100644 --- a/packages/freezed/lib/src/templates/properties.dart +++ b/packages/freezed/lib/src/templates/properties.dart @@ -27,21 +27,21 @@ class Property { }) : type = type ?? 'dynamic'; Property.fromParameter(Parameter p, {required bool isSynthetic}) - : this( - decorators: p.decorators, - name: p.name, - isFinal: p.isFinal, - doc: p.doc, - type: p.type, - defaultValueSource: p.defaultValueSource, - isSynthetic: isSynthetic, - isNullable: p.isNullable, - isDartList: p.isDartList, - isDartMap: p.isDartMap, - isDartSet: p.isDartSet, - isPossiblyDartCollection: p.isPossiblyDartCollection, - hasJsonKey: false, - ); + : this( + decorators: p.decorators, + name: p.name, + isFinal: p.isFinal, + doc: p.doc, + type: p.type, + defaultValueSource: p.defaultValueSource, + isSynthetic: isSynthetic, + isNullable: p.isNullable, + isDartList: p.isDartList, + isDartMap: p.isDartMap, + isDartSet: p.isDartSet, + isPossiblyDartCollection: p.isPossiblyDartCollection, + hasJsonKey: false, + ); static Property fromFormalParameter( FormalParameter parameter, { @@ -97,28 +97,28 @@ class Property { } Getter get abstractGetter => Getter( - name: name, - type: type, - decorators: decorators, - doc: doc, - body: ';', - ); + name: name, + type: type, + decorators: decorators, + doc: doc, + body: ';', + ); Getter asGetter(String body) => Getter( - name: name, - type: type, - decorators: decorators, - doc: doc, - body: body, - ); + name: name, + type: type, + decorators: decorators, + doc: doc, + body: body, + ); Setter get abstractSetter => Setter( - name: name, - type: type, - decorators: decorators, - doc: doc, - body: ';', - ); + name: name, + type: type, + decorators: decorators, + doc: doc, + body: ';', + ); Property copyWith({ String? type, diff --git a/packages/freezed/lib/src/tools/recursive_import_locator.dart b/packages/freezed/lib/src/tools/recursive_import_locator.dart index 8eb0c801..6e4b78d2 100644 --- a/packages/freezed/lib/src/tools/recursive_import_locator.dart +++ b/packages/freezed/lib/src/tools/recursive_import_locator.dart @@ -30,16 +30,15 @@ extension FindAllAvailableTopLevelElements on LibraryElement { }) sync* { yield* topLevelElements; - final librariesToCheck = - checkExports - ? units - .expand((e) => e.libraryExports) - .map(_LibraryDirectives.fromExport) - .nonNulls - : units - .expand((e) => e.libraryImports) - .map(_LibraryDirectives.fromImport) - .nonNulls; + final librariesToCheck = checkExports + ? units + .expand((e) => e.libraryExports) + .map(_LibraryDirectives.fromExport) + .nonNulls + : units + .expand((e) => e.libraryImports) + .map(_LibraryDirectives.fromImport) + .nonNulls; for (final directive in librariesToCheck) { if (!visitedLibraryPaths.add(directive.key)) { @@ -48,17 +47,17 @@ extension FindAllAvailableTopLevelElements on LibraryElement { yield* directive.library ._findAllAvailableTopLevelElements( - visitedLibraryPaths, - checkExports: true, - key: directive.key, - ) + visitedLibraryPaths, + checkExports: true, + key: directive.key, + ) .where((element) { - return (directive.showStatements.isEmpty && - directive.hideStatements.isEmpty) || - (directive.hideStatements.isNotEmpty && - !directive.hideStatements.contains(element.name)) || - directive.showStatements.contains(element.name); - }); + return (directive.showStatements.isEmpty && + directive.hideStatements.isEmpty) || + (directive.hideStatements.isNotEmpty && + !directive.hideStatements.contains(element.name)) || + directive.showStatements.contains(element.name); + }); } } } @@ -74,17 +73,15 @@ class _LibraryDirectives { final library = export.exportedLibrary; if (library == null) return null; - final hideStatements = - export.combinators - .whereType() - .expand((e) => e.hiddenNames) - .toSet(); + final hideStatements = export.combinators + .whereType() + .expand((e) => e.hiddenNames) + .toSet(); - final showStatements = - export.combinators - .whereType() - .expand((e) => e.shownNames) - .toSet(); + final showStatements = export.combinators + .whereType() + .expand((e) => e.shownNames) + .toSet(); return _LibraryDirectives( hideStatements: hideStatements, @@ -97,17 +94,15 @@ class _LibraryDirectives { final library = export.importedLibrary; if (library == null) return null; - final hideStatements = - export.combinators - .whereType() - .expand((e) => e.hiddenNames) - .toSet(); + final hideStatements = export.combinators + .whereType() + .expand((e) => e.hiddenNames) + .toSet(); - final showStatements = - export.combinators - .whereType() - .expand((e) => e.shownNames) - .toSet(); + final showStatements = export.combinators + .whereType() + .expand((e) => e.shownNames) + .toSet(); return _LibraryDirectives( hideStatements: hideStatements, @@ -166,10 +161,10 @@ class _LibraryKey { @override int get hashCode => Object.hash( - librarySource, - const SetEquality().hash(hideStatements), - const SetEquality().hash(showStatements), - ); + librarySource, + const SetEquality().hash(hideStatements), + const SetEquality().hash(showStatements), + ); @override String toString() { diff --git a/packages/freezed/lib/src/tools/type.dart b/packages/freezed/lib/src/tools/type.dart index 56e915a2..ee50e2c3 100644 --- a/packages/freezed/lib/src/tools/type.dart +++ b/packages/freezed/lib/src/tools/type.dart @@ -41,12 +41,12 @@ String resolveFullTypeStringFrom(LibraryElement originLibrary, DartType type) { final owner = originLibrary.units .expand((e) => e.libraryImportPrefixes) .firstWhereOrNull((e) { - return e.imports.any((l) { - return l.importedLibrary!.anyTransitiveExport((library) { - return library.id == _getElementForType(type)?.library?.id; - }); - }); + return e.imports.any((l) { + return l.importedLibrary!.anyTransitiveExport((library) { + return library.id == _getElementForType(type)?.library?.id; }); + }); + }); String? displayType = type.getDisplayString(); diff --git a/packages/freezed/pubspec.yaml b/packages/freezed/pubspec.yaml index 69eaced3..3cf986d6 100644 --- a/packages/freezed/pubspec.yaml +++ b/packages/freezed/pubspec.yaml @@ -7,10 +7,10 @@ repository: https://github.com/rrousselGit/freezed issue_tracker: https://github.com/rrousselGit/freezed/issues environment: - sdk: ">=3.7.0 <4.0.0" + sdk: ">=3.6.0 <4.0.0" dependencies: - analyzer: ">=7.0.0 <8.0.0" + analyzer: ">=6.9.0 <8.0.0" build: ^2.3.1 build_config: ^1.1.0 collection: ^1.15.0 diff --git a/packages/freezed/test/bidirectional_test.dart b/packages/freezed/test/bidirectional_test.dart index 2cfb679f..5c486511 100644 --- a/packages/freezed/test/bidirectional_test.dart +++ b/packages/freezed/test/bidirectional_test.dart @@ -13,11 +13,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/bidirectional.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/bidirectional.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); diff --git a/packages/freezed/test/common.dart b/packages/freezed/test/common.dart index ec63bb9f..69825be9 100644 --- a/packages/freezed/test/common.dart +++ b/packages/freezed/test/common.dart @@ -15,13 +15,11 @@ $src ''', }, (r) => r.findLibraryByName('main')); - final errorResult = - await main!.session.getErrors('/freezed/test/integration/main.dart') - as ErrorsResult; - final criticalErrors = - errorResult.errors - .where((element) => element.severity == Severity.error) - .toList(); + final errorResult = await main!.session + .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; + final criticalErrors = errorResult.errors + .where((element) => element.severity == Severity.error) + .toList(); if (criticalErrors.isNotEmpty) { throw CompileError(criticalErrors); diff --git a/packages/freezed/test/common_types_test.dart b/packages/freezed/test/common_types_test.dart index a4881638..29c10446 100644 --- a/packages/freezed/test/common_types_test.dart +++ b/packages/freezed/test/common_types_test.dart @@ -18,11 +18,9 @@ Future main() async { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/common_types.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/common_types.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); diff --git a/packages/freezed/test/decorator_test.dart b/packages/freezed/test/decorator_test.dart index 52461a13..78919e6d 100644 --- a/packages/freezed/test/decorator_test.dart +++ b/packages/freezed/test/decorator_test.dart @@ -12,15 +12,12 @@ void main() { ), ); - var errorResult = - await main.session.getErrors( - '/freezed/test/integration/decorator.freezed.dart', - ) - as ErrorsResult; + var errorResult = await main.session.getErrors( + '/freezed/test/integration/decorator.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); - errorResult = - await main.session.getErrors('/freezed/test/integration/decorator.dart') - as ErrorsResult; + errorResult = await main.session + .getErrors('/freezed/test/integration/decorator.dart') as ErrorsResult; }); test( @@ -83,9 +80,8 @@ void main() { ), ); - var errorResult = - await main.session.getErrors('/freezed/test/integration/main.dart') - as ErrorsResult; + var errorResult = await main.session + .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; expect( errorResult.errors.map((e) => e.errorCode.name), anyOf([ diff --git a/packages/freezed/test/deep_copy_test.dart b/packages/freezed/test/deep_copy_test.dart index 0f3d31f9..7a724621 100644 --- a/packages/freezed/test/deep_copy_test.dart +++ b/packages/freezed/test/deep_copy_test.dart @@ -24,11 +24,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/deep_copy.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/deep_copy.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); @@ -41,11 +39,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/deep_copy2.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/deep_copy2.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); @@ -726,9 +722,8 @@ void main() { ), ); - final errorResult = - await main.session.getErrors('/freezed/test/integration/main.dart') - as ErrorsResult; + final errorResult = await main.session + .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; expect(errorResult.errors.map((e) => e.errorCode.name), [ 'UNUSED_RESULT', diff --git a/packages/freezed/test/generic_test.dart b/packages/freezed/test/generic_test.dart index b50c301d..5b7f24f5 100644 --- a/packages/freezed/test/generic_test.dart +++ b/packages/freezed/test/generic_test.dart @@ -45,11 +45,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/generic.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/generic.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); diff --git a/packages/freezed/test/generics_refs_test.dart b/packages/freezed/test/generics_refs_test.dart index 5b3338aa..f50ce62d 100644 --- a/packages/freezed/test/generics_refs_test.dart +++ b/packages/freezed/test/generics_refs_test.dart @@ -14,11 +14,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/generics_refs.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/generics_refs.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); diff --git a/packages/freezed/test/integration/json.dart b/packages/freezed/test/integration/json.dart index 0b6e57cc..94ae6709 100644 --- a/packages/freezed/test/integration/json.dart +++ b/packages/freezed/test/integration/json.dart @@ -344,7 +344,8 @@ abstract class UnrecognizedKeysCustomUnionValue factory UnrecognizedKeysCustomUnionValue.fromJson( Map json, - ) => _$UnrecognizedKeysCustomUnionValueFromJson(json); + ) => + _$UnrecognizedKeysCustomUnionValueFromJson(json); } @Freezed(fallbackUnion: 'fallback') @@ -379,7 +380,8 @@ abstract class UnrecognizedKeysUnionFallbackWithDefault factory UnrecognizedKeysUnionFallbackWithDefault.fromJson( Map json, - ) => _$UnrecognizedKeysUnionFallbackWithDefaultFromJson(json); + ) => + _$UnrecognizedKeysUnionFallbackWithDefaultFromJson(json); } @Freezed(unionValueCase: FreezedUnionCase.pascal) @@ -394,7 +396,8 @@ abstract class UnrecognizedKeysUnionValueCasePascal factory UnrecognizedKeysUnionValueCasePascal.fromJson( Map json, - ) => _$UnrecognizedKeysUnionValueCasePascalFromJson(json); + ) => + _$UnrecognizedKeysUnionValueCasePascalFromJson(json); } @Freezed(unionValueCase: FreezedUnionCase.kebab) @@ -409,7 +412,8 @@ abstract class UnrecognizedKeysUnionValueCaseKebab factory UnrecognizedKeysUnionValueCaseKebab.fromJson( Map json, - ) => _$UnrecognizedKeysUnionValueCaseKebabFromJson(json); + ) => + _$UnrecognizedKeysUnionValueCaseKebabFromJson(json); } @Freezed(unionValueCase: FreezedUnionCase.snake) @@ -424,7 +428,8 @@ abstract class UnrecognizedKeysUnionValueCaseSnake factory UnrecognizedKeysUnionValueCaseSnake.fromJson( Map json, - ) => _$UnrecognizedKeysUnionValueCaseSnakeFromJson(json); + ) => + _$UnrecognizedKeysUnionValueCaseSnakeFromJson(json); } @Freezed(unionValueCase: FreezedUnionCase.screamingSnake) @@ -440,7 +445,8 @@ abstract class UnrecognizedKeysUnionValueCaseScreamingSnake factory UnrecognizedKeysUnionValueCaseScreamingSnake.fromJson( Map json, - ) => _$UnrecognizedKeysUnionValueCaseScreamingSnakeFromJson(json); + ) => + _$UnrecognizedKeysUnionValueCaseScreamingSnakeFromJson(json); } @freezed @@ -568,7 +574,8 @@ abstract class GenericWithArgumentFactories factory GenericWithArgumentFactories.fromJson( Map json, T Function(Object? json) fromJsonT, - ) => _$GenericWithArgumentFactoriesFromJson(json, fromJsonT); + ) => + _$GenericWithArgumentFactoriesFromJson(json, fromJsonT); } @Freezed(genericArgumentFactories: true) @@ -581,7 +588,8 @@ abstract class GenericTupleWithArgumentFactories Map json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, - ) => _$GenericTupleWithArgumentFactoriesFromJson(json, fromJsonT, fromJsonS); + ) => + _$GenericTupleWithArgumentFactoriesFromJson(json, fromJsonT, fromJsonS); } @Freezed(genericArgumentFactories: true) @@ -614,9 +622,10 @@ abstract class GenericMultiCtorWithArgumentFactories Map json, T Function(Object? json) fromJsonT, S Function(Object? json) fromJsonS, - ) => _$GenericMultiCtorWithArgumentFactoriesFromJson( - json, - fromJsonT, - fromJsonS, - ); + ) => + _$GenericMultiCtorWithArgumentFactoriesFromJson( + json, + fromJsonT, + fromJsonS, + ); } diff --git a/packages/freezed/test/integration/multiple_constructors.dart b/packages/freezed/test/integration/multiple_constructors.dart index f702df37..f0c6cf01 100644 --- a/packages/freezed/test/integration/multiple_constructors.dart +++ b/packages/freezed/test/integration/multiple_constructors.dart @@ -131,7 +131,6 @@ abstract class Complex with _$Complex { const factory Complex.first( /// World String a, { - /// B bool? b, double? d, @@ -139,7 +138,6 @@ abstract class Complex with _$Complex { const factory Complex.second( String a, [ - /// C int? c, double? d, diff --git a/packages/freezed/test/integration/single_class_constructor.dart b/packages/freezed/test/integration/single_class_constructor.dart index 247f0c10..0a4f2da9 100644 --- a/packages/freezed/test/integration/single_class_constructor.dart +++ b/packages/freezed/test/integration/single_class_constructor.dart @@ -278,7 +278,6 @@ abstract class Doc with _$Doc { /// line /// positional int positional, { - /// Single line named int? named, @@ -424,13 +423,12 @@ abstract class ComplexLate with _$ComplexLate { factory ComplexLate(List values) = _ComplexLate; @override - late final List odd = - values.where((value) { - if (value.isOdd) - return true; - else - return false; - }).toList(); + late final List odd = values.where((value) { + if (value.isOdd) + return true; + else + return false; + }).toList(); } @freezed @@ -508,8 +506,8 @@ abstract class NullDefault with _$NullDefault { @freezed abstract class ExplicitConstDefault with _$ExplicitConstDefault { factory ExplicitConstDefault( - //ignore: unnecessary_const - [@Default(const []) List value]) = _ExplicitConstDefault; + //ignore: unnecessary_const + [@Default(const []) List value]) = _ExplicitConstDefault; } @freezed diff --git a/packages/freezed/test/json_test.dart b/packages/freezed/test/json_test.dart index 6008707c..ef216c31 100644 --- a/packages/freezed/test/json_test.dart +++ b/packages/freezed/test/json_test.dart @@ -774,11 +774,9 @@ void main() { }); test('has no issue', () async { - var errorResult = - await jsonFile.session.getErrors( - '/freezed/test/integration/json.freezed.dart', - ) - as ErrorsResult; + var errorResult = await jsonFile.session.getErrors( + '/freezed/test/integration/json.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }, skip: true); diff --git a/packages/freezed/test/multiple_constructors_test.dart b/packages/freezed/test/multiple_constructors_test.dart index eed74985..9edbae85 100644 --- a/packages/freezed/test/multiple_constructors_test.dart +++ b/packages/freezed/test/multiple_constructors_test.dart @@ -24,8 +24,8 @@ Future main() async { ClassElement _getClassElement(String elementName) { return sources.topLevelElements.whereType().firstWhere( - (element) => element.name == elementName, - ); + (element) => element.name == elementName, + ); } test('Response', () { @@ -175,11 +175,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/multiple_constructors.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/multiple_constructors.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); @@ -411,10 +409,12 @@ void main() { var error = Error(); final value = NameConflict.error(error); - expect(switch (value) { - Something() => 42, - SomeError(:final error) => error, - }, error); + expect( + switch (value) { + Something() => 42, + SomeError(:final error) => error, + }, + error); }); group('NestedList', () { diff --git a/packages/freezed/test/options_test.dart b/packages/freezed/test/options_test.dart index 5f6799e1..a707bccf 100644 --- a/packages/freezed/test/options_test.dart +++ b/packages/freezed/test/options_test.dart @@ -14,11 +14,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/optional_maybe_test.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/optional_maybe_test.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); diff --git a/packages/freezed/test/single_class_constructor_test.dart b/packages/freezed/test/single_class_constructor_test.dart index 1ba1600b..1509a0ae 100644 --- a/packages/freezed/test/single_class_constructor_test.dart +++ b/packages/freezed/test/single_class_constructor_test.dart @@ -198,9 +198,8 @@ Future main() async { test('documentation', () async { final singleClassLibrary = await analyze(); - final doc = - singleClassLibrary.topLevelElements.firstWhere((e) => e.name == 'Doc') - as ClassElement; + final doc = singleClassLibrary.topLevelElements + .firstWhere((e) => e.name == 'Doc') as ClassElement; expect( doc.mixins.first.accessors.where( @@ -402,11 +401,9 @@ void main() { test('has no issue', () async { final singleClassLibrary = await analyze(); - final errorResult = - await singleClassLibrary.session.getErrors( - '/freezed/test/integration/single_class_constructor.freezed.dart', - ) - as ErrorsResult; + final errorResult = await singleClassLibrary.session.getErrors( + '/freezed/test/integration/single_class_constructor.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); }); @@ -635,9 +632,8 @@ void main() { ''', }, (r) => r.findLibraryByName('main')); - final errorResult = - await main!.session.getErrors('/freezed/test/integration/main.dart') - as ErrorsResult; + final errorResult = await main!.session + .getErrors('/freezed/test/integration/main.dart') as ErrorsResult; expect( errorResult.errors.map((e) => e.toString()), diff --git a/packages/freezed/test/typedef_parameter_test.dart b/packages/freezed/test/typedef_parameter_test.dart index 95b45c77..ff6fa0b7 100644 --- a/packages/freezed/test/typedef_parameter_test.dart +++ b/packages/freezed/test/typedef_parameter_test.dart @@ -14,11 +14,9 @@ void main() { ), ); - final errorResult = - await main.session.getErrors( - '/freezed/test/integration/typedef_parameter_test.freezed.dart', - ) - as ErrorsResult; + final errorResult = await main.session.getErrors( + '/freezed/test/integration/typedef_parameter_test.freezed.dart', + ) as ErrorsResult; expect(errorResult.errors, isEmpty); });