-
Notifications
You must be signed in to change notification settings - Fork 57
CPLAT-11143 Emit a build error for mismatched components in the new boilerplate #496
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b1dc74b
Emit build errors for most new boilerplate components that aren't gro…
greglittlefield-wf a016add
Tidy up error message punctuation
greglittlefield-wf b187a29
Add additional info in assert message
greglittlefield-wf 2a1adf4
Improve code comment
greglittlefield-wf 85c7073
Fix regex
greglittlefield-wf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,12 +382,9 @@ class _BoilerplateMemberDetector { | |
| // Thus, it's non-legacy boilerplate. | ||
|
|
||
| VersionConfidences getConfidence() { | ||
| final overridesIsClassGenerated = classish.members | ||
| .whereType<MethodDeclaration>() | ||
| .any((member) => member.isGetter && member.name.name == r'$isClassGenerated'); | ||
| // Handle classes that look like props but are really just used as interfaces, and aren't extended from or directly used as a component's props. | ||
| // Watch out for empty mixins, though; those are valid props/state mixins. | ||
| if (overridesIsClassGenerated || | ||
| if (_overridesIsClassGenerated(classish) || | ||
| (node is! MixinDeclaration && onlyImplementsThings(classish))) { | ||
| return VersionConfidences.none(); | ||
| } else if (classish.members.whereType<ConstructorDeclaration>().isNotEmpty) { | ||
|
|
@@ -429,26 +426,54 @@ class _BoilerplateMemberDetector { | |
| return false; | ||
| } | ||
|
|
||
| /// UiComponent, UiComponent2, UiStatefulComponent, FluxUiComponent, CustomUiComponent, ... | ||
| static final _componentBaseClassPattern = RegExp(r'Ui\w*Component'); | ||
|
|
||
| bool _detectPotentialComponent(ClassishDeclaration classish) { | ||
| // Don't detect react-dart components as boilerplate components, since they cause issues with grouping | ||
| // if they're in the same file as an OverReact component with non-matching names. | ||
| if (!const {'Component', 'Component2'}.contains(classish.superclass?.nameWithoutPrefix)) { | ||
| if (classish.name.name.endsWith('Component') || | ||
| classish.allSuperTypes | ||
| .map((t) => t.typeNameWithoutPrefix) | ||
| .any(const {'UiComponent', 'UiComponent2'}.contains) || | ||
| .any(_componentBaseClassPattern.hasMatch) || | ||
| (classish.superclass?.typeArguments?.arguments | ||
| ?.map((t) => t.typeNameWithoutPrefix) | ||
| ?.any(propsOrMixinNamePattern.hasMatch) ?? | ||
| false)) { | ||
| onComponent(BoilerplateComponent(classish, VersionConfidences.all(Confidence.neutral))); | ||
| const mixinBoilerplateBaseClasses = { | ||
| 'UiComponent2', | ||
| 'UiStatefulComponent2', | ||
| 'FluxUiComponent2', | ||
| 'FluxUiStatefulComponent2' | ||
| }; | ||
| final confidences = VersionConfidences( | ||
| // If the component extends from a base class known to be supported by the new boilerplate, | ||
| // has no annotation, is not abstract, and does not have $isClassGenerated, then it's | ||
| // most likely intended to be part of a new boilerplate class component declaration. | ||
| // | ||
| // Make this `likely` so that components that don't get associated with factory/props | ||
| // due to naming issues aren't silently ignored. | ||
| v4_mixinBased: !classish.hasAbstractKeyword && | ||
| !_overridesIsClassGenerated(classish) && | ||
| mixinBoilerplateBaseClasses.contains(classish.superclass?.nameWithoutPrefix) | ||
| ? Confidence.likely | ||
| : Confidence.neutral, | ||
| v2_legacyBackwardsCompat: Confidence.neutral, | ||
| v3_legacyDart2Only: Confidence.neutral, | ||
|
Comment on lines
+450
to
+463
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really cool
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I'm super happy that the confidence approach made this kind of change easy |
||
| ); | ||
| onComponent(BoilerplateComponent(classish, confidences)); | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| static bool _overridesIsClassGenerated(ClassishDeclaration classish) => classish.members | ||
| .whereType<MethodDeclaration>() | ||
| .any((member) => member.isGetter && member.name.name == r'$isClassGenerated'); | ||
| } | ||
|
|
||
| class _BoilerplateMemberDetectorVisitor extends SimpleAstVisitor<void> { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.