Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(brick_build): restore compatability with analyzer 6.5 #435

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/reusable-dart-analyze-format-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ jobs:

- run: dart pub get && dart run melos bootstrap --scope="${{ inputs.package }}"

- run: dart analyze --fatal-infos lib
# TODO: Restore --fatal-infos when analyzer 6.5 is significantly available
# in major versions of Flutter. Likely in Q1 2025 https://github.com/GetDutchie/brick/pull/435
# - run: dart analyze --fatal-infos lib
- run: dart analyze lib
working-directory: packages/${{ inputs.package }}

- run: dart format --output=none --line-length 100 --set-exit-if-changed lib test
Expand Down
4 changes: 4 additions & 0 deletions packages/brick_build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 3.2.1

- Revert `.getDisplayString()` change due to Flutter 3.22 being restricted to analyzer <6.4.1. `meta` is pinned to `1.12` in this version of Flutter, and `analyzer >=6.5.0`, where the change was made, requires `meta >= 1.15`. This change will eventually be re-reverted.

## 3.2.0

- Add convenience mixin `AnnotationFinderWithFieldRename` for field renames in generators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class ProviderSerializableGenerator<Config> {

/// Property under the annotation that contains the serialized config.
///
/// Example, `"restConfig"` here:
/// Such as `"restConfig"` here:
/// ```dart
/// @ConnectOfflineFirstWithRest(
/// restConfig: RestSerializable(...)
Expand Down
5 changes: 3 additions & 2 deletions packages/brick_build/lib/src/utils/shared_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class SharedChecker<_SiblingModel extends Model> {
if (classElement.supertype?.typeArguments == null ||
classElement.supertype!.typeArguments.isEmpty) {
throw InvalidGenerationSourceError(
'Type argument for ${targetType.getDisplayString()} is undefined.',
'Type argument for ${targetType.getDisplayString(withNullability: true)} is undefined.',
todo:
'Define the type on class ${targetType.element}, e.g. `extends ${withoutNullability(classElement.supertype!)}<int>`',
element: targetType.element,
Expand Down Expand Up @@ -243,7 +243,8 @@ class SharedChecker<_SiblingModel extends Model> {
}

/// Print the `DartType` without nullability
static String withoutNullability(DartType type) => type.getDisplayString().replaceAll('?', '');
static String withoutNullability(DartType type) =>
type.getDisplayString(withNullability: true).replaceAll('?', '');

/// Destructs a type to determine the bottom type after going through Futures and Iterables.
///
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_build/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_build
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.2.0
version: 3.2.1

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/brick_json_generators/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## Unreleased

- (test) remove analysis options override for non-standard library prefixes
- Revert `.getDisplayString()` change due to Flutter 3.22 being restricted to analyzer <6.4.1. `meta` is pinned to `1.12` in this version of Flutter, and `analyzer >=6.5.0`, where the change was made, requires `meta >= 1.15`. This change will eventually be re-reverted.

## 3.1.0
## 3.1.1

- Apply standardized lints
- Update `analyzer` constraints to `>=6.0.0 <7.0.0`
Expand Down
4 changes: 2 additions & 2 deletions packages/brick_json_generators/lib/json_deserialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mixin JsonDeserialize<TModel extends Model, Annotation extends FieldSerializable
final nullableSuffix = checker.isNullable ? '?' : '';

return '''$fieldValue$nullableSuffix.map(
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString()})
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString(withNullability: true)})
)$castIterable$defaultValue''';
}

Expand Down Expand Up @@ -138,7 +138,7 @@ mixin JsonDeserialize<TModel extends Model, Annotation extends FieldSerializable
final parameterType = checker.fromJsonConstructor!.parameters.first.type;

final output =
'${klass.displayName}.fromJson($fieldValue as ${parameterType.getDisplayString()})';
'${klass.displayName}.fromJson($fieldValue as ${parameterType.getDisplayString(withNullability: true)})';
if (checker.isNullable) return '$fieldValue != null ? $output : null';
return output;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_json_generators/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_json_gene
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.1.0
version: 3.1.1

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/brick_offline_first_build/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Unreleased

## 3.2.1

- (test) remove analysis options override for non-standard library prefixes
- Revert `.getDisplayString()` change due to Flutter 3.22 being restricted to analyzer <6.4.1. `meta` is pinned to `1.12` in this version of Flutter, and `analyzer >=6.5.0`, where the change was made, requires `meta >= 1.15`. This change will eventually be re-reverted.

## 3.2.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ mixin OfflineFirstJsonDeserialize<TModel extends Model, Annotation extends Field
if (argTypeChecker.hasSerdes) {
final doesHaveConstructor = hasConstructor(checker.argType);
if (doesHaveConstructor) {
final serializableType = argTypeChecker.superClassTypeArgs.first.getDisplayString();
final serializableType =
argTypeChecker.superClassTypeArgs.first.getDisplayString(withNullability: true);
final nullabilityOperator = checker.isNullable ? '?' : '';
return '$fieldValue$nullabilityOperator.map((c) => ${SharedChecker.withoutNullability(checker.argType)}.$constructorName(c as $serializableType))$castIterable$defaultValue';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class OfflineFirstSqliteDeserialize extends SqliteDeserialize {
if (argTypeChecker.hasSerdes) {
final doesHaveConstructor = hasConstructor(checker.argType);
if (doesHaveConstructor) {
final serializableType = argTypeChecker.superClassTypeArgs.last.getDisplayString();
final serializableType =
argTypeChecker.superClassTypeArgs.last.getDisplayString(withNullability: true);
return '''
jsonDecode($fieldValue).map(
(c) => $argType.$constructorName(c as $serializableType)
Expand All @@ -105,7 +106,8 @@ class OfflineFirstSqliteDeserialize extends SqliteDeserialize {
if ((checker as OfflineFirstChecker).hasSerdes) {
final doesHaveConstructor = hasConstructor(field.type);
if (doesHaveConstructor) {
final serializableType = checker.superClassTypeArgs.last.getDisplayString();
final serializableType =
checker.superClassTypeArgs.last.getDisplayString(withNullability: true);
return '${SharedChecker.withoutNullability(field.type)}.$constructorName($fieldValue as $serializableType)';
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_offline_first_build/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_offline_f
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.2.0
version: 3.2.1

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/brick_sqlite_generators/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

## 3.2.2

- Revert `.getDisplayString()` change due to Flutter 3.22 being restricted to analyzer <6.4.1. `meta` is pinned to `1.12` in this version of Flutter, and `analyzer >=6.5.0`, where the change was made, requires `meta >= 1.15`. This change will eventually be re-reverted.

## 3.2.1

- Use `SharedChecker.withoutNullability` instead of stripping null suffixes manually
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SqliteDeserialize<_Model extends SqliteModel> extends SqliteSerdesGenerato
final discoveredByIndex =
'jsonDecode($fieldValue).map((d) => d as int > -1 ? ${SharedChecker.withoutNullability(argType)}.values[d] : null)';
final nullableSuffix = checker.isNullable ? '?' : '';
return '$discoveredByIndex$nullableSuffix.whereType<${argType.getDisplayString()}>()$castIterable';
return '$discoveredByIndex$nullableSuffix.whereType<${argType.getDisplayString(withNullability: true)}>()$castIterable';
}

// Iterable<bool>
Expand All @@ -152,7 +152,7 @@ class SqliteDeserialize<_Model extends SqliteModel> extends SqliteSerdesGenerato
final nullableSuffix = checker.isNullable ? " ?? '[]'" : '';

return '''jsonDecode($fieldValue$nullableSuffix).map(
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString()})
(d) => ${klass.displayName}.fromJson(d as ${parameterType.getDisplayString(withNullability: true)})
)$castIterable$defaultValue''';
}

Expand Down Expand Up @@ -210,7 +210,7 @@ class SqliteDeserialize<_Model extends SqliteModel> extends SqliteSerdesGenerato
} else if (checker.fromJsonConstructor != null) {
final klass = checker.targetType.element as ClassElement;
final parameterType = checker.fromJsonConstructor!.parameters.first.type;
return '${klass.displayName}.fromJson(jsonDecode($fieldValue as String) as ${parameterType.getDisplayString()})';
return '${klass.displayName}.fromJson(jsonDecode($fieldValue as String) as ${parameterType.getDisplayString(withNullability: true)})';
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/brick_sqlite_generators/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/GetDutchie/brick/tree/main/packages/brick_sqlite_ge
issue_tracker: https://github.com/GetDutchie/brick/issues
repository: https://github.com/GetDutchie/brick

version: 3.2.1
version: 3.2.2

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down
Loading