https://github.com/jnbn/composer-json-fixer
A tool for fixing and cleaning up "composer.json" file according to its schema and best practices.
https://github.com/jnbn/composer-json-fixer
cleaner composer fixer standardization
Last synced: 2 months ago
JSON representation
A tool for fixing and cleaning up "composer.json" file according to its schema and best practices.
- Host: GitHub
- URL: https://github.com/jnbn/composer-json-fixer
- Owner: jnbn
- License: mit
- Created: 2020-04-14T15:28:31.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-05T11:42:27.000Z (over 5 years ago)
- Last Synced: 2025-12-14T22:59:04.004Z (6 months ago)
- Topics: cleaner, composer, fixer, standardization
- Language: PHP
- Homepage:
- Size: 127 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# composer.json fixer
[](https://packagist.org/packages/jnbn/composer-json-fixer)
[](https://php.net)
[](https://packagist.org/packages/jnbn/composer-json-fixer)
[](https://travis-ci.org/jnbn/composer-json-fixer)
[](https://coveralls.io/github/jnbn/composer-json-fixer?branch=master)
A tool for fixing and cleaning up `composer.json` file
according to its [schema](https://getcomposer.org/doc/04-schema.md) and best practices.
## Installation
composer.json fixer can be installed [globally](https://getcomposer.org/doc/03-cli.md#global):
```bash
composer global require jnbn/composer-json-fixer
```
or as a dependency (e.g. to include into CI process):
```bash
composer require --dev jnbn/composer-json-fixer
```
## Usage
Run and fix:
```bash
vendor/bin/composer-json-fixer
```
See diff of potential fixes:
```bash
vendor/bin/composer-json-fixer --dry-run
```
Upgrade dependencies with `composer require`:
```bash
vendor/bin/composer-json-fixer --upgrade
```
## Fixers
- **composer keys lowercase** - changes names of properties to lowercase
- **autoload** - fixes paths and sorts `autoload` and `autoload-dev`
- **config** - sorts `config` by key
- **keywords** - sorts `keywords` by value
- **license** - adds `license` if it is missing
- **minimum stability** - removes `minimum-stability` if it has default value ("stable")
- **name** - makes package name lowercase
- **repositories** - sorts `repositories`
- **require** - cleans up versions for `require` and `require-dev`
- **version** - removes `version` if it is present
- **composer keys sorting** - sorts properties according to [the documentation](https://getcomposer.org/doc/04-schema.md)
## Example
Before running `composer-json-fixer`:
```json
{
"name": "JohnDoe/FooBar",
"version": "v1.0.0",
"type": "library",
"description": "A library to do something cool",
"keywords": [
"cool",
"awesome stuff"
],
"require-dev": {
"phpunit/phpunit": "^5.7 | ^6.5"
},
"require": {
"symfony/finder": "^2.7|^3.4|^4",
"symfony/yaml": ">= 2.7"
},
"minimum-stability": "stable",
"autoload": {
"psr-4": {
"FooBar": "src"
}
}
}
```
After:
```json
{
"name": "johndoe/foobar",
"description": "A library to do something cool",
"type": "library",
"keywords": [
"awesome stuff",
"cool"
],
"license": "proprietary",
"require": {
"symfony/finder": "^2.7 || ^3.4 || ^4",
"symfony/yaml": ">=2.7"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^6.5"
},
"autoload": {
"psr-4": {
"FooBar\\": "src/"
}
}
}
```
## Exit status
- `0` - `composer.json` file does not require fixing,
- `1` - `composer.json` file can be, or was fixed,
- `2` - exception was thrown.
## Contributing
Request a feature or report a bug by creating [issue](https://github.com/jnbn/composer-json-fixer/issues).
Alternatively, fork the repo, develop your changes, regenerate `README.md`:
```bash
src/Readme/run > README.md
```
make sure all checks pass:
```bash
composer check
```
and submit a pull request.