XUtils

Composer Normalize

A plugin for normalizing `composer.json` files.


composer-normalize

Integrate Merge Release Renew Update

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer plugin for normalizing composer.json.

Hmm, kinda cool I guess

Why

When it comes to formatting composer.json, you have the following options:

  • you can stop caring
  • you can format it manually (and request changes when contributors format it differently)
  • you can use ergebnis/composer-normalize
ergebnis/composer-normalize normalizes composer.json, so you don’t have to.

:bulb: If you want to find out more, take a look at the examples and read this blog post.

Composer

Run

composer require --dev ergebnis/composer-normalize

to install ergebnis/composer-normalize as a composer plugin.

Run

composer config allow-plugins.ergebnis/composer-normalize true
to allow ergebnis/composer-normalize to run as a composer plugin.

:bulb: The allow-plugins has been added to composer/composer to add an extra layer of security.

For reference, see

Phar

Head over to http://github.com/ergebnis/composer-normalize/releases/latest and download the latest composer-normalize.phar.

Run

chmod +x composer-normalize.phar

to make the downloaded composer-normalize.phar executable.

Phive

Run

phive install ergebnis/composer-normalize

to install ergebnis/composer-normalize with PHIVE.

Composer

Run

composer normalize

to normalize composer.json in the working directory.

Phar

Run

./composer-normalize.phar

to normalize composer.json in the working directory.

Phive

Run

./tools/composer-normalize

to normalize composer.json in the working directory.

Details

The NormalizeCommand provided by the NormalizePlugin within this package will

  • determine whether a composer.json exists
  • determine whether a composer.lock exists, and if so, whether it is up to date (unless the --no-check-lock option is used)
  • use Ergebnis\Json\Normalizer\Vendor\Composer\ComposerJsonNormalizer to normalize the content of composer.json
  • format the normalized content (either as sniffed, or as specified using the --indent-size and --indent-style options)
  • write the normalized and formatted content of composer.json back to the file
  • update the hash in composer.lock if it exists and if an update is necessary

Arguments

  • file: Path to composer.json file (optional, defaults to composer.json in working directory)

Options

  • --diff: Show the results of normalizing
  • --dry-run: Show the results of normalizing, but do not modify any files
  • --indent-size: Indent size (an integer greater than 0); should be used with the --indent-style option
  • --indent-style: Indent style (one of “space”, “tab”); should be used with the --indent-size option
  • --no-check-lock: Do not check if lock file is up to date
  • --no-update-lock: Do not update lock file if it exists

As an alternative to specifying the --indent-size and --indent-style options, you can also use composer extra to configure these options in composer.json:

{
  "extra": {
    "composer-normalize": {
      "indent-size": 2,
      "indent-style": "space"
    }
  }
}

:bulb: The configuration provided in composer extra always overrides the configuration provided via command line options.

Continuous Integration

If you want to run this in continuous integration services, use the --dry-run option.

composer normalize --dry-run

In case composer.json is not normalized (or composer.lock is not up-to-date), the command will fail with an exit code of 1 and show a diff.

Examples

Changelog

The maintainers of this project record notable changes to this project in a changelog.

Code of Conduct

The maintainers of this project ask contributors to follow the code of conduct.

Security Policy

This project has a security policy.

Social

Follow @localheinz and @ergebnis on Twitter.


Articles

  • coming soon...