ergebnis/composer-normalize
Composer plugin that automatically normalizes composer.json: consistent key ordering, formatting, and whitespace to reduce diffs and style debates. Install as a dev dependency, allow the plugin, and run it in CI to keep composer.json tidy and predictable.
composer.json adheres to a standardized format. No impact on Laravel’s architecture or performance.composer require and configuration update (allow-plugins).husky, pre-commit, or Git hooks).composer normalize or scripts in package.json.laravel/framework, spatie/laravel-*) to enforce consistent composer.json formatting.composer.json.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Composer Version | Requires Composer 2.0+ (Laravel projects typically use Composer 2.x). | Verify Composer version in CI/CD and local environments. |
| Lock File Conflicts | May update composer.lock if composer.json changes. |
Use --no-update-lock in CI or enforce --dry-run for validation. |
| False Positives | Strict normalization may flag intentional formatting (e.g., custom scripts). | Configure extra.composer-normalize to relax rules or exclude specific sections. |
| Performance | Minimal overhead; runs only during normalization. | Benchmark in CI to ensure no slowdowns. |
| Plugin Security | Requires allow-plugins configuration. |
Audit plugin permissions and restrict to trusted dev environments. |
composer.json or all sub-packages (e.g., in a monorepo)?composer.json is non-compliant (CI enforcement)?post-install-cmd) or manually?scripts, extra) be excluded from normalization?composer.json files that deviate significantly from the normalized format?spatie/laravel-*, laravel/scout) to maintain consistency.composer.json.| Phase | Action | Tools/Commands |
|---|---|---|
| Evaluation | Test normalization on a non-critical repo (e.g., a sample package). | composer normalize --dry-run --diff |
| Configuration | Add to composer.json and CI/CD. |
composer require --dev ergebnis/composer-normalize + composer config allow-plugins |
| CI Enforcement | Add to CI pipeline as a validation step. | GitHub Actions: composer normalize --dry-run (fails if diff exists). |
| Local Adoption | Integrate into pre-commit hooks or VS Code tasks. | husky + composer normalize or package.json scripts. |
| Rollout | Gradually enforce across all Laravel packages/repos. | Start with opt-in, then mandate for new packages. |
composer.json: May conflict with highly customized files (e.g., non-standard key ordering). Mitigate via extra.composer-normalize overrides.composer normalize --dry-run --diff across all Laravel packages to identify potential conflicts.extra.composer-normalize settings (e.g., indentation, excluded sections) in a base template.tasks.json)..composer-normalize.md guide for contributors on formatting rules and exceptions.composer.json formatting.composer update ergebnis/composer-normalize.extra.composer-normalize settings across repos.composer normalize --diff --verbose.allow-plugins, local config).CONTRIBUTING.md or repo README.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Lock File Mismatch | Builds fail due to outdated composer.lock. |
Use --no-update-lock in CI or enforce --dry-run. |
| Merge Conflicts | Normalized files conflict with manual edits. | Use --dry-run in CI; resolve locally before committing. |
| False Positives | Legitimate formatting flagged as invalid. | Configure extra.composer-normalize to exclude sections or relax rules. |
| Composer Plugin Blocked | allow-plugins not configured. |
Add |
How can I help you explore Laravel packages today?