Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rrousselGit/freezed into …
Browse files Browse the repository at this point in the history
…pr/rekire/1069
  • Loading branch information
rrousselGit committed May 14, 2024
2 parents 4c96853 + 83ff203 commit fe207f9
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- uses: actions/add-to-project@v1.0.0
- uses: actions/add-to-project@v1.0.1
with:
project-url: https://github.com/users/rrousselGit/projects/8
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
4 changes: 4 additions & 0 deletions packages/freezed/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased patch

- Support analyzer 6.5.0

## 2.5.2 - 2024-04-11

- Fixed `copyWith(value: null)` when using nullable generics
Expand Down
6 changes: 1 addition & 5 deletions packages/freezed/lib/src/freezed_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ class FreezedGenerator extends ParserGenerator<GlobalData, Data, Freezed> {
final commonTypeString = resolveFullTypeStringFrom(
library,
commonTypeBetweenAllUnionConstructors,
withNullability: true,
);

final commonProperty = Property(
Expand Down Expand Up @@ -341,7 +340,6 @@ class FreezedGenerator extends ParserGenerator<GlobalData, Data, Freezed> {
type: resolveFullTypeStringFrom(
library,
copyWithType,
withNullability: true,
),
isNullable: copyWithType.isNullable,
isDartList: copyWithType.isDartCoreList,
Expand Down Expand Up @@ -488,7 +486,6 @@ class FreezedGenerator extends ParserGenerator<GlobalData, Data, Freezed> {
yield resolveFullTypeStringFrom(
constructor.library,
(object.type! as InterfaceType).typeArguments.single,
withNullability: false,
);
}
}
Expand All @@ -508,7 +505,6 @@ class FreezedGenerator extends ParserGenerator<GlobalData, Data, Freezed> {
yield resolveFullTypeStringFrom(
constructor.library,
(object.type! as InterfaceType).typeArguments.single,
withNullability: false,
);
}
}
Expand Down Expand Up @@ -547,7 +543,7 @@ class FreezedGenerator extends ParserGenerator<GlobalData, Data, Freezed> {
genericParameters: GenericsParameterTemplate(
(parameter.type as InterfaceType)
.typeArguments
.map((e) => e.getDisplayString(withNullability: true))
.map((e) => e.getDisplayString())
.toList(),
),
);
Expand Down
3 changes: 1 addition & 2 deletions packages/freezed/lib/src/templates/concrete_template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ extension DefaultValue on ParameterElement {
}

String? parseTypeSource(VariableElement element) {
String? type = element.type.getDisplayString(withNullability: true);
String? type = element.type.getDisplayString();

if ((type.contains('dynamic') || type.contains('InvalidType')) &&
element.nameOffset > 0) {
Expand All @@ -578,6 +578,5 @@ String? parseTypeSource(VariableElement element) {
return resolveFullTypeStringFrom(
element.library!,
element.type,
withNullability: true,
);
}
2 changes: 1 addition & 1 deletion packages/freezed/lib/src/templates/parameter_template.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GenericsDefinitionTemplate {
factory GenericsDefinitionTemplate.fromGenericElement(
List<TypeParameterElement> generics) {
return GenericsDefinitionTemplate(
generics.map((e) => e.getDisplayString(withNullability: true)).toList(),
generics.map((e) => e.getDisplayString()).toList(),
);
}

Expand Down
9 changes: 4 additions & 5 deletions packages/freezed/lib/src/tools/type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ Element? _getElementForType(DartType type) {
/// Renders a type based on its string + potential import alias
String resolveFullTypeStringFrom(
LibraryElement originLibrary,
DartType type, {
required bool withNullability,
}) {
DartType type,
) {
final owner = originLibrary.prefixes.firstWhereOrNull(
(e) {
return e.imports.any((l) {
Expand All @@ -52,7 +51,7 @@ String resolveFullTypeStringFrom(
},
);

String? displayType = type.getDisplayString(withNullability: withNullability);
String? displayType = type.getDisplayString();

// The parameter is a typedef in the form of
// SomeTypedef typedef
Expand Down Expand Up @@ -95,7 +94,7 @@ String resolveFullTypeStringFrom(
(t) => t is InvalidType,
dynamicType,
);
displayType = modified.getDisplayString(withNullability: withNullability);
displayType = modified.getDisplayString();
}

if (owner != null) {
Expand Down
4 changes: 3 additions & 1 deletion packages/freezed/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ environment:
sdk: ">=2.17.0 <3.0.0"

dependencies:
analyzer: ">=5.13.0 <7.0.0"
analyzer: ">=6.5.0 <7.0.0"
build: ^2.3.1
build_config: ^1.1.0
collection: ^1.15.0
meta: ^1.9.1
source_gen: ^1.4.0
freezed_annotation: ^2.4.1
json_annotation: ^4.6.0
# Indirect dependency, but fixes a compiler error when using `pub downgrade`
dart_style: ^2.3.6

dev_dependencies:
json_serializable: ^6.3.2
Expand Down
61 changes: 11 additions & 50 deletions packages/freezed/test/multiple_constructors_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ Future<void> main() async {
final recursiveClass = _getClassElement('_RecursiveWith\$DollarNext');

expect(
recursiveClass
.getField('value')!
.type
.getDisplayString(withNullability: true),
recursiveClass.getField('value')!.type.getDisplayString(),
'RecursiveWith\$DollarImpl',
);
});
Expand Down Expand Up @@ -532,63 +529,39 @@ void main() {
test('generates List of correct type', () async {
final nestedListClass = _getClassElement('ShallowNestedList');

expect(
nestedListClass
.getField('children')!
.type
.getDisplayString(withNullability: true),
expect(nestedListClass.getField('children')!.type.getDisplayString(),
'List<LeafNestedListItem>');
});

test('generates List of correct type for deeply nested case', () async {
final nestedListClass = _getClassElement('DeepNestedList');

expect(
nestedListClass
.getField('children')!
.type
.getDisplayString(withNullability: true),
expect(nestedListClass.getField('children')!.type.getDisplayString(),
'List<InnerNestedListItem>');

final nestedListItemClass = _getClassElement('InnerNestedListItem');

expect(
nestedListItemClass
.getField('children')!
.type
.getDisplayString(withNullability: true),
expect(nestedListItemClass.getField('children')!.type.getDisplayString(),
'List<LeafNestedListItem>');
});
});
group('NestedMap', () {
test('generates Map of correct type', () async {
final nestedMapClass = _getClassElement('ShallowNestedMap');

expect(
nestedMapClass
.getField('children')!
.type
.getDisplayString(withNullability: true),
expect(nestedMapClass.getField('children')!.type.getDisplayString(),
'Map<String, LeafNestedMapItem>');
});

test('generates Map of correct type for deeply nested case', () async {
final nestedMapClass = _getClassElement('DeepNestedMap');

expect(
nestedMapClass
.getField('children')!
.type
.getDisplayString(withNullability: true),
expect(nestedMapClass.getField('children')!.type.getDisplayString(),
'Map<String, InnerNestedMapItem>');

final nestedMapItemClass = _getClassElement('InnerNestedMapItem');

expect(
nestedMapItemClass
.getField('children')!
.type
.getDisplayString(withNullability: true),
expect(nestedMapItemClass.getField('children')!.type.getDisplayString(),
'Map<String, LeafNestedMapItem>');
});
});
Expand All @@ -598,31 +571,19 @@ void main() {
final nestedMapClass = _getClassElement('_UsesGenerated');

expect(
nestedMapClass
.getField('value')!
.type
.getDisplayString(withNullability: true),
nestedMapClass.getField('value')!.type.getDisplayString(),
'CodeGenerated',
);
expect(
nestedMapClass
.getField('list')!
.type
.getDisplayString(withNullability: true),
nestedMapClass.getField('list')!.type.getDisplayString(),
'List<CodeGenerated>',
);
expect(
nestedMapClass
.getField('nestedList')!
.type
.getDisplayString(withNullability: true),
nestedMapClass.getField('nestedList')!.type.getDisplayString(),
'List<List<CodeGenerated>>',
);
expect(
nestedMapClass
.getField('map')!
.type
.getDisplayString(withNullability: true),
nestedMapClass.getField('map')!.type.getDisplayString(),
'Map<int, CodeGenerated>',
);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/freezed_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased patch

- Support analyzer 6.5.0

## 0.0.1 - 2024-02-04

- Support latest custom_lint version.
Expand Down
4 changes: 2 additions & 2 deletions packages/freezed_lint/lib/src/missing_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class MissingMixin extends DartLintRule {
final name = '_\$${element.name}';
final withClause = node.withClause;
if (withClause == null) {
reporter.reportErrorForElement(code, element, [name]);
reporter.atElement(element, code, arguments: [name]);
return;
}

final mixins = withClause.mixinTypes;
if (mixins.any((m) => name == m.name2.lexeme)) return;
reporter.reportErrorForElement(code, element, [name]);
reporter.atElement(element, code, arguments: [name]);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MissingPrivateEmptyCtor extends DartLintRule {

final constToken = element.constToken();
final name = '${constToken}${element.displayName}._();';
reporter.reportErrorForElement(code, element, [name]);
reporter.atElement(element, code, arguments: [name]);
});
}

Expand Down
4 changes: 1 addition & 3 deletions packages/freezed_lint/lib/src/tools/element_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';

extension DartTypeExt on DartType {
bool hasName(String name) {
return getDisplayString(withNullability: false) == name;
}
bool hasName(String name) => getDisplayString() == name;
}

extension ClassElementExt on ClassElement {
Expand Down
2 changes: 1 addition & 1 deletion packages/freezed_lint/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
analyzer: ^6.0.0
analyzer: ^6.5.0
analyzer_plugin: ^0.11.2
custom_lint_builder: ^0.6.0
freezed_annotation: ^2.3.0
Expand Down

0 comments on commit fe207f9

Please sign in to comment.