Skip to main content

prefer-single-declaration-per-file

added in: 1.17.0
⚙️

Warns when a file contains more than one top-level declaration (class, mixin, extension, enum or extension type).

⚙️ Config

Set ignore-private (default is true) to ignore private declarations.

dart_code_metrics:
...
rules:
...
- prefer-single-declaration-per-file:
ignore-private: true

Example

❌ Bad:

some_class.dart

class SomeClass {}

class SomeOtherClass {} // LINT

✅ Good:

some_class.dart

class SomeClass {}

some_other_class.dart

class SomeOtherClass {}