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

(riverpod_lint) Add new lint avoid_passing_build_context_to_providers #2928

Merged
merged 6 commits into from
Sep 28, 2023
Merged

(riverpod_lint) Add new lint avoid_passing_build_context_to_providers #2928

merged 6 commits into from
Sep 28, 2023

Conversation

charlescyt
Copy link
Contributor

Implement a lint for #2187

@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

Merging #2928 (8d63325) into master (dfe84e0) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2928   +/-   ##
=======================================
  Coverage   95.24%   95.24%           
=======================================
  Files          53       53           
  Lines        2252     2252           
=======================================
  Hits         2145     2145           
  Misses        107      107           

Comment on lines 8 to 9
TypeChecker buildContextType =
const TypeChecker.fromName('BuildContext', packageName: 'flutter');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TypeChecker buildContextType =
const TypeChecker.fromName('BuildContext', packageName: 'flutter');
const buildContextType = TypeChecker.fromName(
'BuildContext',
packageName: 'flutter',
);

Comment on lines 47 to 55
final buildContextParameters = parameters.parameters.where(
(e) =>
e.declaredElement?.type != null &&
buildContextType.isExactlyType(e.declaredElement!.type),
);

for (final contextParameter in buildContextParameters) {
reporter.reportErrorForNode(_code, contextParameter);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be refactored with the functional-based bit to avoid the duplicate?
A function which takes the list of parameter and emit warnings should be fine.

@rrousselGit
Copy link
Owner

Outside of a small DRY thingy, LGTM!

Ah yes, one more thing: I'm not sure about the name picked. It's a bit lengthy.
Maybe we could shorten it up a bit with "avoid_build_context_in_providers"?

@charlescyt
Copy link
Contributor Author

Definitely. I am not good at naming.

@rrousselGit
Copy link
Owner

Perfect. I'll sync with master, check the CI and merge/deploy this

@rrousselGit rrousselGit merged commit 7642120 into rrousselGit:master Sep 28, 2023
@charlescyt charlescyt deleted the avoid_passing_build_context_to_providers branch September 28, 2023 12:30
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