prefer-named-imports
Warns if the configured import is not a named import.
note
This rule requires configuration in order to highlight any issues.
⚙️ Config
Set entries
(default is empty) to configure the list of named import entries.
Each entry is either a map or a string.
If the entry is a map, the key represents the imported package name and the value is the expected name alias.
If the entry is a string, the value represents both the imported package name and the expected name alias.
dart_code_metrics:
...
rules:
...
- prefer-named-imports:
entries:
- test
- path: p
- "dart:io": io
Example
With the configuration in the example above, here are some bad/good examples.
❌ Bad:
import 'package:test/test.dart'; // LINT
import 'package:some/other.dart';
import 'package:path/path.dart'; // LINT
✅ Good:
import 'package:test/test.dart' as test;
import 'package:some/other.dart';
import 'package:path/path.dart' as p;