Saltar al contenido principal

prefer-match-file-name

added in: 1.0.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.

dart_code_linter:
...
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 {
@override
Widget build(BuildContext context) {
//...
}
}

Good:

File name: some_widget.dart

class SomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
//...
}
}

Example 2 Multiple class in the file

Bad:

File name: some_other_widget.dart

class _SomeOtherWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
//...
}
}

class SomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
//...
}
}

Good:

File name: some_widget.dart

class _SomeOtherWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
//...
}
}

class SomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
//...
}
}