ergebnis/composer-normalize

提供用于标准化 composer.json 的 composer 插件。

安装量: 20,100,876

依赖项: 1,613

建议者: 6

安全: 0

星标: 1,031

关注者: 13

分支: 29

开放问题: 4

类型:composer-plugin


README

Integrate Merge Release Renew Update

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

本项目提供用于标准化 composercomposer.json 的插件。

Hmm, kinda cool I guess

原因

在格式化 composer.json 时,你有以下选项

  • 你可以手动格式化它(并在贡献者格式化不同时请求更改)
  • 你也可以停止关心
  • 或者你可以使用 ergebnis/composer-normalize

ergebnis/composer-normalize 标准化 composer.json,因此你不必这么做。

💡 如果你想了解更多信息,请查看 示例 并阅读此 博客文章

安装

Composer

运行

composer require --dev ergebnis/composer-normalize

安装 ergebnis/composer-normalize 作为 composer 插件。

运行

composer config allow-plugins.ergebnis/composer-normalize true

允许 ergebnis/composer-normalize 作为 composer 插件运行。

💡 allow-plugins 已添加到 composer/composer 以增加额外的安全层。

参考

Phar

前往 http://github.com/ergebnis/composer-normalize/releases/latest 下载最新的 composer-normalize.phar

运行

chmod +x composer-normalize.phar

使下载的 composer-normalize.phar 可执行。

Phive

运行

phive install ergebnis/composer-normalize

使用 PHIVE 安装 ergebnis/composer-normalize

用法

Composer

运行

composer normalize

在当前工作目录中标准化 composer.json

Phar

运行

./composer-normalize.phar

在当前工作目录中标准化 composer.json

Phive

运行

./tools/composer-normalize

在当前工作目录中标准化 composer.json

详细信息

本包内提供的 NormalizePlugin 提供的 NormalizeCommand 将会

  • 确定是否存在 composer.json
  • 确定是否存在 composer.lock,如果存在,则确定其是否是最新的(除非使用了 --no-check-lock 选项)
  • 使用 Ergebnis\Json\Normalizer\Vendor\Composer\ComposerJsonNormalizer 标准化 composer.json 的内容
  • 格式化标准化后的内容(要么是嗅探到的,要么是使用 --indent-size--indent-style 选项指定的)
  • 将标准化和格式化后的 composer.json 内容写回文件
  • 如果存在且需要更新,则更新 composer.lock 中的哈希值

参数

  • file: composer.json 文件的路径(可选,默认为工作目录中的 composer.json

选项

  • --diff: 显示标准化的结果
  • --dry-run: 显示标准化的结果,但不修改任何文件
  • --indent-size: 缩进大小(一个大于 0 的整数);应与 --indent-style 选项一起使用
  • --indent-style: 缩进样式("space" 或 "tab" 中的一个);应与 --indent-size 选项一起使用
  • --no-check-lock: 不检查锁定文件是否是最新的
  • --no-update-lock: 如果存在,则不更新锁定文件

作为指定--indent-size--indent-style选项的替代方案,您还可以使用composer extracomposer.json中配置这些选项。

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

💡 composer extra中提供的配置始终会覆盖通过命令行选项提供的配置。

持续集成

如果您想在持续集成服务中运行此操作,请使用--dry-run选项。

composer normalize --dry-run

如果composer.json未标准化(或composer.lock未更新),则命令将失败,并以退出代码1显示diff。

示例

pestphp/pest

运行

composer normalize

针对https://github.com/pestphp/pest/blob/v0.3.19/composer.json,得到以下diff

diff --git a/composer.json b/composer.json
index 1cfbf1e..204f20f 100644
--- a/composer.json
+++ b/composer.json
@@ -25,6 +25,32 @@
         "pestphp/pest-plugin-init": "^0.3",
         "phpunit/phpunit": ">= 9.3.7 <= 9.5.0"
     },
+    "require-dev": {
+        "illuminate/console": "^7.16.1",
+        "illuminate/support": "^7.16.1",
+        "laravel/dusk": "^6.9.1",
+        "mockery/mockery": "^1.4.1",
+        "pestphp/pest-dev-tools": "dev-master"
+    },
+    "config": {
+        "preferred-install": "dist",
+        "sort-packages": true
+    },
+    "extra": {
+        "branch-alias": {
+            "dev-master": "0.3.x-dev"
+        },
+        "laravel": {
+            "providers": [
+                "Pest\\Laravel\\PestServiceProvider"
+            ]
+        },
+        "pest": {
+            "plugins": [
+                "Pest\\Plugins\\Version"
+            ]
+        }
+    },
     "autoload": {
         "psr-4": {
             "Pest\\": "src/"
@@ -42,49 +68,23 @@
             "tests/Autoload.php"
         ]
     },
-    "require-dev": {
-        "illuminate/console": "^7.16.1",
-        "illuminate/support": "^7.16.1",
-        "laravel/dusk": "^6.9.1",
-        "mockery/mockery": "^1.4.1",
-        "pestphp/pest-dev-tools": "dev-master"
-    },
     "minimum-stability": "dev",
     "prefer-stable": true,
-    "config": {
-        "sort-packages": true,
-        "preferred-install": "dist"
-    },
     "bin": [
         "bin/pest"
     ],
     "scripts": {
         "lint": "php-cs-fixer fix -v",
-        "test:lint": "php-cs-fixer fix -v --dry-run",
-        "test:types": "phpstan analyse --ansi --memory-limit=0",
-        "test:unit": "php bin/pest --colors=always --exclude-group=integration",
-        "test:integration": "php bin/pest --colors=always --group=integration",
-        "update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
         "test": [
             "@test:lint",
             "@test:types",
             "@test:unit",
             "@test:integration"
-        ]
-    },
-    "extra": {
-        "branch-alias": {
-            "dev-master": "0.3.x-dev"
-        },
-        "pest": {
-            "plugins": [
-                "Pest\\Plugins\\Version"
-            ]
-        },
-        "laravel": {
-            "providers": [
-                "Pest\\Laravel\\PestServiceProvider"
-            ]
-        }
+        ],
+        "test:integration": "php bin/pest --colors=always --group=integration",
+        "test:lint": "php-cs-fixer fix -v --dry-run",
+        "test:types": "phpstan analyse --ansi --memory-limit=0",
+        "test:unit": "php bin/pest --colors=always --exclude-group=integration",
+        "update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always"
     }
 }

phpspec/phpspec

运行

composer normalize

针对https://github.com/phpspec/phpspec/blob/7.0.1/composer.json,得到以下diff

diff --git a/composer.json b/composer.json
index 90150a37..276a2ecd 100644
--- a/composer.json
+++ b/composer.json
@@ -1,72 +1,73 @@
 {
-    "name":         "phpspec/phpspec",
-    "description":  "Specification-oriented BDD framework for PHP 7.1+",
-    "keywords":     ["BDD", "SpecBDD", "TDD", "spec", "specification", "tests", "testing"],
-    "homepage":     "http://phpspec.net/",
-    "type":         "library",
-    "license":      "MIT",
-    "authors":      [
+    "name": "phpspec/phpspec",
+    "type": "library",
+    "description": "Specification-oriented BDD framework for PHP 7.1+",
+    "keywords": [
+        "BDD",
+        "SpecBDD",
+        "TDD",
+        "spec",
+        "specification",
+        "tests",
+        "testing"
+    ],
+    "homepage": "http://phpspec.net/",
+    "license": "MIT",
+    "authors": [
         {
-            "name":      "Konstantin Kudryashov",
-            "email":     "[email protected]",
-            "homepage":  "http://everzet.com"
+            "name": "Konstantin Kudryashov",
+            "email": "[email protected]",
+            "homepage": "http://everzet.com"
         },
         {
-            "name":      "Marcello Duarte",
-            "homepage":  "http://marcelloduarte.net/"
+            "name": "Marcello Duarte",
+            "homepage": "http://marcelloduarte.net/"
         },
         {
-            "name":      "Ciaran McNulty",
-            "homepage":  "https://ciaranmcnulty.com/"
+            "name": "Ciaran McNulty",
+            "homepage": "https://ciaranmcnulty.com/"
         }
     ],
-
     "require": {
-        "php":                      "^7.3 || 8.0.*",
-        "phpspec/prophecy":         "^1.9",
-        "phpspec/php-diff":         "^1.0.0",
-        "sebastian/exporter":       "^3.0 || ^4.0",
-        "symfony/console":          "^3.4 || ^4.4 || ^5.0",
+        "php": "^7.3 || 8.0.*",
+        "ext-tokenizer": "*",
+        "doctrine/instantiator": "^1.0.5",
+        "phpspec/php-diff": "^1.0.0",
+        "phpspec/prophecy": "^1.9",
+        "sebastian/exporter": "^3.0 || ^4.0",
+        "symfony/console": "^3.4 || ^4.4 || ^5.0",
         "symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.0",
-        "symfony/process":          "^3.4 || ^4.4 || ^5.0",
-        "symfony/finder":           "^3.4 || ^4.4 || ^5.0",
-        "symfony/yaml":             "^3.4 || ^4.4 || ^5.0",
-        "doctrine/instantiator":    "^1.0.5",
-        "ext-tokenizer":            "*"
+        "symfony/finder": "^3.4 || ^4.4 || ^5.0",
+        "symfony/process": "^3.4 || ^4.4 || ^5.0",
+        "symfony/yaml": "^3.4 || ^4.4 || ^5.0"
+    },
+    "conflict": {
+        "sebastian/comparator": "<1.2.4"
     },
-
     "require-dev": {
-        "behat/behat":           "^3.3",
-        "symfony/filesystem":    "^3.4 || ^4.0 || ^5.0",
-        "phpunit/phpunit":       "^8.0 || ^9.0"
+        "behat/behat": "^3.3",
+        "phpunit/phpunit": "^8.0 || ^9.0",
+        "symfony/filesystem": "^3.4 || ^4.0 || ^5.0"
     },
-
     "suggest": {
         "phpspec/nyan-formatters": "Adds Nyan formatters"
     },
-
-    "conflict": {
-        "sebastian/comparator" : "<1.2.4"
+    "extra": {
+        "branch-alias": {
+            "dev-main": "7.0.x-dev"
+        }
     },
-
     "autoload": {
         "psr-0": {
             "PhpSpec": "src/"
         }
     },
-
     "autoload-dev": {
         "psr-0": {
             "spec\\PhpSpec": "."
         }
     },
-
-    "bin": ["bin/phpspec"],
-
-    "extra": {
-        "branch-alias": {
-            "dev-main": "7.0.x-dev"
-        }
-    }
-
+    "bin": [
+        "bin/phpspec"
+    ]
 }

phpunit/phpunit

运行

composer normalize

针对https://github.com/sebastianbergmann/phpunit/blob/9.5.0/composer.json,得到以下diff

diff --git a/composer.json b/composer.json
index fd6461fc3..23c3a3596 100644
--- a/composer.json
+++ b/composer.json
@@ -1,7 +1,7 @@
 {
     "name": "phpunit/phpunit",
-    "description": "The PHP Unit Testing framework.",
     "type": "library",
+    "description": "The PHP Unit Testing framework.",
     "keywords": [
         "phpunit",
         "xunit",
@@ -16,10 +16,6 @@
             "role": "lead"
         }
     ],
-    "support": {
-        "issues": "https://github.com/sebastianbergmann/phpunit/issues"
-    },
-    "prefer-stable": true,
     "require": {
         "php": ">=7.3",
         "ext-dom": "*",
@@ -54,20 +50,22 @@
         "ext-PDO": "*",
         "phpspec/prophecy-phpunit": "^2.0.1"
     },
+    "suggest": {
+        "ext-soap": "*",
+        "ext-xdebug": "*"
+    },
     "config": {
+        "optimize-autoloader": true,
         "platform": {
             "php": "7.3.0"
         },
-        "optimize-autoloader": true,
         "sort-packages": true
     },
-    "suggest": {
-        "ext-soap": "*",
-        "ext-xdebug": "*"
+    "extra": {
+        "branch-alias": {
+            "dev-master": "9.5-dev"
+        }
     },
-    "bin": [
-        "phpunit"
-    ],
     "autoload": {
         "classmap": [
             "src/"
@@ -86,9 +84,11 @@
             "tests/_files/NamespaceCoveredFunction.php"
         ]
     },
-    "extra": {
-        "branch-alias": {
-            "dev-master": "9.5-dev"
-        }
+    "prefer-stable": true,
+    "bin": [
+        "phpunit"
+    ],
+    "support": {
+        "issues": "https://github.com/sebastianbergmann/phpunit/issues"
     }
 }

变更日志

本项目维护者将本项目的重要更改记录在变更日志中。

贡献

本项目维护者建议遵循贡献指南

行为准则

本项目维护者要求贡献者遵循行为准则

一般支持政策

本项目维护者提供有限的支持。

您可以通过赞助 @localheinz请求与本项目相关的服务发票来支持本项目的维护。

PHP版本支持政策

本项目支持具有活跃和安全支持的PHP版本。

本项目维护者在其初始发布后添加对PHP版本的支持,并在其达到安全支持结束时停止对PHP版本的支持。

安全策略

本项目有一个安全政策

许可证

本项目使用MIT许可证

社交

关注Twitter上的@localheinz@ergebnis