From c211133380f97c4352f5d3d37438cc738790117a Mon Sep 17 00:00:00 2001 From: Sourcegraph Date: Thu, 25 Apr 2024 20:15:05 +0000 Subject: [PATCH] Replace mockito with mocktail --- lib/src/creator_utils.dart | 4 ++-- .../class_component_required_default_props.dart | 2 +- .../null_safety_prep/required_flux_props.dart | 4 ++-- .../null_safety_prep/utils/hint_detection.dart | 2 +- lib/src/executables/intl_message_migration.dart | 2 +- lib/src/intl_suggestors/intl_importer.dart | 4 ++-- lib/src/intl_suggestors/intl_migrator.dart | 4 ++-- lib/src/intl_suggestors/utils.dart | 4 ++-- .../mui_suggestors/components/mui_button_migrator.dart | 10 +++++----- .../components/mui_inline_alert_migrator.dart | 2 +- lib/src/react16_suggestors/react16_utilities.dart | 2 +- .../rmui_preparation_suggestors/dart_script_adder.dart | 2 +- lib/src/util/component_usage.dart | 2 +- lib/src/util/component_usage_migrator.dart | 2 +- lib/src/util/element_type_helpers.dart | 2 +- lib/src/util/get_all_props.dart | 6 +++--- lib/src/util/get_all_state.dart | 6 +++--- lib/src/util/ignore_info.dart | 4 ++-- lib/src/util/importer.dart | 2 +- lib/src/util/package_util.dart | 2 +- lib/src/util/wsd_util.dart | 2 +- pubspec.yaml | 2 +- 22 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/src/creator_utils.dart b/lib/src/creator_utils.dart index d4487bc6..bb0721ad 100644 --- a/lib/src/creator_utils.dart +++ b/lib/src/creator_utils.dart @@ -85,11 +85,11 @@ class PubspecCreator { .where((dep) => !(dep.asDev || dep.asOverride)) .join('\n') : '') + - (dependencies.any((dep) => dep.asDev) + (dependencies.any()((dep) => dep.asDev) ? '\ndev_dependencies: \n' + dependencies.where((dep) => dep.asDev).join('\n') : '') + - (dependencies.any((dep) => dep.asOverride) + (dependencies.any()((dep) => dep.asOverride) ? '\ndependency_overrides: \n' + dependencies.where((dep) => dep.asOverride).join('\n') : '') + diff --git a/lib/src/dart3_suggestors/null_safety_prep/class_component_required_default_props.dart b/lib/src/dart3_suggestors/null_safety_prep/class_component_required_default_props.dart index e3f9c425..3e67fcdd 100644 --- a/lib/src/dart3_suggestors/null_safety_prep/class_component_required_default_props.dart +++ b/lib/src/dart3_suggestors/null_safety_prep/class_component_required_default_props.dart @@ -83,7 +83,7 @@ class ClassComponentRequiredDefaultPropsMigrator Future visitCascadeExpression(CascadeExpression node) async { super.visitCascadeExpression(node); - final isDefaultProps = node.ancestors.any((ancestor) { + final isDefaultProps = node.ancestors.any()((ancestor) { if (ancestor is MethodDeclaration) { return [relevantGetterName, relevantMethodName] .contains(ancestor.declaredElement?.name); diff --git a/lib/src/dart3_suggestors/null_safety_prep/required_flux_props.dart b/lib/src/dart3_suggestors/null_safety_prep/required_flux_props.dart index 30108b0a..829d9048 100644 --- a/lib/src/dart3_suggestors/null_safety_prep/required_flux_props.dart +++ b/lib/src/dart3_suggestors/null_safety_prep/required_flux_props.dart @@ -75,11 +75,11 @@ class RequiredFluxProps extends RecursiveAstVisitor with ClassSuggestor { final cascadingAssignments = node.cascadeSections.whereType(); - var storeAssigned = cascadingAssignments.any((cascade) { + var storeAssigned = cascadingAssignments.any()((cascade) { final lhs = cascade.leftHandSide; return lhs is PropertyAccess && lhs.propertyName.name == 'store'; }); - var actionsAssigned = cascadingAssignments.any((cascade) { + var actionsAssigned = cascadingAssignments.any()((cascade) { final lhs = cascade.leftHandSide; return lhs is PropertyAccess && lhs.propertyName.name == 'actions'; }); diff --git a/lib/src/dart3_suggestors/null_safety_prep/utils/hint_detection.dart b/lib/src/dart3_suggestors/null_safety_prep/utils/hint_detection.dart index f8a82a0e..552aa266 100644 --- a/lib/src/dart3_suggestors/null_safety_prep/utils/hint_detection.dart +++ b/lib/src/dart3_suggestors/null_safety_prep/utils/hint_detection.dart @@ -38,5 +38,5 @@ bool requiredHintAlreadyExists(TypeAnnotation type) { // Since the `/*late*/` comment is possibly adjacent to the prop declaration's doc comments, // we have to recursively traverse the `precedingComments` in order to determine if the `/*late*/` // comment actually exists. - return allComments(type.beginToken).any((t) => t.value() == '/*late*/'); + return allComments(type.beginToken).any()((t) => t.value() == '/*late*/'); } diff --git a/lib/src/executables/intl_message_migration.dart b/lib/src/executables/intl_message_migration.dart index 9633e4c4..f29aa648 100644 --- a/lib/src/executables/intl_message_migration.dart +++ b/lib/src/executables/intl_message_migration.dart @@ -430,6 +430,6 @@ List limitPaths(List allPaths, [ for (var path in allPaths) if (allowed - .any((included) => included == path || p.isWithin(included, path))) + .any()((included) => included == path || p.isWithin(included, path))) path ]; diff --git a/lib/src/intl_suggestors/intl_importer.dart b/lib/src/intl_suggestors/intl_importer.dart index 636509cf..43df54c8 100644 --- a/lib/src/intl_suggestors/intl_importer.dart +++ b/lib/src/intl_suggestors/intl_importer.dart @@ -37,7 +37,7 @@ Stream intlImporter( final needsIntlImport = libraryResult.units .expand((unitResult) => unitResult.errors) .where((error) => error.errorCode.name == 'UNDEFINED_IDENTIFIER') - .any((error) => error.message.contains("Undefined name '$className'")); + .any()((error) => error.message.contains("Undefined name '$className'")); if (!needsIntlImport) return; @@ -144,7 +144,7 @@ _InsertionLocation _insertionLocationForPackageImport( trailingNewlineCount: 2, usePackageImports: true); } - hasOnlyPackageImports = !imports.any((importDirective) { + hasOnlyPackageImports = !imports.any()((importDirective) { final uriContent = importDirective.uri.stringValue; if (uriContent != null) { final uri = Uri.parse(uriContent); diff --git a/lib/src/intl_suggestors/intl_migrator.dart b/lib/src/intl_suggestors/intl_migrator.dart index bd2b3ee0..bce0a85a 100644 --- a/lib/src/intl_suggestors/intl_migrator.dart +++ b/lib/src/intl_suggestors/intl_migrator.dart @@ -182,10 +182,10 @@ class IntlMigrator extends ComponentUsageMigrator { if (isStatementIgnored(usage.node)) return false; if (isFileIgnored(this.context.sourceText)) return false; - return usage.cascadedProps.any((prop) => + return usage.cascadedProps.any()((prop) => isValidStringLiteralProp(prop) || isValidStringInterpolationProp(prop)) || - usage.children.any((child) => + usage.children.any()((child) => isValidStringLiteralNode(child.node) || isValidStringInterpolationNode(child.node)); } diff --git a/lib/src/intl_suggestors/utils.dart b/lib/src/intl_suggestors/utils.dart index 70778c71..4b8a8ecb 100644 --- a/lib/src/intl_suggestors/utils.dart +++ b/lib/src/intl_suggestors/utils.dart @@ -296,7 +296,7 @@ extension ElementSubtypeUtils on Element /*?*/ { final that = this; return that is InterfaceElement && (that.isTypeFromPackage(typeName, packageName, packageType) || - that.allSupertypes.any((type) => type.element + that.allSupertypes.any()((type) => type.element .isTypeFromPackage(typeName, packageName, packageType))); } @@ -341,7 +341,7 @@ bool hasIgnoreComment(Token token, {int limit = 128}) { var comments = token.precedingComments; if (comments != null && - (_allComments(comments).any((line) => line.contains(ignoreStatement)))) { + (_allComments(comments).any()((line) => line.contains(ignoreStatement)))) { return true; } else { return token.previous != null && diff --git a/lib/src/mui_suggestors/components/mui_button_migrator.dart b/lib/src/mui_suggestors/components/mui_button_migrator.dart index 6f12710b..a1b6993a 100644 --- a/lib/src/mui_suggestors/components/mui_button_migrator.dart +++ b/lib/src/mui_suggestors/components/mui_button_migrator.dart @@ -33,10 +33,10 @@ class MuiButtonMigrator extends ComponentUsageMigrator with MuiMigrator, ButtonDisplayPropsMigrator { static bool hasLinkButtonSkin(FluentComponentUsage usage) => usage .cascadedProps - .any((p) => p.name.name == 'skin' && isLinkButtonSkin(p.rightHandSide)); + .any()((p) => p.name.name == 'skin' && isLinkButtonSkin(p.rightHandSide)); static bool isLinkButtonSkin(Expression expr) => - _linkButtonSkins.any((linkSkin) => isWsdStaticConstant(expr, linkSkin)); + _linkButtonSkins.any()((linkSkin) => isWsdStaticConstant(expr, linkSkin)); static bool isLikelyAssignedToButtonAddonProp(FluentComponentUsage usage) => usage.node.ancestors.whereType().map((e) { @@ -48,7 +48,7 @@ class MuiButtonMigrator extends ComponentUsageMigrator // Use variable.name since PropertyAccessorElement's name has a trailing `=` ? writeElement.variable.name : writeElement.name; - }).any(const {'buttonBefore', 'buttonAfter'}.contains); + }).any()(const {'buttonBefore', 'buttonAfter'}.contains); @override bool shouldMigrateUsage(FluentComponentUsage usage) => @@ -56,7 +56,7 @@ class MuiButtonMigrator extends ComponentUsageMigrator 'Button', 'FormSubmitInput', 'FormResetInput', - }.any((wsdFactory) => usesWsdFactory(usage, wsdFactory)) && + }.any()((wsdFactory) => usesWsdFactory(usage, wsdFactory)) && !usesWsdToolbarFactory(usage) && !isLikelyAssignedToButtonAddonProp(usage); @@ -277,7 +277,7 @@ class MuiButtonMigrator extends ComponentUsageMigrator // If it's a single child or `noText = true`, no moving is needed. if (usage.children.length == 1 || - usage.cascadedProps.any((p) => + usage.cascadedProps.any()((p) => p.name.name == 'noText' && p.rightHandSide.tryCast()?.value == true)) { return; diff --git a/lib/src/mui_suggestors/components/mui_inline_alert_migrator.dart b/lib/src/mui_suggestors/components/mui_inline_alert_migrator.dart index e52003d3..005cb757 100644 --- a/lib/src/mui_suggestors/components/mui_inline_alert_migrator.dart +++ b/lib/src/mui_suggestors/components/mui_inline_alert_migrator.dart @@ -41,7 +41,7 @@ class MuiInlineAlertMigrator extends ComponentUsageMigrator // If the alert has props related to the `toast` variant, don't try to // migrate it. !usage.cascadedProps - .any((prop) => toastAlertProps.contains(prop.name.name)); + .any()((prop) => toastAlertProps.contains(prop.name.name)); @override void migrateUsage(FluentComponentUsage usage) { diff --git a/lib/src/react16_suggestors/react16_utilities.dart b/lib/src/react16_suggestors/react16_utilities.dart index 15077fe7..dc7ceb82 100644 --- a/lib/src/react16_suggestors/react16_utilities.dart +++ b/lib/src/react16_suggestors/react16_utilities.dart @@ -76,7 +76,7 @@ bool hasMultilineDocComment( for (var i = 0; i < commentLines.length; i++) { final potentialMatch = commentLines[i]; - if (nodeComments.any((line) => line == potentialMatch)) { + if (nodeComments.any()((line) => line == potentialMatch)) { match = true; break; } diff --git a/lib/src/rmui_preparation_suggestors/dart_script_adder.dart b/lib/src/rmui_preparation_suggestors/dart_script_adder.dart index 4bdaaa06..54d9ad48 100644 --- a/lib/src/rmui_preparation_suggestors/dart_script_adder.dart +++ b/lib/src/rmui_preparation_suggestors/dart_script_adder.dart @@ -67,7 +67,7 @@ class DartScriptAdder extends RecursiveAstVisitor } } else if (parent is ListLiteral) { // Do not add the script to the list if it is already there. - if (parent.elements.any((element) => + if (parent.elements.any()((element) => element is SimpleStringLiteral && scriptToAdd.pattern.hasMatch(element.literal.lexeme))) { return; diff --git a/lib/src/util/component_usage.dart b/lib/src/util/component_usage.dart index 0a1f4c6f..4ad2a5a4 100644 --- a/lib/src/util/component_usage.dart +++ b/lib/src/util/component_usage.dart @@ -201,7 +201,7 @@ class FluentComponentUsage { ]; final allUnhandledMembers = cascadeSections - .where((section) => !allHandledMembers.any((m) => m.node == section)) + .where((section) => !allHandledMembers.any()((m) => m.node == section)) .map((section) => OtherBuilderMemberAccess(section)) .toList(); diff --git a/lib/src/util/component_usage_migrator.dart b/lib/src/util/component_usage_migrator.dart index f2debcdf..123f6fbf 100644 --- a/lib/src/util/component_usage_migrator.dart +++ b/lib/src/util/component_usage_migrator.dart @@ -627,7 +627,7 @@ abstract class ComponentUsageMigrator with ClassSuggestor { if (componentName != null) componentName, if (propsName != null) propsName, ]; - return codes.any((code) => ignoreInfo.ignoredAt(code, line)); + return codes.any()((code) => ignoreInfo.ignoredAt(code, line)); } } diff --git a/lib/src/util/element_type_helpers.dart b/lib/src/util/element_type_helpers.dart index 00d7c7ca..bf2b459a 100644 --- a/lib/src/util/element_type_helpers.dart +++ b/lib/src/util/element_type_helpers.dart @@ -27,7 +27,7 @@ extension TypeHelpers on DartType { final element = typeOrBound.element; return element is InterfaceElement && (element.isElementFromPackage(typeName, packageName) || - element.allSupertypes.any((type) => + element.allSupertypes.any()((type) => type.element.isElementFromPackage(typeName, packageName))); } } diff --git a/lib/src/util/get_all_props.dart b/lib/src/util/get_all_props.dart index 80ee8df2..8a643c81 100644 --- a/lib/src/util/get_all_props.dart +++ b/lib/src/util/get_all_props.dart @@ -47,7 +47,7 @@ List getAllProps(InterfaceElement propsElement) { // This check is only necessary to retrieve props when [propsElement] is itself a legacy mixin, and not when legacy // props mixins are encountered below as supertypes. final inheritsFromUiProps = uiPropsElement != null; - late final isPropsMixin = propsElement.metadata.any(_isPropsMixinAnnotation); + late final isPropsMixin = propsElement.metadata.any()(_isPropsMixinAnnotation); if (!inheritsFromUiProps && !isPropsMixin) { return []; } @@ -68,9 +68,9 @@ List getAllProps(InterfaceElement propsElement) { } final isMixinBasedPropsMixin = interface is MixinElement && - interface.superclassConstraints.any((s) => s.element.name == 'UiProps'); + interface.superclassConstraints.any()((s) => s.element.name == 'UiProps'); late final isLegacyPropsOrPropsMixinConsumerClass = !isFromGeneratedFile && - interface.metadata.any(_isPropsOrPropsMixinAnnotation); + interface.metadata.any()(_isPropsOrPropsMixinAnnotation); if (!isMixinBasedPropsMixin && !isLegacyPropsOrPropsMixinConsumerClass) { continue; diff --git a/lib/src/util/get_all_state.dart b/lib/src/util/get_all_state.dart index 51449ebc..74f9a2dc 100644 --- a/lib/src/util/get_all_state.dart +++ b/lib/src/util/get_all_state.dart @@ -46,7 +46,7 @@ List getAllState(InterfaceElement stateElement) { // This check is only necessary to retrieve props when [stateElement] is itself a legacy mixin, and not when legacy // props mixins are encountered below as supertypes. final inheritsFromUiState = uiStateElement != null; - late final isStateMixin = stateElement.metadata.any(_isStateMixinAnnotation); + late final isStateMixin = stateElement.metadata.any()(_isStateMixinAnnotation); if (!inheritsFromUiState && !isStateMixin) { return []; } @@ -66,9 +66,9 @@ List getAllState(InterfaceElement stateElement) { } final isMixinBasedPropsMixin = interface is MixinElement && - interface.superclassConstraints.any((s) => s.element.name == 'UiState'); + interface.superclassConstraints.any()((s) => s.element.name == 'UiState'); late final isLegacyStateOrStateMixinConsumerClass = !isFromGeneratedFile && - interface.metadata.any(_isStateOrStateMixinAnnotation); + interface.metadata.any()(_isStateOrStateMixinAnnotation); if (!isMixinBasedPropsMixin && !isLegacyStateOrStateMixinConsumerClass) { continue; diff --git a/lib/src/util/ignore_info.dart b/lib/src/util/ignore_info.dart index 0e8343e7..d6521a75 100644 --- a/lib/src/util/ignore_info.dart +++ b/lib/src/util/ignore_info.dart @@ -93,11 +93,11 @@ class OrcmIgnoreInfo { /// Whether the [code] is ignored at the given [line]. bool ignoredAt(String code, int line) => - _ignoresForLine(line).any((ignore) => ignore.ignoresCode(code)); + _ignoresForLine(line).any()((ignore) => ignore.ignoresCode(code)); /// Whether all codes is ignored at the given [line]. bool allCodesIgnoredAt(int line) => - _ignoresForLine(line).any((ignore) => ignore.ignoresAllCodes); + _ignoresForLine(line).any()((ignore) => ignore.ignoresAllCodes); } /// An ignore for either a single code or for all codes. diff --git a/lib/src/util/importer.dart b/lib/src/util/importer.dart index 954754b6..13e36249 100644 --- a/lib/src/util/importer.dart +++ b/lib/src/util/importer.dart @@ -46,7 +46,7 @@ Suggestor importerSuggestorBuilder({ final needsImport = libraryResult.units .expand((unitResult) => unitResult.errors) .where((error) => error.errorCode.name == 'UNDEFINED_IDENTIFIER') - .any((error) => + .any()((error) => error.message.contains("Undefined name '$importNamespace'")); if (!needsImport) return; diff --git a/lib/src/util/package_util.dart b/lib/src/util/package_util.dart index c0728733..2c79005a 100644 --- a/lib/src/util/package_util.dart +++ b/lib/src/util/package_util.dart @@ -130,6 +130,6 @@ bool isNotWithinTopLevelToolDir(File file) => /// Returns whether [file] is within a top-level [topLevelDir] directory /// (e.g., `bin`, `lib`, `web`) of a package root. bool isWithinTopLevelDir(File file, String topLevelDir) => - ancestorsOfPath(file.path).any((ancestor) => + ancestorsOfPath(file.path).any()((ancestor) => p.basename(ancestor) == topLevelDir && File(p.join(p.dirname(ancestor), 'pubspec.yaml')).existsSync()); diff --git a/lib/src/util/wsd_util.dart b/lib/src/util/wsd_util.dart index 8f18cd10..a2d95d49 100644 --- a/lib/src/util/wsd_util.dart +++ b/lib/src/util/wsd_util.dart @@ -158,7 +158,7 @@ bool usesWsdToolbarFactory(FluentComponentUsage usage) { // isDeclaredInWsd implies non-null source final uri = factoryElement.source!.uri; - return _wsdToolbarPathPatterns.any(uri.path.contains); + return _wsdToolbarPathPatterns.any()(uri.path.contains); } final _isValidSimpleIdentifier = RegExp(r'^[_$a-zA-Z][_$a-zA-Z0-9]*$').hasMatch; diff --git a/pubspec.yaml b/pubspec.yaml index d3550c91..74cb468c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,7 @@ dev_dependencies: build_test: ^2.1.3 dart_style: ^2.0.3 dependency_validator: ^3.1.2 - mockito: ^5.0.14 + mocktail: ^1.0.3 test: ^1.17.10 test_descriptor: ^2.0.0 uuid: ^3.0.5