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

Dart: ignore internal warning related to visibleForTesting usage #1644

Conversation

pwrobeldev
Copy link
Contributor

----- Motivation -----
In order to allow users to mock static functions in classes the 'prototype'
approach was implemented in the past. It uses prototype class to redirect
static function calls.

A class with '$Impl' suffix is created as a prototype. It is annotated as
'visibleForTesting' and exported from the library.

The user may provide its own implementation in tests and this way redirect
the calls to the mock (after setting it as prototype).

Sadly, when a class is derived from the class, which has static methods, then
its '$Impl' derives from the '$Impl' of base class. This leads to linter warnings:
'invalid_use_of_visible_for_testing_member'.

----- Implemented solution -----
This change adds a comment, which disables linter warnings for derived '$Impl'
classes to remove the mentioned warnings from the generated code.

----- Motivation -----
In order to allow users to mock static functions in classes
the 'prototype' approach was implemented in the past. It uses
prototype class to redirect static function calls.

A class with '$Impl' suffix is created as a prototype. It is
annotated as 'visibleForTesting' and exported from the library.

The user may provide its own implementation in tests and this
way redirect the calls to the mock (after setting it as prototype).

Sadly, when a class is derived from the class, which has static
methods, then its '$Impl' derives from the '$Impl' of base class.
This leads to linter warnings: 'invalid_use_of_visible_for_testing_member'.

----- Implemented solution -----
This change adds a comment, which disables linter warnings for derived '$Impl'
classes to remove the mentioned warnings from the generated code.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev merged commit 2528ae3 into master Jan 13, 2025
17 checks passed
@pwrobeldev pwrobeldev deleted the pwrobeldev/ignore-visibleForTesting-warning-in-case-of-inheritance branch January 13, 2025 13:01
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

Successfully merging this pull request may close these issues.

2 participants