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.
Example
Example with 1 Class
❌ Bad:
some_widget.dart
// LINT: The first class name does not match the file name. Try renaming it.
class SomeOtherWidget extends StatelessWidget {
Widget build(BuildContext context) {
// ...
}
}
✅ Good:
some_widget.dart
class SomeWidget extends StatelessWidget {
Widget build(BuildContext context) {
// ...
}
}
Example with Several Classes
❌ Bad:
some_other_widget.dart
class _SomeOtherWidget extends StatelessWidget {
Widget build(BuildContext context) {
// ...
}
}
// LINT: The first class name does not match the file name. Try renaming it.
class SomeWidget extends StatelessWidget {
Widget build(BuildContext context) {
// ...
}
}
✅ Good:
some_widget.dart
class _SomeOtherWidget extends StatelessWidget {
Widget build(BuildContext context) {
// ...
}
}
// Correct, the file has a new name
class SomeWidget extends StatelessWidget {
Widget build(BuildContext context) {
// ...
}
}