Skip to content

Commit 0e03dad

Browse files
authored
Support latest pkg:analyzer, prepare v2.2.11 (#193)
1 parent 1c3aa4e commit 0e03dad

6 files changed

Lines changed: 129 additions & 17 deletions

File tree

build_cli/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
## 2.2.11-wip
1+
## 2.2.11
22

33
- Validate that `allowedHelp` keys match `allowed` values.
4+
- Required `analyzer: ">=10.0.0 <13.0.0"`
5+
- Required `build: ^4.0.4`
6+
- Required `source_gen: ^4.1.2`
7+
- Required `source_helper: ^1.3.10`
48

59
## 2.2.10
610

build_cli/lib/src/enum_helpers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Map<FieldElement, String>? _enumFieldsMap(DartType targetType) {
2929
if (targetType is InterfaceType && targetType.element is EnumElement) {
3030
return Map<FieldElement, String>.fromEntries(
3131
targetType.element.fields
32-
.where((p) => !p.isSynthetic)
32+
.where((p) => p.isOriginDeclaration)
3333
.map((p) => MapEntry(p, p.name!)),
3434
);
3535
}

build_cli/lib/src/to_share.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ Never throwUnsupported(FieldElement element, String message, {String? todo}) =>
3131
Set<FieldElement> createSortedFieldSet(InstanceElement element) {
3232
// Get all of the fields that need to be assigned
3333
// TODO: support overriding the field set with an annotation option
34-
final fieldsList = element.fields.where((e) => !e.isStatic).toList();
34+
final fieldsList = element.fields
35+
.where((e) => !e.isStatic)
36+
.cast<FieldElement>()
37+
.toList();
3538

3639
final manager = InheritanceManager3();
3740

@@ -41,8 +44,8 @@ Set<FieldElement> createSortedFieldSet(InstanceElement element) {
4144
continue;
4245
}
4346

44-
if (v is PropertyAccessorElement && v.baseElement is FieldElement) {
45-
fieldsList.add(v.baseElement as FieldElement);
47+
if (v case PropertyAccessorElement(:final FieldElement variable)) {
48+
fieldsList.add(variable);
4649
}
4750
}
4851

@@ -74,7 +77,7 @@ int _sortByLocation(FieldElement a, FieldElement b) {
7477
/// Returns the offset of given field/property in its source file – with a
7578
/// preference for the getter if it's defined.
7679
int offsetFor(FieldElement e) {
77-
if (e.isSynthetic) {
80+
if (!e.isOriginDeclaration) {
7881
return (e.getter ?? e.setter)!.firstFragment.nameOffset ?? 0;
7982
}
8083
return e.firstFragment.nameOffset ?? 0;

build_cli/pubspec.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: build_cli
2-
version: 2.2.11-wip
2+
version: 2.2.11
33
description: >-
44
Parse command line arguments directly into an annotation class
55
using the power of build_runner and source_gen.
@@ -11,25 +11,25 @@ environment:
1111
resolution: workspace
1212

1313
dependencies:
14-
analyzer: ">=9.0.0 <11.0.0"
15-
build: ^4.0.3
14+
analyzer: ">=10.0.0 <13.0.0"
15+
build: ^4.0.4
1616
# Limit version range on build_cli_annotations
1717
# new features need to stay in sync
1818
build_cli_annotations: ">=2.1.1 <2.2.0"
1919
build_config: ^1.2.0
2020
pub_semver: ^2.1.4
21-
source_gen: ^4.1.1
22-
source_helper: ^1.3.9
21+
source_gen: ^4.1.2
22+
source_helper: ^1.3.10
2323
yaml: ^3.1.3
2424

2525
dev_dependencies:
2626
# Args is exported and restricted by `build_cli_annotation`, but tests in this
2727
# package assume the output of features in ^2.0.0
2828
args: ^2.6.0
29-
build_runner: ^2.10.4
29+
build_runner: ^2.10.5
3030
build_verify: ^3.0.0
3131
dart_flutter_team_lints: ^3.2.0
3232
io: ^1.0.0
3333
path: ^1.9.0
34-
source_gen_test: ^1.3.3
35-
test: ^1.27.0
34+
source_gen_test: ^1.3.4
35+
test: ^1.29.0

build_cli/test/build_cli_test.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Future<void> main() async {
2121
libraryReader,
2222
generator,
2323
expectedAnnotatedTests: [
24+
'AllowedHelpKeyNoAllowed',
25+
'AllowedHelpKeyNotInAllowed',
2426
'AnnotatedCommandNoParser',
2527
'AnnotatedCommandWithParser',
2628
'annotatedMethod',
@@ -34,18 +36,18 @@ Future<void> main() async {
3436
'FlagWithAllowedHelp',
3537
'FlagWithStringDefault',
3638
'FlagWithValueHelp',
39+
'GenericSubClass',
3740
'LonelyWasParsed',
3841
'NegatableMultiOption',
3942
'NegatableOption',
43+
'NonNullableTypes',
4044
'PrivateCtor',
4145
'SpecialNotAnnotated',
46+
'SubClass',
4247
'theAnswer',
4348
'TwoNonDefaultConstructors',
4449
'UnsupportedFieldType',
4550
'WithCommand',
46-
'NonNullableTypes',
47-
'AllowedHelpKeyNotInAllowed',
48-
'AllowedHelpKeyNoAllowed',
4951
],
5052
);
5153
});

build_cli/test/test_input/test_input.dart

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,3 +463,106 @@ class NonNullableTypes {
463463
required this.number,
464464
});
465465
}
466+
467+
class SuperClass {
468+
String? superField;
469+
}
470+
471+
@ShouldGenerate(r'''
472+
SubClass _$parseSubClassResult(ArgResults result) => SubClass()
473+
..superField = result['super-field'] as String?
474+
..yLocal = result['y-local'] as String?
475+
..xLocal = result['x-local'] as String?
476+
..wExplicitSetter = result['w-explicit-setter'] as String?
477+
..subclassField = result['subclass-field'] as String?;
478+
479+
ArgParser _$populateSubClassParser(ArgParser parser) => parser
480+
..addOption(
481+
'super-field',
482+
)
483+
..addOption(
484+
'y-local',
485+
)
486+
..addOption(
487+
'x-local',
488+
)
489+
..addOption(
490+
'w-explicit-setter',
491+
)
492+
..addOption(
493+
'subclass-field',
494+
);
495+
496+
final _$parserForSubClass = _$populateSubClassParser(ArgParser());
497+
498+
SubClass parseSubClass(List<String> args) {
499+
final result = _$parserForSubClass.parse(args);
500+
return _$parseSubClassResult(result);
501+
}
502+
''')
503+
@CliOptions()
504+
class SubClass extends SuperClass {
505+
String? yLocal;
506+
String? xLocal;
507+
String? get wExplicitSetter => null;
508+
set wExplicitSetter(String? value) {}
509+
String? subclassField;
510+
}
511+
512+
abstract class GenericSuperClass<T> {
513+
T? bField;
514+
T? aField;
515+
}
516+
517+
@ShouldGenerate(r'''
518+
T _$badNumberFormat<T extends num>(
519+
String source,
520+
String type,
521+
String argName,
522+
) =>
523+
throw FormatException(
524+
'Cannot parse "$source" into `$type` for option "$argName".',
525+
);
526+
527+
GenericSubClass _$parseGenericSubClassResult(ArgResults result) =>
528+
GenericSubClass()
529+
..bField = result['b-field'] != null
530+
? int.tryParse(result['b-field'] as String) ??
531+
_$badNumberFormat(
532+
result['b-field'] as String,
533+
'int',
534+
'b-field',
535+
)
536+
: null
537+
..aField = result['a-field'] != null
538+
? int.tryParse(result['a-field'] as String) ??
539+
_$badNumberFormat(
540+
result['a-field'] as String,
541+
'int',
542+
'a-field',
543+
)
544+
: null
545+
..subclassField = result['subclass-field'] as String?;
546+
547+
ArgParser _$populateGenericSubClassParser(ArgParser parser) => parser
548+
..addOption(
549+
'b-field',
550+
)
551+
..addOption(
552+
'a-field',
553+
)
554+
..addOption(
555+
'subclass-field',
556+
);
557+
558+
final _$parserForGenericSubClass = _$populateGenericSubClassParser(ArgParser());
559+
560+
GenericSubClass parseGenericSubClass(List<String> args) {
561+
final result = _$parserForGenericSubClass.parse(args);
562+
return _$parseGenericSubClassResult(result);
563+
}
564+
''')
565+
@CliOptions()
566+
class GenericSubClass extends GenericSuperClass<int> {
567+
String? subclassField;
568+
}

0 commit comments

Comments
 (0)