Skip to content

Commit

Permalink
Replace mockito with mocktail
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcegraph committed Apr 25, 2024
1 parent 0c235dd commit c211133
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lib/src/creator_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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')
: '') +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ClassComponentRequiredDefaultPropsMigrator
Future<void> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ class RequiredFluxProps extends RecursiveAstVisitor with ClassSuggestor {

final cascadingAssignments =
node.cascadeSections.whereType<AssignmentExpression>();
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';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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*/');
}
2 changes: 1 addition & 1 deletion lib/src/executables/intl_message_migration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,6 @@ List<String> limitPaths(List<String> 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
];
4 changes: 2 additions & 2 deletions lib/src/intl_suggestors/intl_importer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Stream<Patch> 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;

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/intl_suggestors/intl_migrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/intl_suggestors/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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 &&
Expand Down
10 changes: 5 additions & 5 deletions lib/src/mui_suggestors/components/mui_button_migrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssignmentExpression>().map((e) {
Expand All @@ -48,15 +48,15 @@ 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) =>
const {
'Button',
'FormSubmitInput',
'FormResetInput',
}.any((wsdFactory) => usesWsdFactory(usage, wsdFactory)) &&
}.any()((wsdFactory) => usesWsdFactory(usage, wsdFactory)) &&
!usesWsdToolbarFactory(usage) &&
!isLikelyAssignedToButtonAddonProp(usage);

Expand Down Expand Up @@ -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<BooleanLiteral>()?.value == true)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/react16_suggestors/react16_utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/rmui_preparation_suggestors/dart_script_adder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DartScriptAdder extends RecursiveAstVisitor<void>
}
} 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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/component_usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/component_usage_migrator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/element_type_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/util/get_all_props.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ List<FieldElement> 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 [];
}
Expand All @@ -68,9 +68,9 @@ List<FieldElement> 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;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/util/get_all_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ List<FieldElement> 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 [];
}
Expand All @@ -66,9 +66,9 @@ List<FieldElement> 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;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/util/ignore_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/importer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/package_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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());
2 changes: 1 addition & 1 deletion lib/src/util/wsd_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c211133

Please sign in to comment.