Skip to content

Enable recent lints for site tooling and implementation - #13845

Open
parlough wants to merge 1 commit into
mainfrom
misc/3-13-new-lints
Open

Enable recent lints for site tooling and implementation#13845
parlough wants to merge 1 commit into
mainfrom
misc/3-13-new-lints

Conversation

@parlough

@parlough parlough commented Sep 2, 2026

Copy link
Copy Markdown
Member
  • Enables some new and some pre-existing lints for site tooling and implementation.
  • Fixes diagnostics reported after enabling those lints.
  • Temporarily enabled some others to address certain cases of them.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the linter rules in analysis.yaml, bumps the SDK version constraint to ^3.13.0, and applies various code cleanups across multiple packages, such as optimizing const usage, simplifying pattern matching, and removing redundant async keywords. The reviewer identified two critical resource leaks: a memory leak in _TooltipState due to an uncancelled window resize event listener, and a file handle leak in TrackingAssetTransformer because the IOSink is never closed.

Comment on lines +34 to +35
bool _isVisible = false;
double _tooltipOffset = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The window resize event listener registered in setupTooltip is never cancelled, which will cause a memory leak. When this state/component is disposed, the listener on the global web.window remains active, keeping a reference to the state and preventing it from being garbage collected.

To fix this, store the StreamSubscription and cancel it in the dispose method:

  1. Add a _resizeSubscription field.
  2. Assign the subscription in setupTooltip:
    _resizeSubscription = web.EventStreamProviders.resizeEvent.forTarget(web.window).listen((_) {
      ensureVisible();
    });
  3. Implement dispose to cancel the subscription:
    @override
    void dispose() {
      _resizeSubscription?.cancel();
      super.dispose();
    }
Suggested change
bool _isVisible = false;
double _tooltipOffset = 0;
bool _isVisible = false;
double _tooltipOffset = 0;
StreamSubscription<web.Event>? _resizeSubscription;

Comment on lines +19 to 21
final IOSink _trackingFile = File(
p.join('tool', 'used_assets.txt'),
).openWrite(mode: FileMode.write);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The _trackingFile IOSink is opened when TrackingAssetTransformer is instantiated but is never closed. This can lead to a resource leak and potential data loss, as some written asset paths might remain in the buffer and not be flushed to the file when the build process exits.

Since AssetTransformer does not have a standard lifecycle method to close resources, a more robust approach is to avoid keeping an open IOSink altogether. Instead, you can clear the file once on initialization and append to it synchronously in the transform method:

class TrackingAssetTransformer implements AssetTransformer {
  TrackingAssetTransformer() {
    File(_trackingPath).writeAsStringSync('');
  }

  static final String _trackingPath = p.join('tool', 'used_assets.txt');

  @override
  Asset transform(Asset asset, [Object? aspect]) {
    File(_trackingPath).writeAsStringSync('\${asset.path}\n', mode: FileMode.append);
    return asset;
  }
}

@flutter-website-bot

Copy link
Copy Markdown
Collaborator

Staged preview of the updated docs.flutter.dev site (updated for commit ab4abb0):

https://flutter-docs-prod--docs-pr13845-misc-3-13-new-lints-h9bynf5e.web.app

@flutter-website-bot

Copy link
Copy Markdown
Collaborator

Staged preview of the updated flutter.dev site (updated for commit ab4abb0):

https://flutter-dev-230821--www-pr13845-misc-3-13-new-lints-amaj0j8n.web.app

@sfshaza2 sfshaza2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

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.

3 participants