You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a lint to check for conditional imports/exports on legacy web libraries #61875
Came up in a convo with @kevmoo, but we should considering adding a lint when users use the legacy web libraries listed in the left nav on https://api.dart.dev/. These libraries are deprecated and may be removed, which would make various code that depends on the conditional break.
The one caveat is we do advise users who are specifically differentiating between JS and Wasm compiles to use dart.library.html, but I still think we should lint there. If users know what they're doing, they can ignore that, but the risk still exists that dart:html will be removed at some point in the future. We should instead expose a robust way to differentiate between JS and Wasm compiles.
Users should use dart.library.js_interop to differentiate between the VM and Web.
We could be more general and just say dart.library.lib_marked_deprecated is linted as a no-no! This would catch all of the (web) libraries we care about!
Sorry, what is dart.library.lib_marked_deprecated?
When I read "These libraries are deprecated" I assumed you meant that they contain an application of the deprecated annotation on the library directive:
I thought we already had a diagnostic when we find an import of a deprecated library, so I'm surprised that we need a lint. If we don't we should, and it should be a warning (that is, not require enabling it) not a lint.
There are some RARE cases where a user might want to detect JS-only (like node) vs browser in which case dart:html is the only option. But for those folks, we can just say ignore the error
I thought we already had a diagnostic when we find an import of a deprecated library, so I'm surprised that we need a lint. If we don't we should, and it should be a warning (that is, not require enabling it) not a lint.
We have lints for an import/export, but not for when the library is used as the conditional e.g. import 'a.dart' if (dart.library.html) 'b.dart'.
Let's lint dart.library.html usages in conditional imports even if it's a valid conditional to differentiate between JS and Wasm compilation, with the caveat that the lint should mention that it's okay if that is the intended use case.
Obviously, this will break whenever we remove the deprecated libraries in the conditional imports. However, that's better than not providing a lint and having users be unaware that their dart.library.html conditional import doesn't actually differentiate between the web and the VM anymore.
When we do have better environment variables here, we can then change the lint message to tell users to use the new environment variables instead.
#54785 is probably a long timeframe, and I don't currently have a timeframe for something localized to these libraries. @kevmoo, should we make that a priority? I assume migrating a bunch of code using lint ignores is not great.
@srujzs , flutter/flutter has a few violations of this new warning. Can you look in these spots and send PRs either changing the import configurations, or adding // ignore comments. One directly references WASM so I don't feel confident I can make the distinction 😅 .
warning - lib/src/engine/renderer.dart:13:9 - 'dart:html' is deprecated and shouldn't be used as an import/export configuration. Try using 'dart.library.js_interop' instead. - deprecated_web_configuration
warning - test/ui/utils.dart:10:9 - 'dart:html' is deprecated and shouldn't be used as an import/export configuration. Try using 'dart.library.js_interop' instead. - deprecated_web_configuration
Each of these is in flutter/flutter, in the engine/src/flutter/lib/web_ui directory.
I think renderer.dart is definitely differentiating between Wasm and JS because it determines whether to use Skwasm or not based on that. The implementation is also using dart:js_interop and dart:_wasm while the stub is using dart:js_interop, so they want dart.library.html intentionally there.
The imports are identical in the utils.dart file as well so it applies there too.
re: Ignores, Flutter will complain about lints that don't exist yet, so I'll need to add another ignore on top of that ignore and then remove it after your CL has landed :). Are we committed to the name "deprecated_web_configuration" for the lint?
Activity
kevmoo commentedon Oct 30, 2025
We could be more general and just say
dart.library.lib_marked_deprecatedis linted as a no-no! This would catch all of the (web) libraries we care about!bwilkerson commentedon Oct 30, 2025
Sorry, what is
dart.library.lib_marked_deprecated?When I read "These libraries are deprecated" I assumed you meant that they contain an application of the
deprecatedannotation on the library directive:Is that what it means?
kevmoo commentedon Oct 30, 2025
@bwilkerson – YEP!
srujzs commentedon Oct 30, 2025
Yeah, I like the idea of making this true for deprecated libraries in general to future-proof.
bwilkerson commentedon Oct 30, 2025
I thought we already had a diagnostic when we find an import of a deprecated library, so I'm surprised that we need a lint. If we don't we should, and it should be a warning (that is, not require enabling it) not a lint.
kevmoo commentedon Oct 30, 2025
I'll take a warning! Please!
FMorschel commentedon Oct 30, 2025
We do have that warning. I mentioned it at #61214 description.
Maybe some case is missing? Like
dart:foo? I've not fully read the issue so take my comment with a grain of salt.kevmoo commentedon Oct 30, 2025
There are some RARE cases where a user might want to detect JS-only (like node) vs browser in which case
dart:htmlis the only option. But for those folks, we can just say ignore the errorkevmoo commentedon Oct 30, 2025
@FMorschel – this is SPECIFICALLY about using
dart.libary.xyzfor conditional imports. https://dart.dev/tools/pub/create-packages#conditionally-importing-and-exporting-library-filessrujzs commentedon Oct 30, 2025
We have lints for an import/export, but not for when the library is used as the conditional e.g.
import 'a.dart' if (dart.library.html) 'b.dart'.FMorschel commentedon Oct 30, 2025
Oh I see. Thanks for clarifying!
bwilkerson commentedon Oct 31, 2025
Ah, now I know what
dart.library.htmlis.No we don't have warnings for those, but we should.
14 remaining items
srujzs commentedon Mar 19, 2026
Summarizing from offline:
Let's lint
dart.library.htmlusages in conditional imports even if it's a valid conditional to differentiate between JS and Wasm compilation, with the caveat that the lint should mention that it's okay if that is the intended use case.Obviously, this will break whenever we remove the deprecated libraries in the conditional imports. However, that's better than not providing a lint and having users be unaware that their
dart.library.htmlconditional import doesn't actually differentiate between the web and the VM anymore.When we do have better environment variables here, we can then change the lint message to tell users to use the new environment variables instead.
bwilkerson commentedon Mar 19, 2026
What's the timeframe for getting better variables to use?
srujzs commentedon Mar 19, 2026
#54785 is probably a long timeframe, and I don't currently have a timeframe for something localized to these libraries. @kevmoo, should we make that a priority? I assume migrating a bunch of code using lint ignores is not great.
srawlins commentedon Mar 25, 2026
@srujzs , flutter/flutter has a few violations of this new warning. Can you look in these spots and send PRs either changing the import configurations, or adding
// ignorecomments. One directly references WASM so I don't feel confident I can make the distinction 😅 .From this failure:
Each of these is in flutter/flutter, in the
engine/src/flutter/lib/web_uidirectory.srujzs commentedon Mar 25, 2026
I think
renderer.dartis definitely differentiating between Wasm and JS because it determines whether to use Skwasm or not based on that. The implementation is also usingdart:js_interopanddart:_wasmwhile the stub is usingdart:js_interop, so they wantdart.library.htmlintentionally there.The imports are identical in the
utils.dartfile as well so it applies there too.re: Ignores, Flutter will complain about lints that don't exist yet, so I'll need to add another ignore on top of that ignore and then remove it after your CL has landed :). Are we committed to the name "deprecated_web_configuration" for the lint?
srawlins commentedon Mar 25, 2026
I think it's a fine name, but I'll get a +1 on the Gerrit review first, just in case.
Ignore incoming deprecated_web_configuration lint
srawlins commentedon Mar 30, 2026
@srujzs , @bwilkerson approves of the name, so we can move forward.
srujzs commentedon Mar 30, 2026
Sounds good, I have flutter/flutter#184130 out for review.
Ignore incoming deprecated_web_configuration lint (#184130)
Ignore incoming deprecated_web_configuration lint (flutter#184130)
[pointer_interceptor] Use dart.library.js_interop in example export (#…
Reference dart-lang/sdk#61464 on deprecated_web_configuration ignores (…
analyzer: New warning for deprecated directive configurations