Skip to main content

prefer-match-file-name

added in: 4.2.0
warning
🛠

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.

note

For this rule it's recommended to exclude the test folder.

info

The fix for this rule is available only in "Teams" version.

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) {
//...
}
}