Skip to content

✨ Fix: Remove redundant // ignore: must_be_immutable in generated mocks #809

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,6 @@ class _MockClassInfo {
typeAlias?.element2.aliasedType as analyzer.InterfaceType?;
final typeToMock = aliasedType ?? mockTarget.classType;
final classToMock = mockTarget.interfaceElement;
final classIsImmutable = classToMock.metadata.any((it) => it.isImmutable);
final className = aliasedElement?.name3 ?? classToMock.name3;

return Class((cBuilder) {
Expand All @@ -1271,9 +1270,7 @@ class _MockClassInfo {
'/// See the documentation for Mockito\'s code generation '
'for more information.',
);
if (classIsImmutable) {
cBuilder.docs.add('// ignore: must_be_immutable');
}

// For each type parameter on [classToMock], the Mock class needs a type
// parameter with same type variables, and a mirrored type argument for
// the "implements" clause.
Expand Down
14 changes: 0 additions & 14 deletions test/builder/auto_mocks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3784,20 +3784,6 @@ void main() {
);
});

test('adds ignore: must_be_immutable analyzer comment if mocked class is '
'immutable', () async {
await expectSingleNonNullableOutput(
dedent(r'''
import 'package:meta/meta.dart';
@immutable
class Foo {
void foo();
}
'''),
_containsAllOf('// ignore: must_be_immutable\nclass MockFoo'),
);
});

group('typedef mocks', () {
group('are generated properly', () {
test('when aliased type parameters are instantiated', () async {
Expand Down