dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
630 stars 170 forks source link

`depend_on_referenced_packages` multi-module Flutter project false positives #5023

Open pvlKryu opened 1 month ago

pvlKryu commented 1 month ago

Page URL

https://dart.dev/tools/linter-rules/depend_on_referenced_packages.html

Page source

https://github.com/dart-lang/site-www/tree/main/src/content/tools/linter-rules/individual-rules.md

Describe the problem

Title: Lint Rule depend_on_referenced_packages Triggers Incorrectly in Multi-Module Flutter Project

Description:

I am encountering an issue with the depend_on_referenced_packages lint rule in a multi-module Flutter project. The linter is flagging imports of packages as not being declared dependencies, despite them being correctly specified in the respective module's pubspec.yaml file.

Steps to Reproduce:

  1. Create a multi-module Flutter project with at least two modules.
  2. Add dependencies any dependencies for example webview_flutter and webview_flutter_android only in one of the module's pubspec.yaml files.
  3. Import these dependencies in a Dart file within that module.
  4. Observe the depend_on_referenced_packages lint error.

Example is on the screenshot 1.

Expected Behavior:

The linter should recognize the dependencies specified in the module's pubspec.yaml file and should not flag imports of these packages.

Actual Behavior:

The linter flags the imports with the error:

The imported package 'webview_flutter' isn't a dependency of the importing package.
The imported package 'webview_flutter_android' isn't a dependency of the importing package.

However, when these dependencies are added to the main pubspec.yaml file, the lint warnings disappear.

Screenshots:

Screenshot 1: Module's pubspec.yaml and imports causing lint error: telegram-cloud-photo-size-2-5244563567506741101-y

Screenshot 2: Main pubspec.yaml resolving the lint error when dependencies are added: telegram-cloud-photo-size-2-5244563567506741104-y

Additional Information:

I have tried clearing the cache, restarting the IDE, and running flutter clean followed by flutter pub get, but the issue persists.

Workaround:

Adding the dependencies to the main pubspec.yaml resolves the lint error, but this should not be necessary if the module's pubspec.yaml is correctly configured.

Request:

Please investigate this issue and provide guidance on how to correctly configure dependencies in a multi-module Flutter project without encountering this lint error.

Thank you!

Contact Information:


Expected fix

No response

Additional context

No response

I would like to fix this problem.

stereotype441 commented 1 month ago

@pq does this issue belong in dart-lang/linter?

dart-github-bot commented 1 month ago

Summary: The depend_on_referenced_packages lint rule incorrectly flags imports in a multi-module Flutter project, even when dependencies are correctly specified in the module's pubspec.yaml. The linter expects dependencies to be listed in the main pubspec.yaml, which is not the expected behavior for multi-module projects.

pq commented 1 month ago

@keertip might have some perspective?

pvlKryu commented 1 month ago

any thoughts? @keertip @pq

pq commented 1 month ago

@keertip: perhaps this is addressed w/ your recent fixes?

srawlins commented 2 weeks ago

Assigning to Keerti for first thoughts.