match_lib_folder_structure
This rule flags a file under lib/ that sits in a folder whose name is not lower_snake_case.
This rule is in the pedantic preset.
Why use this rule
Section titled “Why use this rule”A folder name becomes part of every package: URI that imports through it, so it is public API in a way a local variable name is not — renaming it later is a breaking change for every consumer.
CamelCase and kebab-case folders also break on case-insensitive filesystems. A folder renamed from Models to models is invisible to git on macOS by default, so the import keeps resolving on the machine that made the change and fails in CI, which is the worst place to find out.
The SDK’s file_names rule checks the file; nothing in the SDK checks the directories above it, which is the gap this fills.
The diagnostic is reported once per file, at the first offending folder: a second one on the same path would be fixed by the same rename.
See also: file_names, Effective Dart: naming
lib/dataSources/user_repository.dartlib/data-sources/user_repository.dartlib/data_sources/user_repository.dartOptions
Section titled “Options”many_lints: rules: match_lib_folder_structure: root: librules: match_lib_folder_structure: root: lib| Option | Type | Default | Description |
|---|---|---|---|
root |
string | lib |
The top-level directory the rule applies to. Files outside it are never reported |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: match_lib_folder_structure: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”prefer_match_file_name— Name a file after the first public declaration in it.prefer_single_declaration_per_file— Keep one top-level declaration per file, with per-type budgets.prefer_single_widget_per_file— Keep one public widget per file for better organization.arguments_ordering— Keep named arguments in a configured order.