Skip to content

feat: Add automatic sorting for pubspec.yaml dependencies #89

Description

@Franklyn-R-Silva

Description

This PR introduces a new feature to automatically sort dependencies within pubspec.yaml alphabetically. This helps keep the project configuration clean and organized, similar to how Dart imports are sorted.

Key Changes

  • New Logic: Added lib/pubspec_sort.dart which handles the parsing and sorting of the yaml file.
  • Dependency: Added yaml_edit package to safely modify pubspec.yaml while preserving existing comments and whitespace.
  • Integration: Updated bin/import_sorter.dart to execute the pubspec sorting after the import sorting process.
  • Scope: The tool now sorts the following sections if they exist:
    • dependencies
    • dev_dependencies
    • dependency_overrides

Testing

  • Added unit tests in test/pubspec_test.dart to verify that dependencies are correctly reordered alphabetically.
  • Verified manually that the tool runs successfully via dart run import_sorter.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update (README updated)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions