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

Please add // ignore_for_file: unnecessary_overrides to generated files or do not generate toString() overrides #461

Closed
idrats opened this issue Aug 3, 2021 · 7 comments
Assignees

Comments

@idrats
Copy link

idrats commented Aug 3, 2021

Because

  @override
  String toString() => super.toString();

is not allowed by strict analyser options

@srawlins
Copy link
Member

srawlins commented Aug 3, 2021

Thanks for the report. Can you please include:

  • your mockito version (I thought this was fixed in mockito 5.0.12)
  • the class on which this override was found

@brizaldi
Copy link

Hi, I'm currently using mockito: ^5.0.14 this issue still appears.

my_test.dart

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:mockito/annotations.dart';

import 'my_test.mocks.dart';

@GenerateMocks([Connectivity])
void main() {
  final mockConnectivity = MockConnectivity();
}

my_test_mocks.dart

// Mocks generated by Mockito 5.0.14 from annotations
// in wallpaper_app/test/extra/network/my_test.dart.
// Do not manually edit this file.

import 'dart:async' as _i3;

import 'package:connectivity_plus/connectivity_plus.dart' as _i2;
import 'package:connectivity_plus_platform_interface/connectivity_plus_platform_interface.dart'
    as _i4;
import 'package:mockito/mockito.dart' as _i1;

// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis

/// A class which mocks [Connectivity].
///
/// See the documentation for Mockito's code generation for more information.
class MockConnectivity extends _i1.Mock implements _i2.Connectivity {
  MockConnectivity() {
    _i1.throwOnMissingStub(this);
  }

  @override
  _i3.Stream<_i4.ConnectivityResult> get onConnectivityChanged =>
      (super.noSuchMethod(Invocation.getter(#onConnectivityChanged),
              returnValue: Stream<_i4.ConnectivityResult>.empty())
          as _i3.Stream<_i4.ConnectivityResult>);
  @override
  _i3.Future<_i4.ConnectivityResult> checkConnectivity() => (super.noSuchMethod(
          Invocation.method(#checkConnectivity, []),
          returnValue:
              Future<_i4.ConnectivityResult>.value(_i4.ConnectivityResult.wifi))
      as _i3.Future<_i4.ConnectivityResult>);
  @override
  String toString() => super.toString();
}

@Fox32
Copy link

Fox32 commented Aug 18, 2021

Maybe important to note, this is related to the recommended lints from the lints package.

@acoutts
Copy link

acoutts commented Aug 20, 2021

Same thing but please add an ignore for implementation_imports as well - it also complains when using the lints package.

@srawlins srawlins self-assigned this Sep 22, 2021
@srawlins
Copy link
Member

Sorry for the delay and thanks for the repro. I can reproduce.

@acoutts
Copy link

acoutts commented Sep 22, 2021

Alternatively I've found a better workaround for my project. Instead I just added this to my analysis_options.yaml file:

include: package:lints/recommended.yaml

analyzer:
  exclude:
    - "**/*.mocks.dart"

Then there will be no lint errors in any of the generated mock files.

@srawlins
Copy link
Member

Dart 2.16 has support for ignoring all lint errors in a file which mockito takes advantage of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants