linter
linter copied to clipboard
Avoid `depend_on_referenced_packages` false positive in colocated test directory
Description
When test files are colocated (in a test/ subdirectory of lib/src/) the depend_on_referenced_packages lint does not consider dev dependencies as part of the file's dependencies and thus gives false positives for all referenced dev dependencies.
fyi @jakemac53
All files under lib are considered public, anybody could import them with a package: import. So this is working as intended. I don't think we want to special case directories called test or anything like that.
I don't think we want to special case directories called
testor anything like that.
The proposal is to use the existing detection for test directories (see the PR code), not a special case for directories called "test/".
All files under
libare considered public, anybody could import them with apackage:import.
I opened an issue a while back to suggest a lint to avoid this issue: https://github.com/dart-lang/linter/issues/3289
The proposal is to use the existing detection for test directories (see the PR code), not a special case for directories called "test/".
That detection looks very permissive and is probably designed for a different use case.
For instance, one strategy I have seen is to create a testing directory under lib with actually intentional shared helper code for writing tests (generated mocks, etc). In that case it is important for the dependencies of those libraries to be real dependencies.
Creating files under lib which import packages that are not regular dependencies will also break build_runner, because it expects to be able to compile all of lib.
In general, we expect published packages to use the package layout conventions, and for good reason imo.
I opened an issue a while back to suggest a lint to avoid this issue: #3289
That doesn't really avoid the issue, not everybody uses the linter (or would have that lint enabled), and it also doesn't allow for the valid use case of a testing directory under lib which contains test helper code. It also wouldn't fix things like build_runner that expect packages to have a certain layout.
I agree. (Sorry for the delay.) I think we can only support the package conventions laid out by convention. I'll close this for now.