Skip to main content

no-empty-string

configurable
pro+

Warns when a string literal is empty.

While empty string literals are quite common, in some cases they are a refactoring leftover (or a value that has not been updated with a real value). This rule highlights all usages of empty strings, and for any valid usage, consider creating a shared constant variable and using it instead.

⚙️ Config

Set ignore-interpolations (default is false) to ignore empty string literals inside interpolations.

analysis_options.yaml
dart_code_metrics:
rules:
- no-empty-string:
ignore-interpolations: false

Example

❌ Bad:

void fn() {
// LINT: Avoid empty string literals. Try extracting it to a named constant or variable.
Uri.https('');

// LINT: Avoid empty string literals. Try extracting it to a named constant or variable.
Error('');
}

✅ Good:

void fn() {
Uri.https('https://dcm.dev');
Error('Some valid error message');
}