no_placeholder_implementation
Reports a function body that was never written: a lone throw UnimplementedError() or // TODO. Write the body.
- Tier
- blocking
- Scope
- Dart
- Fix
- none
What it reports
Section titled “What it reports”A body where a placeholder stands in place of the implementation:
- A body that only throws the SDK’s
UnimplementedError:=> throw UnimplementedError(), or a block whose only statement is that throw. The error’s message and comments beside the throw make no difference. The violation covers the throw expression. - A body with no statement and at least one marker comment:
{ // TODO: write the record. }. A marker comment has one of themarkersin it as a whole word, by defaultTODOandFIXME. The violation covers the first marker comment of the body.
Any body counts: of a function, method, getter, setter, constructor, local function or function expression. An override is reported like any other declaration, in a fake or a stub too, and test code like any other code: name such paths in exclude.
It does not report:
- a member with no body: an abstract method or getter, an
externalfunction; - a body that is empty or holds only comments without a marker:
void onEvent(Object event) {},{ // Nothing to release here. }; - a marker comment in a body that has at least one statement, whatever it is;
- a marker comment outside the body: above the declaration or after the closing bracket;
- a body that throws another error, such as
UnsupportedError; - a marker in a longer word or in another case:
todo,TODOS; - a block that is not a function body, such as an
ifor a loop body, or the body of a class, mixin, enum or extension; - an error of a class of your own named
UnimplementedError, a subclass of it, or one thrown through a variable or a helper function; - a placeholder in other words, such as
// implementation goes here: add the phrase tomarkers.
UnimplementedError and a lone // TODO both say that the work was put off. The code compiles, the signature looks finished, and every caller gets an error at run time or nothing at all.
An AI coding agent leaves such bodies behind when it scaffolds more than it writes: the class and its methods are there, and one of them is throw UnimplementedError(). The rule is blocking because the function does not do what its name says.
The SDK lint flutter_style_todos checks how a TODO comment is written, wherever it stands. This rule does not care how the comment is written, only that it is all a body holds.
Example
Section titled “Example”class ReceiptStore { Future<Receipt> load(String id) => throw UnimplementedError();
Future<void> save(Receipt receipt) async { // TODO: write the receipt to disk. }}class ReceiptStore { Future<Receipt> load(String id) async => Receipt.parse(await _fileOf(id).readAsString());
Future<void> save(Receipt receipt) async { await _fileOf(receipt.id).writeAsString(receipt.encode()); }}When a body is not a placeholder, say so in a way the rule can tell apart:
- an operation unsupported on purpose throws
UnsupportedError('Receipts are read-only on the web.'), which is what that error is for; - a body that must stay empty has a comment without a marker,
{ // Nothing to release here. }, or no comment; - a fake in a test implements only what the test needs, through
noSuchMethodor by throwingUnsupportedErrorfrom the members it leaves out.
Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
markers |
[TODO, FIXME] |
The words that make a comment a marker comment. Your list replaces the default. |
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
assay: rules: no_placeholder_implementation: markers: [TODO, FIXME, HACK, XXX]A marker is matched as a whole word, in the case it is written in: TODO matches // TODO: later, // TODO(ali): later and /* TODO */, but not todo, TODOS or AUTODOC. A marker may be several words, such as not implemented. An empty marker is left out. With an empty list, no comment is a marker comment, and the rule reports only bodies that throw UnimplementedError.
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// The generator fills this body in; the hand-written file only declares it.// ignore: assay/no_placeholder_implementationReceipt decode(String text) => throw UnimplementedError();The suppression goes above the line the placeholder starts on: the throw, or the marker comment. So in a block body it stands inside the body:
Future<void> export(Receipt receipt) async { // Export ships with the next release; the button is hidden until then. // ignore: assay/no_placeholder_implementation // TODO: write the export.}// ignore_for_file: assay/no_placeholder_implementation silences it in a whole file, and // ignore: no_placeholder_implementation without the prefix works too. See Suppressions.