Skip to content

Commit

Permalink
Merge pull request #960 from Workiva/analyzer-6
Browse files Browse the repository at this point in the history
FED-3255 Allow analyzer 6.x
  • Loading branch information
rmconsole5-wk authored Oct 18, 2024
2 parents 85ed6a8 + bf0fa9c commit 39ae7d7
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 25 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/dart_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ jobs:
matrix:
sdk: [ 2.19.6, stable ]
analyzer:
# We only have one version currently, but we'll leave this CI step in place
# for the next time we need to support multiple analyzer versions.
- ^5.1.0
- ^5.13.0 # This should match the lower bound
- ^6.0.0
exclude:
# Analyzer 6 only resolves in Dart 3
- sdk: 2.19.6
analyzer: ^6.0.0

steps:
- uses: actions/checkout@v4
- id: setup-dart
Expand Down
2 changes: 1 addition & 1 deletion lib/src/builder/codegen/typed_map_impl_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
for (var i = 0; i < mixins.length; i++) {
final mixin = mixins[i];
final typeArguments = mixin.typeArguments?.toSource() ?? '';
final names = TypedMapNames(mixin.name.name);
final names = TypedMapNames(mixin.nameWithPrefix);
header.write('${names.consumerName}$typeArguments');
header.write(',');
// Add a space at the beginning of the line so that dartfmt indents it
Expand Down
12 changes: 11 additions & 1 deletion lib/src/builder/parsing/ast_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ extension TypeAnnotationNameHelper on TypeAnnotation {
/// field of [Identifier]s.
extension TypeNameHelper on NamedType {
/// The type name without any namespace prefixes.
String get nameWithoutPrefix => name.nameWithoutPrefix;
String get nameWithoutPrefix => name2.lexeme;

/// The type name including the namespace prefix.
String get nameWithPrefix {
final prefix = importPrefix?.name.lexeme;
final name = name2.lexeme;
return [
if (prefix != null) prefix,
name,
].join('.');
}
}

/// Utilities related to simplifying access to node identifier fields.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/builder/parsing/declarations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mixin _TypedMapMixinShorthandDeclaration {
.toList();

if (badConstraints != null && badConstraints.isNotEmpty) {
final badConstraintsString = badConstraints.map((c) => c.name.name).join(', ');
final badConstraintsString = badConstraints.map((c) => c.nameWithPrefix).join(', ');

final suggestedImplName = mixin.name.name.endsWith('Mixin')
? mixin.name.name.replaceFirst(RegExp(r'Mixin$'), '')
Expand All @@ -229,7 +229,7 @@ extension on Union<BoilerplateProps, BoilerplatePropsMixin> {
/// This is the safest way to retrieve that information because it takes
/// into account the nature of the [Union] typing of `props`.
List<String> get allPropsMixins => this.switchCase(
(a) => a.nodeHelper.mixins.map((name) => name.name.name).toList(),
(a) => a.nodeHelper.mixins.map((name) => name.nameWithPrefix).toList(),
(b) => [b.name.name],
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:

dependencies:
collection: ^1.15.0
analyzer: ^5.13.0
analyzer: '>=5.13.0 <7.0.0'
build: ^2.0.0
dart_style: ^2.0.0
js: ^0.6.1+1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ main() {

expect(parseAndGetSingleClassish('''
abstract class Foo implements Bar, Baz {}
''').interfaces.map((i) => i.name.name), ['Bar', 'Baz']);
''').interfaces.map((i) => i.name2.name), ['Bar', 'Baz']);
});

test('withClause', () {
Expand Down Expand Up @@ -105,7 +105,7 @@ main() {

expect(parseAndGetSingleClassish('''
class Foo extends Bar {}
''').superclass?.name.name, 'Bar');
''').superclass?.name2.name, 'Bar');
});

test('mixins', () {
Expand All @@ -115,13 +115,13 @@ main() {

expect(parseAndGetSingleClassish('''
class Foo extends Object with Bar, Baz {}
''').mixins.map((m) => m.name.name), ['Bar', 'Baz']);
''').mixins.map((m) => m.name2.name), ['Bar', 'Baz']);
});

test('allSuperTypes', () {
expect(parseAndGetSingleClassish('''
class Foo extends Bar with Baz implements Qux {}
''').allSuperTypes.map((m) => m.name.name), unorderedEquals(['Bar', 'Baz', 'Qux']));
''').allSuperTypes.map((m) => m.name2.name), unorderedEquals(['Bar', 'Baz', 'Qux']));
});
});
});
Expand All @@ -148,7 +148,7 @@ main() {

expect(parseAndGetSingleClassish('''
abstract class Foo = Object with Something implements Bar, Baz;
''').interfaces.map((i) => i.name.name), ['Bar', 'Baz']);
''').interfaces.map((i) => i.name2.name), ['Bar', 'Baz']);
});

test('withClause', () {
Expand Down Expand Up @@ -180,19 +180,19 @@ main() {
test('superclass', () {
expect(parseAndGetSingleClassish('''
class Foo = Bar with Baz;
''').superclass?.name.name, 'Bar');
''').superclass?.name2.name, 'Bar');
});

test('mixins', () {
expect(parseAndGetSingleClassish('''
class Foo = Object with Bar, Baz;
''').mixins.map((m) => m.name.name), ['Bar', 'Baz']);
''').mixins.map((m) => m.name2.name), ['Bar', 'Baz']);
});

test('allSuperTypes', () {
expect(parseAndGetSingleClassish('''
class Foo = Bar with Baz implements Qux;
''').allSuperTypes.map((m) => m.name.name), unorderedEquals(['Bar', 'Baz', 'Qux']));
''').allSuperTypes.map((m) => m.name2.name), unorderedEquals(['Bar', 'Baz', 'Qux']));
});
});
});
Expand Down Expand Up @@ -232,7 +232,7 @@ main() {

expect(parseAndGetSingleClassish('''
mixin Foo on Bar implements Baz {}
''').interfaces.map((i) => i.name.name), unorderedEquals(['Bar', 'Baz']));
''').interfaces.map((i) => i.name2.name), unorderedEquals(['Bar', 'Baz']));
});

test('withClause', () {
Expand Down Expand Up @@ -268,7 +268,7 @@ main() {
test('allSuperTypes', () {
expect(parseAndGetSingleClassish('''
mixin Foo on Bar implements Baz {}
''').allSuperTypes.map((m) => m.name.name), unorderedEquals(['Bar', 'Baz']));
''').allSuperTypes.map((m) => m.name2.name), unorderedEquals(['Bar', 'Baz']));
});
});
});
Expand Down
25 changes: 18 additions & 7 deletions test/vm_tests/builder/parsing/ast_util_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,28 @@ main() {
foo.SomeTypeName foo;
''')).nameWithoutPrefix, 'SomeTypeName');
});

test('nameWithPrefix', () {
expect(TypeNameHelper(parseAndGetSingleWithType('''
SomeTypeName foo;
''')).nameWithPrefix, 'SomeTypeName');

expect(TypeNameHelper(parseAndGetSingleWithType('''
foo.SomeTypeName foo;
''')).nameWithPrefix, 'foo.SomeTypeName');
});
});

group('NameHelper', () {
test('nameWithoutPrefix', () {
expect(NameHelper(parseAndGetFirstWithType('''
SomeName foo;
''')).nameWithoutPrefix, 'SomeName');

expect(NameHelper(parseAndGetFirstWithType('''
foo.SomeName foo;
''')).nameWithoutPrefix, 'SomeName');
final identifier = parseAndGetSingleWithType<ExpressionFunctionBody>('''
example() => identifier;
''').expression as Identifier;
expect(NameHelper(identifier).nameWithoutPrefix, 'identifier');

expect(NameHelper(parseAndGetFirstWithType<PrefixedIdentifier>('''
example() => foo.identifier;
''')).nameWithoutPrefix, 'identifier');
});
});

Expand Down

0 comments on commit 39ae7d7

Please sign in to comment.