Skip to main content

avoid-unused-instances

added in: 1.8.0
⚙️
Pro+
preset: recommended

Warns when a newly created object is not being used.

⚙️ Config

Set ignored-instances (default is [Timer, Debounce, Catcher]) to ignore instances that are intended to be unused.

dart_code_metrics:
...
rules:
...
- avoid-unused-instances:
ignored-instances:
- Timer
- SomeOtherClass

Example

❌ Bad:

class SomeClass {
...
}

SomeClass function() {
if (someCondition) {
SomeClass(); // LINT
}

return SomeClass();
}

✅ Good:

class SomeClass {
...
}

SomeClass function() {
if (someCondition) {
return SomeClass();
}

return SomeClass();
}