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

FEDX-165 Upgrade to analyzer 5 #835

Merged
merged 45 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
18d6877
"Update dev dependencies for analyzer 2"
Aug 30, 2023
bdc3467
pub get and format
robbecker-wf Aug 31, 2023
a7a456f
Upgrade main package to analyzer 5
greglittlefield-wf Sep 5, 2023
35243a2
Upgrade main package to analyzer 5
greglittlefield-wf Sep 5, 2023
474bb3c
Fix test file not getting run due to it missing the _test suffix
greglittlefield-wf Sep 5, 2023
b366b4f
Update generated code
greglittlefield-wf Sep 5, 2023
e82647a
Update CI analyzer matrix, run on 2.19, stop running on 2.13.4
greglittlefield-wf Sep 5, 2023
155e40d
Update generated comment placement to smooth over formatting differen…
greglittlefield-wf Sep 5, 2023
c8e8e5a
Update generated files with new comment placements
greglittlefield-wf Sep 5, 2023
780119a
Update gold files with new comment placements
greglittlefield-wf Sep 5, 2023
f2ffd7d
Update Dockerfile Dart version
greglittlefield-wf Sep 5, 2023
1dce39a
Upgrade analyzer and analyzer_plugin, first stab at fixing ServerPlug…
greglittlefield-wf Sep 6, 2023
6a852c4
Address analyzer breakages
greglittlefield-wf Sep 6, 2023
946cf1f
Address analyzer breakages in boilerplate_validator
greglittlefield-wf Sep 6, 2023
ea6bf32
Refactor test setup in response to analyzer_plugin changes
greglittlefield-wf Sep 6, 2023
620db2f
Fix bad usages of ClassElement now that mixins elements don't use it
greglittlefield-wf Sep 6, 2023
2a299d9
Update plugin test setup to use shared analysis context
greglittlefield-wf Sep 6, 2023
9d2fd9b
Fix ast_util tests
greglittlefield-wf Sep 6, 2023
6d3583b
Support tests with custom analysis_options.yaml
greglittlefield-wf Sep 7, 2023
4779728
Sync NodeLocator(2) and tests from analyzer package
greglittlefield-wf Sep 7, 2023
511ca2a
Fix boilerplate_util tests
greglittlefield-wf Sep 7, 2023
4e961de
Fix analysis warnings in test cases
greglittlefield-wf Sep 7, 2023
6070bd6
Fix references to types no longer being Identifiers
greglittlefield-wf Sep 7, 2023
d798b10
Fix warning
greglittlefield-wf Sep 7, 2023
2d80fd4
Revert local pubspec.yaml changes
greglittlefield-wf Sep 7, 2023
eb61939
Fix dependency_validator issues
greglittlefield-wf Sep 7, 2023
1dc9e27
Fix code dependent on newer analyzer version than lower bound
greglittlefield-wf Sep 8, 2023
9eb82d7
Fix hint
greglittlefield-wf Sep 8, 2023
9209594
Clean up implementation imports
greglittlefield-wf Sep 8, 2023
eb9415f
Omit types in StubServerPlugin overrides to clean up imports and remo…
greglittlefield-wf Sep 8, 2023
ec32364
Cleanup
greglittlefield-wf Sep 8, 2023
a542aee
Port over package_util tests
greglittlefield-wf Sep 8, 2023
07fb65f
Clean up unused SharedAnalysisContext-related code
greglittlefield-wf Sep 8, 2023
86feba0
Delete temporary shared contexts after use
greglittlefield-wf Sep 8, 2023
080bb7f
Clean up temporary test fixture pathing
greglittlefield-wf Sep 8, 2023
aed6ca3
Add attribution
greglittlefield-wf Sep 8, 2023
471bf57
Clean up newSource API
greglittlefield-wf Sep 8, 2023
edc08c6
Clean up and document StubChannel
greglittlefield-wf Sep 8, 2023
d49d36a
Remove unused dependency
greglittlefield-wf Sep 8, 2023
c10f1d3
Clean up unused_local_variable ignore
greglittlefield-wf Sep 8, 2023
8adc8ed
Remove outdated comment
greglittlefield-wf Sep 8, 2023
b132fe3
Remove unused NavigationMixin to fix VS Code
greglittlefield-wf Sep 8, 2023
e52d994
Fix missed NavigationMixin
greglittlefield-wf Sep 8, 2023
9bcf9b0
Don't analyze non-Dart files
greglittlefield-wf Sep 8, 2023
2aaba91
Don't warn on keys based on enum values
greglittlefield-wf Sep 8, 2023
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
17 changes: 5 additions & 12 deletions .github/workflows/dart_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ jobs:
fail-fast: false
matrix:
# Can't run on `dev` (Dart 3) until we're fully null-safe.
# We can't run on Dart >=2.19 until https://github.com/dart-lang/sdk/issues/51128
# is fixed, or we work around it, which requires upgrading to analyzer ^5.1.0.
sdk: [ 2.13.4, 2.18.7 ]
sdk: [ 2.18.7, 2.19.6 ]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v0.2
Expand Down Expand Up @@ -88,16 +86,11 @@ jobs:
fail-fast: false
matrix:
# Can't run on `dev` (Dart 3) until we're fully null-safe.
# We can't run on Dart >=2.19 until https://github.com/dart-lang/sdk/issues/51128
# is fixed, or we work around it, which requires upgrading to analyzer ^5.1.0.
sdk: [ 2.13.4, 2.18.7 ]
sdk: [ 2.18.7, 2.19.6 ]
analyzer:
- ^1.0.0
- ^2.0.0
# Don't validate analyzer ^2.0.0 in 2.13.4 since it can't resolve.
exclude:
- sdk: 2.13.4
analyzer: ^2.0.0
# 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
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v0.2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ pubspec.lock

# Should not track the output of code coverage for now
coverage/

tools/analyzer_plugin/test/test_fixtures/**/lib/dynamic_test_files/
tools/analyzer_plugin/test/temporary_test_fixtures/**
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM google/dart:2.13
FROM dart:2.18

# Expose env vars for git ssh access
ARG GIT_SSH_KEY
Expand Down
2 changes: 1 addition & 1 deletion app/over_react_redux/todo_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dev_dependencies:
test: ^1.15.7
test_html_builder: ^3.0.0
time: ^1.2.0
w_common: '>=2.0.0 <4.0.0'
w_common: ^3.0.0
workiva_analysis_options: ^1.1.0

dependency_overrides:
Expand Down
15 changes: 8 additions & 7 deletions lib/src/builder/codegen/accessors_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract class TypedMapAccessorsGenerator extends BoilerplateDeclarationGenerato

String get accessorsMixinName;

ClassOrMixinDeclaration get node => member.node as ClassOrMixinDeclaration;
ClassishDeclaration get node => member.node.asClassish();

TypeParameterList get typeParameters => member.nodeHelper.typeParameters;

Expand Down Expand Up @@ -363,7 +363,9 @@ class _TypedMapMixinAccessorsGenerator extends TypedMapAccessorsGenerator {

@override
void generate() {
outputContentsBuffer..write(_generateAccessorsMixin())..write(_generateMetaConstImpl());
outputContentsBuffer
..write(_generateAccessorsMixin())
..write(_generateMetaConstImpl());
}
}

Expand Down Expand Up @@ -422,9 +424,8 @@ class _LegacyTypedMapAccessorsGenerator extends TypedMapAccessorsGenerator {
return '';
}

final classishNode = node.asClassish();
final metadata = classishNode.metadata;
final typeParameters = classishNode.typeParameters;
final metadata = node.metadata;
final typeParameters = node.typeParameters;
final typeParamsOnClass = typeParameters?.toSource() ?? '';
final typeParamsOnSuper = removeBoundsFromTypeParameters(typeParameters);
final accessorsMixinName = names.legacyAccessorsMixinName;
Expand Down Expand Up @@ -462,7 +463,7 @@ class TypedMapType {
static const TypedMapType stateMixin = TypedMapType(false, false, true);
}

String _copyClassMembers(ClassOrMixinDeclaration node) {
String _copyClassMembers(ClassishDeclaration node) {
bool isValidForCopying(ClassMember member) {
// Static members should be copied over as needed by [_copyStaticMembers].
// Otherwise, fields which are not synthetic have concrete getters/setters
Expand Down Expand Up @@ -493,7 +494,7 @@ String _copyClassMembers(ClassOrMixinDeclaration node) {
return buffer.toString();
}

String _copyStaticMembers(ClassOrMixinDeclaration node) {
String _copyStaticMembers(ClassishDeclaration node) {
final buffer = StringBuffer();
node.members.where(isStaticMember).forEach((member) {
// Don't copy over anything named `meta`, since the static meta field is already going to be generated.
Expand Down
4 changes: 3 additions & 1 deletion lib/src/builder/codegen/component_factory_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class ComponentFactoryProxyGenerator extends BoilerplateDeclarationGenerator {
outputContentsBuffer.writeln(' skipMethods: const [],');
}

outputContentsBuffer..writeln(');')..writeln();
outputContentsBuffer
..writeln(');')
..writeln();
}
}
23 changes: 14 additions & 9 deletions lib/src/builder/codegen/typed_map_impl_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
String _generateConcretePropsOrStateImpl({
String componentFactoryName,
String propKeyNamespace,
List<Identifier> allPropsMixins,
List<String> allPropsMixins,
}) {
if (isProps) {
if (componentFactoryName == null || propKeyNamespace == null) {
Expand All @@ -153,7 +153,9 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
classDeclaration.write('abstract ');
}

classDeclaration..write(_generateImplClassHeader())..write(' {');
classDeclaration
..write(_generateImplClassHeader())
..write(' {');

final propsOrState = isProps ? 'props' : 'state';

Expand Down Expand Up @@ -235,7 +237,9 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
// Component2-specific classes
if (isComponent2) {
// TODO need to remove this workaround once https://github.com/dart-lang/sdk/issues/36217 is fixed get nice dart2js output
buffer..writeln()..writeln('''
buffer
..writeln()
..writeln('''
// Concrete $propsOrState implementation that can be backed by any [Map].
${internalGeneratedMemberDeprecationLine()}class ${names.plainMapImplName}$typeParamsOnClass extends ${names.implName}$typeParamsOnSuper {
// This initializer of `_$propsOrState` to an empty map, as well as the reassignment
Expand Down Expand Up @@ -350,7 +354,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
@override
final Version version;

final List<Identifier> allPropsMixins;
final List<String> allPropsMixins;

_TypedMapImplGenerator.props(ClassComponentDeclaration declaration)
: names = TypedMapNames(declaration.props.either.name.name),
Expand Down Expand Up @@ -434,8 +438,9 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
return 'class ${names.implName}$typeParamsOnClass'
' extends ${isProps ? 'UiProps' : 'UiState'}'
' with\n'
' ${names.consumerName}$typeParamsOnSuper\n,'
' ${names.generatedMixinName}$typeParamsOnSuper${generatedMixinWarningCommentLine(names, isProps: isProps)}';
' ${names.consumerName}$typeParamsOnSuper,\n'
' ${generatedMixinWarningCommentLine(names, isProps: isProps)}'
' ${names.generatedMixinName}$typeParamsOnSuper';
} else if (member is BoilerplatePropsOrState) {
final header = StringBuffer()
..write('class ${names.implName}$typeParamsOnClass'
Expand All @@ -462,14 +467,14 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
final names = TypedMapNames(mixin.name.name);
header.write('${names.consumerName}$typeArguments');
header.write(',');
// Add a space at the beginning of the line so that dartfmt indents it
// with the following line, as opposed to "sticking" it to the beginning of the line.
header.write('\n ' + generatedMixinWarningCommentLine(names, isProps: isProps));
header.write('${names.generatedMixinName}$typeArguments');
// Don't write the comma if we're at the end of the list.
// Do this manually instead of using `.join` so that we can always have
// the warning comment be at the end of the line, regardless of whether the comma is there.
if (i != mixins.length - 1) {
header.write(',');
}
header.write(generatedMixinWarningCommentLine(names, isProps: isProps));
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/src/builder/codegen/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:analyzer/dart/ast/ast.dart';
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:over_react/src/component_declaration/annotations.dart' as annotations;
Expand Down Expand Up @@ -70,7 +69,7 @@ String generatedMixinWarningCommentLine(TypedMapNames mixinNames, {@required boo

void generatePropsMeta(
StringBuffer buffer,
List<Identifier> mixins, {
List<String> mixins, {
String classType = 'PropsMetaCollection',
String fieldName = 'propsMeta',
}) {
Expand All @@ -79,7 +78,7 @@ void generatePropsMeta(
..writeln(' @override')
..writeln(' $classType get $fieldName => const $classType({');
for (final name in mixins) {
final names = TypedMapNames(name.name);
final names = TypedMapNames(name);
buffer.write(' ${generatedMixinWarningCommentLine(names, isProps: true)}');
buffer.writeln(' ${names.consumerName}: ${names.publicGeneratedMetaName},');
}
Expand Down
13 changes: 11 additions & 2 deletions lib/src/builder/parsing/ast_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ extension SuperclassConstraint on MixinDeclaration {
}
}

/// Utilities for determining if a [ClassOrMixinDeclaration] has an abstract getter.
extension AbstractGetter on ClassOrMixinDeclaration {
/// Utilities for determining if a declaration has an abstract getter.
extension AbstractGetter on ClassishDeclaration {
/// Returns whether this class/mixin contains an abstract getter with the provided [name]
/// and a return type exactly matching [type]
bool hasAbstractGetter(String type, String name) =>
Expand All @@ -106,6 +106,15 @@ extension AbstractGetter on ClassOrMixinDeclaration {
member.returnType?.toSource() == type);
}

/// An extension that supports APIs that changed from [Identifier] to [Token],
/// in order to cut down on diffs in the analyzer 5 upgrade (and subsequent
/// merge conflicts with the null-safety branch.
///
/// TODO remove this and inline the [name] member.
extension NameIdentifierTokenCompat on Token {
String get name => lexeme;
}

Comment on lines +109 to +117
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why there aren't more changes to move to .lexeme

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, good trick! So, then after this merges there's follow up work to inline the lexeme according to that TODO a few lines up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, exactly. I figure that can happen either in the null safety branch, or after null safety merges

/// Utilities that provide for easier access to [AnnotatedNode] metadata.
extension MetadataHelper on AnnotatedNode {
// Annotations don't always parse as expected, so `.name` can also include the constructor
Expand Down
54 changes: 27 additions & 27 deletions lib/src/builder/parsing/ast_util/classish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ extension Classish on NamedCompilationUnitMember {
ClassishDeclaration asClassish() => ClassishDeclaration(this);
}

/// Provides a common interface for [ClassOrMixinDeclaration] and [ClassTypeAlias].
/// Provides a common interface for [ClassDeclaration], [MixinDeclaration],
/// and [ClassTypeAlias].
abstract class ClassishDeclaration {
factory ClassishDeclaration(NamedCompilationUnitMember node) {
if (node is ClassDeclaration) {
Expand All @@ -41,17 +42,17 @@ abstract class ClassishDeclaration {
//
// Shared

SimpleIdentifier get name => node.name;
Token get name => node.name;
NodeList<Annotation> get metadata => node.metadata;

TypeParameterList get typeParameters;
List<ClassMember> get members;
Token get classOrMixinKeyword;

/// All interfaces used by this class, including mixin superclass constraints.
List<TypeName> get interfaces;
List<NamedType> get interfaces;

List<TypeName> get allSuperTypes => [
List<NamedType> get allSuperTypes => [
...interfaces,
...mixins,
if (superclass != null) superclass,
Expand All @@ -63,25 +64,12 @@ abstract class ClassishDeclaration {
WithClause get withClause;
Token get abstractKeyword;
bool get hasAbstractKeyword => abstractKeyword != null;
TypeName get superclass;
NamedType get superclass;

List<TypeName> get mixins => withClause?.mixinTypes ?? const [];
List<NamedType> get mixins => withClause?.mixinTypes ?? const [];
}

abstract class _ClassishClassOrMixin extends ClassishDeclaration {
_ClassishClassOrMixin._() : super._();

@override
ClassOrMixinDeclaration get node;

@override
List<ClassMember> get members => node.members;

@override
TypeParameterList get typeParameters => node.typeParameters;
}

class _ClassishClass extends _ClassishClassOrMixin {
class _ClassishClass extends ClassishDeclaration {
@override
final ClassDeclaration node;

Expand All @@ -91,21 +79,27 @@ class _ClassishClass extends _ClassishClassOrMixin {
Token get abstractKeyword => node.abstractKeyword;

@override
List<TypeName> get interfaces => [
List<NamedType> get interfaces => [
...?node.implementsClause?.interfaces,
];

@override
TypeName get superclass => node.extendsClause?.superclass;
NamedType get superclass => node.extendsClause?.superclass;

@override
WithClause get withClause => node.withClause;

@override
Token get classOrMixinKeyword => node.classKeyword;

@override
List<ClassMember> get members => node.members;

@override
TypeParameterList get typeParameters => node.typeParameters;
}

class _ClasssishMixin extends _ClassishClassOrMixin {
class _ClasssishMixin extends ClassishDeclaration {
@override
final MixinDeclaration node;

Expand All @@ -118,16 +112,22 @@ class _ClasssishMixin extends _ClassishClassOrMixin {
Token get classOrMixinKeyword => node.mixinKeyword;

@override
List<TypeName> get interfaces => [
List<NamedType> get interfaces => [
...?node.implementsClause?.interfaces,
...?node.onClause?.superclassConstraints,
];

@override
TypeName get superclass => null;
NamedType get superclass => null;

@override
WithClause get withClause => null;

@override
List<ClassMember> get members => node.members;

@override
TypeParameterList get typeParameters => node.typeParameters;
}

class _ClassishClassTypeAlias extends ClassishDeclaration {
Expand All @@ -146,7 +146,7 @@ class _ClassishClassTypeAlias extends ClassishDeclaration {
List<ClassMember> get members => const [];

@override
TypeName get superclass => node.superclass;
NamedType get superclass => node.superclass;

@override
TypeParameterList get typeParameters => node.typeParameters;
Expand All @@ -155,7 +155,7 @@ class _ClassishClassTypeAlias extends ClassishDeclaration {
WithClause get withClause => node.withClause;

@override
List<TypeName> get interfaces => [
List<NamedType> get interfaces => [
...?node.implementsClause?.interfaces,
];
}
Loading