Skip to content

Add a lint to check for conditional imports/exports on legacy web libraries #61875

Closed

Description

@srujzs

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.

Activity

  1. added
    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
    on Oct 30, 2025
  2. kevmoo commented on Oct 30, 2025

    @kevmoo
    Member

    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!

  3. bwilkerson commented on Oct 30, 2025

    @bwilkerson
    Member

    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:

    @deprecated
    library;
    

    Is that what it means?

  4. added
    devexp-linterIssues with the analyzer's support for the linter package
    on Oct 30, 2025
  5. kevmoo commented on Oct 30, 2025

    @kevmoo
    Member

    @bwilkerson – YEP!

    Image
  6. srujzs commented on Oct 30, 2025

    @srujzs
    ContributorAuthor

    Yeah, I like the idea of making this true for deprecated libraries in general to future-proof.

  7. bwilkerson commented on Oct 30, 2025

    @bwilkerson
    Member

    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.

  8. kevmoo commented on Oct 30, 2025

    @kevmoo
    Member

    I'll take a warning! Please!

  9. FMorschel commented on Oct 30, 2025

    @FMorschel
    Contributor

    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.

  10. kevmoo commented on Oct 30, 2025

    @kevmoo
    Member

    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

  11. kevmoo commented on Oct 30, 2025

    @kevmoo
    Member
  12. srujzs commented on Oct 30, 2025

    @srujzs
    ContributorAuthor

    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'.

  13. FMorschel commented on Oct 30, 2025

    @FMorschel
    Contributor

    Oh I see. Thanks for clarifying!

  14. bwilkerson commented on Oct 31, 2025

    @bwilkerson
    Member

    Ah, now I know what dart.library.html is.

    No we don't have warnings for those, but we should.

  15. 14 remaining items

  16. srujzs commented on Mar 19, 2026

    @srujzs
    ContributorAuthor

    Summarizing from offline:

    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.

  17. bwilkerson commented on Mar 19, 2026

    @bwilkerson
    Member

    What's the timeframe for getting better variables to use?

  18. srujzs commented on Mar 19, 2026

    @srujzs
    ContributorAuthor

    #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.

  19. srawlins commented on Mar 25, 2026

    @srawlins
    Member

    @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 😅 .

    From this failure:

    • 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.

  20. srujzs commented on Mar 25, 2026

    @srujzs
    ContributorAuthor

    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?

  21. srawlins commented on Mar 25, 2026

    @srawlins
    Member

    I think it's a fine name, but I'll get a +1 on the Gerrit review first, just in case.

  22. srawlins commented on Mar 30, 2026

    @srawlins
    Member

    @srujzs , @bwilkerson approves of the name, so we can move forward.

  23. srujzs commented on Mar 30, 2026

    @srujzs
    ContributorAuthor

    Sounds good, I have flutter/flutter#184130 out for review.

  24. added a commit that references this issue on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-warningIssues with the analyzer's Warning codestype-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions