Twenty rules are live in loam.dev today, one more is planned. Each rule finds one kind of problem, shows a flagged and a clean example, and tells you whether it can block your gate. All of them sit behind one stable Rule interface: a new rule extends the list, never the pipeline.
Gate profiles
Every live rule has a gate profile. core rules are built for near-zero false positives and are the only ones that turn loam gate red by default. strict rules rely on heuristics or thresholds: they always run and show up as hints, and block only with loam gate --profile strict (or profile: strict in loam.yaml). The profile never changes baseline.json. Disagree with a single Finding? // loam-ignore: <rule-id> – <reason> silences it in place — the reason is mandatory.
Finds public API members — classes, methods, getters/setters, fields, enums, typedefs — that have no references anywhere in the project. Analysis runs on the resolved element model, not regex, so generated-code inputs (Drift, freezed, Riverpod, json_serializable) are automatically excluded without any configuration. Symbols annotated with @visibleForTesting, @internal, @protected or @pragma('loam:reserved') count as deliberately public and are not reported.
flagged
// public but never used outside this library
class OldHelper {
static String format(String s) => s.trim();
}
// also unreferenced — reported by loam.dev
enum LegacyStatus { active, archived }
clean
// either remove it, make it private, or add
// a loam-ignore directive with a reason:
// loam-ignore: unused-public-exports – re-exported via barrel
// kept and used:
class ActiveHelper {
static String format(String s) => s.trim();
}
Detects import cycles across your Dart libraries. Cycles make compilation order ambiguous, prevent tree-shaking, and are a common sign of unclear layer responsibilities.
flagged
// lib/a.dart
import 'b.dart';
// lib/b.dart
import 'a.dart'; // ← cycle: a → b → a
clean
// Extract shared types into a third library
// lib/shared.dart (no imports from a or b)
// lib/a.dart imports shared.dart
// lib/b.dart imports shared.dart
Flags imports that cross a forbidden layer boundary. Layers and boundaries live in loam.yaml: loam init detects them once and writes them out, you refine them, and the rule never guesses. Each finding names the importing layer, the target layer and the import line. Only imports are checked, exports are not. No boundaries configured, no findings.
flagged
// loam.yaml: boundaries: [{from: core, deny: [features]}]
// lib/core/theme.dart
import '../features/profile/profile_page.dart'; // ← core must not import features
clean
// core owns the contract, features implement it:
// lib/core/page_factory.dart (abstract class, no feature imports)
// lib/features/profile/profile_page.dart
import '../../core/page_factory.dart';
loam.dev finds duplicated code blocks using AST-normalised token hashing — exact copies (Type-1) and structurally identical blocks with renamed identifiers or literals (Type-2). Each Finding covers one cluster with all occurrence locations, so the baseline tracks the whole group as a single entry. A classic AI-agent side effect: helpers copy-pasted rather than extracted. Intentional boilerplate (copyWith, ==, hashCode, toString, toJson, fromJson, …) is skipped.
Measures cyclomatic and cognitive complexity per function/method and aggregates them into a project health score. Flags functions that are too complex to review or test reliably.
flagged
// cognitive complexity ≫ threshold
Future<void> syncData(List<Item> items) async {
for (final item in items) {
if (item.isValid) {
if (item.needsSync) {
try {
if (await remote.has(item.id)) {
await remote.update(item);
} else { await remote.create(item); }
} catch (e) { /* swallowed */ }
}
}
}
}
Flags Flutter TextField and TextFormField widgets that have neither a decoration: InputDecoration(labelText: …) or InputDecoration(label: Text(…)) (nor hintText as a weaker fallback) nor an enclosing Semantics(label: …) ancestor. WCAG 1.3.1 (Info and Relationships), 3.3.2 (Labels or Instructions), and 4.1.2 (Name, Role, Value) all require form fields to have a programmatically determinable label. Analysis runs on the resolved element model — local classes named TextField are never flagged. Conservative: a decoration: that is not a literal InputDecoration(…) creation is left alone. AST-only: runtime contrast, focus order, touch-target sizes, and dynamic decoration values are out of scope.
flagged
// no decoration at all — screen reader has no label to announce
TextField()
// InputDecoration present but no labelText or hintText — still missing
TextField(
decoration: InputDecoration(),
)
clean
// labelText provides the primary accessible label
TextField(
decoration: InputDecoration(labelText: 'Email address'),
)
// hintText accepted as fallback (e.g. search fields)
TextField(
decoration: InputDecoration(hintText: 'Search…'),
)
// or wrap with Semantics for custom label delivery
Semantics(
label: 'Email address',
child: TextField(),
)
Flags Flutter Image / Image.asset / Image.network / Image.file / Image.memory widgets that carry no semanticLabel and are not excluded from the accessibility tree via excludeFromSemantics: true, a Semantics(excludeSemantics: true) or ExcludeSemantics ancestor, or labelled by a Semantics(label: …) ancestor. Dot-shorthand images are checked too. WCAG 1.1.1 (Non-text Content) requires every non-decorative image to have a text alternative. Analysis runs on the resolved element model, so local classes named Image are never flagged.
Flags Flutter IconButton widgets that have no tooltip, no Icon with a semanticLabel and are not wrapped in a Semantics(label: …) or Tooltip(message: …) ancestor, and GestureDetector/InkWell widgets whose direct child is a pure Icon widget with the same omission. WCAG 4.1.2 (Name, Role, Value) requires every interactive control to have a programmatically determinable name. Analysis runs on the resolved element model — local classes named IconButton are never flagged. AST-only: composite icon children and dynamic tooltip values are out of scope.
flagged
// no tooltip — screen reader announces nothing
IconButton(
icon: Icon(Icons.close),
onPressed: () => Navigator.pop(context),
)
// GestureDetector with bare Icon child — same problem
GestureDetector(
child: Icon(Icons.delete),
onTap: () => deleteItem(),
)
clean
// tooltip provides the accessible name
IconButton(
icon: Icon(Icons.close),
tooltip: 'Close',
onPressed: () => Navigator.pop(context),
)
// or wrap with Semantics for GestureDetector/InkWell
Semantics(
label: 'Delete item',
child: GestureDetector(
child: Icon(Icons.delete),
onTap: () => deleteItem(),
),
)
Flags generic and custom (non-Flutter) interactive widgets that carry an onTap, onPressed, or onLongPress callback but have no enclosing Semantics(label: …) ancestor. WCAG 4.1.2 (Name, Role, Value) requires every interactive control to have a programmatically determinable name. Analysis runs on the resolved element model — Flutter built-in widgets already covered by sibling rules (IconButton, GestureDetector, InkWell, TextField, TextFormField) are excluded from this rule. Your own wrapper widgets are read, not guessed: if the wrapper's build() routes a name to Semantics(label:), a Tooltip, a label/semanticLabel/tooltip argument or a Text inside the tapped area — directly or through further wrappers up to four levels deep — call sites are accepted. A wrapper that swallows the name is reported once, at its class, however often it is used; a call that leaves out the name of a wrapper that does take one is reported at the call. Wrappers that cannot be read (third-party, dynamic) fall back to checking the call site's label, semanticLabel or tooltip argument. AST-only: out of scope are widgets that become interactive via inherited callbacks, custom gesture recognisers that bypass the named parameters, and accessible-name mechanisms other than Semantics(label: …).
flagged
// custom tappable card — screen reader has no label
CustomCard(
onTap: () => showDetails(item),
)
// custom button with onPressed — also unnamed
ActionChip(
onPressed: () => doAction(),
)
clean
// wrap with Semantics to give it an accessible name
Semantics(
label: 'Show item details',
button: true,
child: CustomCard(
onTap: () => showDetails(item),
),
)
// or ensure the widget carries a label-providing property
ActionChip(
label: Text('Do action'),
onPressed: () => doAction(),
)
Flags API keys, passwords and tokens written into source as string literals — offline, no token cost, and the value is never echoed in the report, baseline or fingerprint. Two paths: known provider formats anywhere (AWS, GitHub, Stripe live, Slack, Anthropic/OpenAI keys, PEM private keys; severity error; Google API keys are a warning that asks you to restrict the key, since Google treats them as client identifiers) and literals on credential-named variables, arguments, parameter defaults, assignments or map keys with a high-entropy value (severity warning). Placeholders, env-var and storage-key names, String.fromEnvironment / Platform.environment reads, tests, fixtures, example/, generated files and firebase_options.dart are never flagged.
flagged
// credential committed to source
const apiKey = 'k8Jx92LmQp4Zr7Tv0aBc';
final client = Client(password: 'Tr0ub4dor&3xQ');
clean
// injected at build time: --dart-define=API_KEY=...
const apiKey = String.fromEnvironment('API_KEY');
// or read at runtime
final password = Platform.environment['DB_PASSWORD'];
Flags catch blocks whose body is empty ({}) or contains only comments — both silently swallow exceptions. The official empty_catches lint already covers the literal {}; loam adds the comment-only variant that AI agents commonly produce when suppressing a catch with a filler comment, plus the project-wide gate. catch (_) {} with a literally empty body is the deliberate way to ignore an error and is not flagged. Severity: warning. Bodies containing a rethrow, throw, or any logging call are never flagged (conservative allowlist). Generated files (.g.dart, .freezed.dart, …) are skipped automatically.
Flags // ignore: and // ignore_for_file: directives that have no written justification — neither inline text after the lint names nor a comment on the preceding line. Groundless suppress directives are a common AI-agent shortcut: the agent silences the linter rather than fixing the root cause. Severity: info. Generated files (.g.dart, .freezed.dart, …) are skipped automatically.
flagged
// no reason given — why is this lint suppressed?
// ignore: avoid_print
print('debug output');
// file-wide suppress with no justification
// ignore_for_file: prefer_const_constructors
clean
// inline reason: tells reviewers why the suppress is intentional
// ignore: avoid_print – CLI output path, not a debug statement
print('done.');
// reason on the line above is also accepted
// Suppress: this file predates null-safety and is scheduled for migration.
// ignore_for_file: avoid_print
Flags // comments that add no information beyond what the code already shows. Declaration-adjacent: text restates the name (e.g. // build before void build()) or uses a fixed narrative phrase (constructor, getter, setter, build method, the <name> method/widget). Context-free, anywhere in the file: decorative banner/divider comments, bare category labels (Main logic, Helper function, …), emoji-only decoration, redundant end-of-block markers (// end if), and vague TODOs with no concrete action or reference — a TODO with real substance is never flagged. Severity: info. Generated files are skipped automatically.
flagged
// ==============================
// MyWidget
class MyWidget extends StatelessWidget {
// Main logic
// build
@override
Widget build(BuildContext context) => const SizedBox();
// constructor
const MyWidget();
// TODO: fix later
}
clean
class MyWidget extends StatelessWidget {
// Renders as a zero-size placeholder during the loading phase.
@override
Widget build(BuildContext context) => const SizedBox();
const MyWidget();
// TODO: handle null case when userId is missing (see #123)
}
Flags two or more Step 1:/Step 2:/First,/Next,/Then,/Finally, comments, each immediately preceding a statement in the same function/method/constructor body, that together narrate the body step-by-step even though the statements are already self-explanatory. A single such comment on its own is not flagged — only a sequence is. Severity: info. Generated files are skipped automatically.
flagged
void placeOrder(Order order) {
// Step 1: validate the order
validate(order);
// Step 2: charge the customer
charge(order);
// Finally, send the confirmation email
sendConfirmation(order);
}
Flags a comment whose whole text is a stand-in for code that is not there, such as // ... rest of code, // ... existing code ..., // rest of the implementation here or // your code here. It is the visible trace of a truncated AI edit: the file compiles, but part of the behaviour is missing. A longer sentence that merely mentions the rest of the code is never flagged, and neither are doc comments. Severity: warning. Generated files are skipped automatically.
Flags a function, method, getter or setter in lib/ or bin/ whose entire body is throw UnimplementedError(), matched by name on the parse tree. A stub that crashes when called is a placeholder an agent left instead of the implementation. Not flagged: a throw among other statements (for example a default branch), members of abstract or sealed classes and mixins, classes extending PlatformInterface (also across files, recognised by a base class named …Platform or a platform_interface import), tests and generated files. Severity: warning.
flagged
class Repository {
Order load(String id) => throw UnimplementedError();
}
clean
class Repository {
Repository(this._db);
final Database _db;
Order load(String id) => Order.fromRow(_db.row('orders', id));
}
Flags a field of a Flutter State, or of a class with its own dispose(), that the class creates itself (a controller, focus node, notifier or Timer.periodic) and that dispose() never releases. The field type must offer dispose, close or cancel on the resolved element model, so OverlayPortalController, which has none, is never flagged; close and cancel count only when the Dart SDK or a third-party package declares them. Released means: referenced in dispose(), in a list or loop there, or in a helper method it calls. Not flagged: values from constructor parameters, widget.x or provider lookups, static fields and late fields never assigned a created value. Severity: warning.
flagged
class _FormState extends State<Form> {
final _name = TextEditingController();
late final Timer _tick;
@override
void initState() {
super.initState();
_tick = Timer.periodic(const Duration(seconds: 1), (_) => refresh());
}
@override
void dispose() {
super.dispose();
}
}
clean
class _FormState extends State<Form> {
final _name = TextEditingController();
late final Timer _tick;
@override
void initState() {
super.initState();
_tick = Timer.periodic(const Duration(seconds: 1), (_) => refresh());
}
@override
void dispose() {
_tick.cancel();
_name.dispose();
super.dispose();
}
}
Flags a test or testWidgets whose body never asserts: no expect, expectLater, fail, verify, check or expectAsync, neither in the body nor in a project function it calls (up to three hops), and no assert or throw in the body itself. The test name promises a behaviour that nothing checks, so the test stays green whatever the code does. Calls into other packages such as pumpWidget are not assertions; a call of a callback parameter counts as one, because the check lives where the callback is supplied. Not flagged: tests with skip: and generated files. Own assertion helpers go under slop_assertion_free_test in loam.yaml. Tests are only checked when they are not excluded by an ignore glob. Severity: info.
flagged
test('restores the cart after a restart', () {
final cart = Cart.restore(storage);
cart.add(item);
});
clean
test('restores the cart after a restart', () {
final cart = Cart.restore(storage);
cart.add(item);
expect(cart.items, [item]);
});
Flags setState in a Flutter State that can run after the screen was closed: after an await, in catch or finally of a try that awaits, or in a Future.then, whenComplete or catchError callback, with no mounted check in between. On an unmounted State, setState throws. The official use_build_context_synchronously lint only covers BuildContext, not setState. Guards that count: if (!mounted) return;, if (!context.mounted) return;, if (mounted) … and mounted ? … : …. Only Flutter's State.setState counts, resolved on the element model; your own wrapper such as safeSetState is not flagged, and neither is unclear control flow. Severity: warning.
Will look for AI shortcuts that take intent to judge: guard clauses that can never trigger and abstractions nobody needs. Deterministic AST patterns run first; an optional LLM layer, on your own API key, judges the rest — every verdict is cached, so the same code always gets the same verdict and repeats cost no tokens. (Empty catch blocks, unjustified // ignore:, filler and placeholder comments and unimplemented stubs are already covered by the live slop rules above.)
flagged
// an interface with one implementation and one caller
abstract class DateFormatterInterface {
String format(DateTime d);
}
class DateFormatterImpl implements DateFormatterInterface {
@override
String format(DateTime d) => '${d.day}.${d.month}.${d.year}';
}
clean
// say what you need, nothing more
String formatDate(DateTime d) => '${d.day}.${d.month}.${d.year}';
Get started
Try the rules on your code
$dart pub global activate loam
$loam scan # in your project
loam scan runs every live rule over your project. The Developer Guide covers the full CLI reference, output formats, configuration and worked examples — including how to run loam gate in CI.