Skip to content

Commit

Permalink
6.0.0 (#94)
Browse files Browse the repository at this point in the history
* #55 passing null in copyWith

* an extra test

* version bump + change notes
  • Loading branch information
numen31337 authored Nov 30, 2024
1 parent 354f441 commit d92c223
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 29 deletions.
3 changes: 3 additions & 0 deletions copy_with_extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 6.0.0
* **BREAKING** The `copyWith` function no longer accepts `null` for non-nullable fields to prevent ambiguity and errors.

## 5.0.4
* Updating `analyzer` to `>=2.0.0 <7.0.0` (thanks [@shilangyu](https://github.com/shilangyu)).

Expand Down
2 changes: 1 addition & 1 deletion copy_with_extension/lib/copy_with_extension.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Provides `CopyWith` annotation class used by [copy_with_extension_gen](https://pub.dev/packages/copy_with_extension_gen).
library copy_with_extension;
library;

import 'package:meta/meta_meta.dart';

Expand Down
4 changes: 2 additions & 2 deletions copy_with_extension/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: copy_with_extension
version: 5.0.4
version: 6.0.0
description: Annotation for generating `copyWith` extensions code using `copy_with_extension_gen`.
homepage: https://github.com/numen31337/copy_with_extension/tree/master/copy_with_extension
repository: https://github.com/numen31337/copy_with_extension
Expand All @@ -12,4 +12,4 @@ dependencies:
meta: ^1.8.0

dev_dependencies:
flutter_lints: ^2.0.1
flutter_lints: ^5.0.0
3 changes: 3 additions & 0 deletions copy_with_extension_gen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 6.0.0
* **BREAKING** The `copyWith` function no longer accepts `null` for non-nullable fields to prevent ambiguity and errors.

## 5.0.4
* Updating `analyzer` to `>=2.0.0 <7.0.0` (thanks [@shilangyu](https://github.com/shilangyu)).

Expand Down
2 changes: 1 addition & 1 deletion copy_with_extension_gen/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// This library is **not** intended to be imported by typical end-users unless
/// you are creating a custom compilation pipeline. See documentation for
/// details, and `build.yaml` for how these builders are configured by default.
library copy_with_extension_gen.builder;
library;

import 'package:build/build.dart' show Builder, BuilderOptions;
import 'package:copy_with_extension_gen/src/settings.dart';
Expand Down
9 changes: 2 additions & 7 deletions copy_with_extension_gen/lib/src/copy_with_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ class CopyWithGenerator extends GeneratorForAnnotation<CopyWith> {
if (v.fieldAnnotation.immutable) return r; // Skip the field

if (isAbstract) {
final type =
v.type.endsWith('?') || v.isDynamic ? v.type : '${v.type}?';
return '$r $type ${v.name},';
return '$r ${v.type} ${v.name},';
} else {
return '$r Object? ${v.name} = const \$CopyWithPlaceholder(),';
}
Expand All @@ -189,11 +187,8 @@ class CopyWithGenerator extends GeneratorForAnnotation<CopyWith> {
return '$r ${v.name}: _value.${v.name},';
}

final nullCheckForNonNullable =
v.nullable ? "" : "|| ${v.name} == null";

return '''$r ${v.isPositioned ? "" : '${v.name}:'}
${v.name} == const \$CopyWithPlaceholder() $nullCheckForNonNullable
${v.name} == const \$CopyWithPlaceholder()
? _value.${v.name}
// ignore: cast_nullable_to_non_nullable
: ${v.name} as ${v.type},''';
Expand Down
4 changes: 2 additions & 2 deletions copy_with_extension_gen/lib/src/field_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ConstructorParameterInfo extends FieldInfo {
super(
name: element.name,
nullable: element.type.nullabilitySuffix != NullabilitySuffix.none,
type: element.type.getDisplayString(withNullability: true),
type: element.type.getDisplayString(),
);

/// Annotation provided by the user with `CopyWithField`.
Expand Down Expand Up @@ -65,7 +65,7 @@ class ConstructorParameterInfo extends FieldInfo {
return FieldInfo(
name: field.name,
nullable: field.type.nullabilitySuffix != NullabilitySuffix.none,
type: field.type.getDisplayString(withNullability: true),
type: field.type.getDisplayString(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion copy_with_extension_gen/lib/src/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CopyWithAnnotation readClassAnnotation(
String typeParametersString(ClassElement classElement, bool nameOnly) {
final names = classElement.typeParameters
.map(
(e) => nameOnly ? e.name : e.getDisplayString(withNullability: true),
(e) => nameOnly ? e.name : e.getDisplayString(),
)
.join(',');
if (names.isNotEmpty) {
Expand Down
10 changes: 5 additions & 5 deletions copy_with_extension_gen/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: copy_with_extension_gen
version: 5.0.4
version: 6.0.0
description: Automatically generating `copyWith` extensions code for classes with `@CopyWith()` annotation.
repository: https://github.com/numen31337/copy_with_extension
homepage: https://github.com/numen31337/copy_with_extension/tree/master/copy_with_extension_gen
Expand All @@ -9,15 +9,15 @@ environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
analyzer: ">=2.0.0 <7.0.0"
analyzer: ^6.5.0
build: ^2.0.0
source_gen: ^1.0.0
copy_with_extension: ^5.0.0
copy_with_extension: ^6.0.0
meta: ^1.8.0

dev_dependencies:
equatable: ^2.0.5
flutter_lints: ^2.0.1
build_runner: ">=1.11.5 <3.0.0"
flutter_lints: ^5.0.0
build_runner: ^2.0.0
test: ^1.20.1
source_gen_test: ^1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ void main() {
const CopyWithValues(id: '').copyWith(id: "test").id,
"test",
);

expect(const CopyWithValues(id: '').copyWith(id: null).id, '');
});

test('CopyWithValuesOptional', () {
Expand All @@ -91,6 +89,11 @@ void main() {
const CopyWithValuesOptional(id: "test").copyWith(id: null).id,
null,
);

expect(
const CopyWithValuesOptional(id: "test").copyWith().id,
"test",
);
});

test('CopyWithProxy', () {
Expand Down
8 changes: 4 additions & 4 deletions copy_with_extension_gen/test/gen_inheritance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mixin Mixin on BasicBaseClass {

@CopyWith()
class BasicSubClass<T> extends BasicBaseClass {
const BasicSubClass({required String id, this.item}) : super(id: id);
const BasicSubClass({required super.id, this.item});

final T? item;
}
Expand All @@ -32,15 +32,15 @@ class ComplexSubClass<T, U extends String> extends BasicSubClass<T>
with Mixin
implements AbstractClass {
ComplexSubClass({
required String id,
required super.id,
required this.date,
this.privateField,
this.abstractString,
this.listWithGenericType,
this.listWithTypedType,
this.listWithType,
T? item,
}) : super(id: id, item: item);
super.item,
});

ComplexSubClass.secondConstructor({required String id})
: this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class _$BasicClassCWProxy<T extends Iterable<int>> {
/// BasicClass<T>(...).copyWith(id: 12, name: "My name")
/// ````
BasicClass<T> call({
String? id,
String id,
T? optional,
});
}
Expand All @@ -35,7 +35,7 @@ class _$BasicClassCWProxyImpl<T extends Iterable<int>>
Object? optional = const $CopyWithPlaceholder(),
}) {
return BasicClass<T>(
id: id == const $CopyWithPlaceholder() || id == null
id: id == const $CopyWithPlaceholder()
? _value.id
// ignore: cast_nullable_to_non_nullable
: id as String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class _$BasicClassCWProxy<T extends Iterable<int>> {
/// BasicClass<T>(...).copyWith(id: 12, name: "My name")
/// ````
BasicClass<T> call({
String? id,
String id,
T? optional,
});
}
Expand Down Expand Up @@ -44,7 +44,7 @@ class _$BasicClassCWProxyImpl<T extends Iterable<int>>
Object? optional = const $CopyWithPlaceholder(),
}) {
return BasicClass<T>(
id: id == const $CopyWithPlaceholder() || id == null
id: id == const $CopyWithPlaceholder()
? _value.id
// ignore: cast_nullable_to_non_nullable
: id as String,
Expand Down

0 comments on commit d92c223

Please sign in to comment.