Keeping pubspec.yaml
dependencies in order facilitates lookup and maintenance. There may be multiple criteria to sort dependencies,
which make sense in the context of the Dart project on-hand.
However, none of the criteria can be a perfect-fit for all projects. In order to promote consistency across projects, and to follow the Principle of least astonishment, it’s best to sort dependencies in
alphabetical ascending order.
While it may not be the most optimal sorting criteria for all specific scenarios, it’s the most neutral, easily inferrable at first glance, as well
as the least surprising.
The rule applies to the following three sections of the pubspec.yaml
file:
-
dependencies
-
dev_dependencies
-
dependency_overrides
What is the potential impact?
Sorting dependencies in a different order may lead, for example, to duplicated dependencies, where a developer assumed a dependency would appear in
a certain section of the pubspec.yaml
file, while it actually appears in a different section.