Enable recent lints for site tooling and implementation - #13845
Conversation
parlough
commented
Sep 2, 2026
- 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.
There was a problem hiding this comment.
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.
| bool _isVisible = false; | ||
| double _tooltipOffset = 0; |
There was a problem hiding this comment.
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:
- Add a
_resizeSubscriptionfield. - Assign the subscription in
setupTooltip:_resizeSubscription = web.EventStreamProviders.resizeEvent.forTarget(web.window).listen((_) { ensureVisible(); });
- Implement
disposeto cancel the subscription:@override void dispose() { _resizeSubscription?.cancel(); super.dispose(); }
| bool _isVisible = false; | |
| double _tooltipOffset = 0; | |
| bool _isVisible = false; | |
| double _tooltipOffset = 0; | |
| StreamSubscription<web.Event>? _resizeSubscription; |
| final IOSink _trackingFile = File( | ||
| p.join('tool', 'used_assets.txt'), | ||
| ).openWrite(mode: FileMode.write); |
There was a problem hiding this comment.
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;
}
}|
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 |
|
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 |