twk_lints 0.3.0
twk_lints: ^0.3.0 copied to clipboard
An analyzer plugin with lints and assists for apps built on twk.
twk_lints #
Lints and editor assists for apps built on
twk. They catch the mistakes a terminal app
makes most often, as you type and in dart analyze, and they offer quick
fixes for some of them.
Features #
- Warnings that are on by default:
set_state_after_disposefinds asetStatethat may run after the widget has gone, such as one that follows anawaitwith no check ofmounted.context_after_awaitdoes the same for acontext.dispose_controllersfinds a controller or aFocusNodethat the state creates and never disposes. - Key names:
key_namesfinds a binding such asctrl+ithat a terminal without the kitty keyboard protocol sends astab, so that it never fires there. - Lints you turn on: a missing key on the stateful widgets of a list, a
Tablewhose row type is lost, anInputListenerthatKeyBindingswould do better, a wait on the wall clock in a test, and a control a screen reader cannot name. - Quick fixes: such as Add 'if (!mounted) return;', where the editor shows a warning.
- Assists at the cursor: wrap a widget, extract it into a new one, remove it, swap it with its parent or child, move it up or down, and convert a stateless widget to a stateful one and back.
Getting started #
Needs Dart 3.13.5 or later. Add the package as a dev dependency:
dart pub add dev:twk_lints
and include its recommended set, with every rule on, in the
analysis_options.yaml at the root of your package:
include: package:twk_lints/recommended.yaml
Beside other sets, it is a list:
include:
- package:pro_lints/recommended.yaml
- package:twk_lints/recommended.yaml
dart analyze and your editor then report what the rules find. This code:
Future<void> _load() async {
final items = await fetch();
setState(() => _items = items);
}
in a State of a twk widget gets
warning - lib/a.dart:17:5 - 'setState' may run after 'dispose': it follows an
'await', with no check of 'mounted'. Try 'if (!mounted) return;' before it.
- set_state_after_dispose
The first analysis after the change compiles the plugin and takes a while; an editor's analysis server picks the change up when it restarts.
To silence a rule on one line, write the plugin's name before it:
// ignore: twk_lints/set_state_after_dispose.
Learn more #
- Reference: every rule, fix and assist in full, and how to turn a rule off.
- How it works and is tested: for those who work on the package.
- What the plugin costs: time and allocations of each rule.
- Lint candidates: the rules that were considered, built or not, and why.
- twk: the framework the rules are for.
License #
MIT, copyright 2026 Andrii Ivanov: LICENSE.