prefer-match-file-name
preset: recommended
Warns if the file name does not match the name of the first public class / mixin / extension / enum in the file or a private one if there are no public entries.
By default this rule skips .g.dart
and .freezed.dart
files. To exclude other files with dot notation, use the exclude
configuration.
note
For this rule it's recommended to exclude the test
folder.
dart_code_metrics:
...
rules:
...
- prefer-match-file-name:
exclude:
- test/**
...
Example
Example 1 One class in the file
❌ Bad:
File name: some_widget.dart
class SomeOtherWidget extends StatelessWidget {
Widget build(BuildContext context) {
//...
}
}
✅ Good:
File name: some_widget.dart
class SomeWidget extends StatelessWidget {
Widget build(BuildContext context) {
//...
}
}
Example 2 Multiple class in the file
❌ Bad:
File name: some_other_widget.dart
class _SomeOtherWidget extends StatelessWidget {
Widget build(BuildContext context) {
//...
}
}
class SomeWidget extends StatelessWidget {
Widget build(BuildContext context) {
//...
}
}
✅ Good:
File name: some_widget.dart
class _SomeOtherWidget extends StatelessWidget {
Widget build(BuildContext context) {
//...
}
}
class SomeWidget extends StatelessWidget {
Widget build(BuildContext context) {
//...
}
}