Skip to content

match_lib_folder_structure

v1.0.0WarningConfigurableCode Organization

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.

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.dart
lib/data-sources/user_repository.dart
lib/data_sources/user_repository.dart
analysis_options.yaml
many_lints:
rules:
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

To disable this rule:

many_lints.yaml
rules:
match_lib_folder_structure: false

To keep the rule on but skip certain paths, use per-rule exclude.