1
0
Fork 0

Detect duplicate keys in composer.json, fixes #4620

pull/4621/head
Jordi Boggiano 2015-11-21 02:35:00 +00:00
parent dbcf8cae13
commit e87190e3da
3 changed files with 18 additions and 9 deletions

View File

@ -26,7 +26,7 @@
"justinrainbow/json-schema": "^1.4.4", "justinrainbow/json-schema": "^1.4.4",
"composer/spdx-licenses": "^1.0", "composer/spdx-licenses": "^1.0",
"composer/semver": "^1.0", "composer/semver": "^1.0",
"seld/jsonlint": "^1.0", "seld/jsonlint": "^1.4",
"symfony/console": "^2.5 || ^3.0", "symfony/console": "^2.5 || ^3.0",
"symfony/finder": "^2.2 || ^3.0", "symfony/finder": "^2.2 || ^3.0",
"symfony/process": "^2.1 || ^3.0", "symfony/process": "^2.1 || ^3.0",

16
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "c88bd0dc7f99b674776d931973d3e1b7", "hash": "93e6b0b69e1d2831beb016b291320e65",
"content-hash": "e31b609879971d42d37f09bb6a526192", "content-hash": "e50c021dd9230b14ee88fe3d62c3923f",
"packages": [ "packages": [
{ {
"name": "composer/semver", "name": "composer/semver",
@ -246,20 +246,20 @@
}, },
{ {
"name": "seld/jsonlint", "name": "seld/jsonlint",
"version": "1.3.1", "version": "1.4.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Seldaek/jsonlint.git", "url": "https://github.com/Seldaek/jsonlint.git",
"reference": "863ae85c6d3ef60ca49cb12bd051c4a0648c40c4" "reference": "66834d3e3566bb5798db7294619388786ae99394"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/863ae85c6d3ef60ca49cb12bd051c4a0648c40c4", "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/66834d3e3566bb5798db7294619388786ae99394",
"reference": "863ae85c6d3ef60ca49cb12bd051c4a0648c40c4", "reference": "66834d3e3566bb5798db7294619388786ae99394",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=5.3.0" "php": "^5.3 || ^7.0"
}, },
"bin": [ "bin": [
"bin/jsonlint" "bin/jsonlint"
@ -288,7 +288,7 @@
"parser", "parser",
"validator" "validator"
], ],
"time": "2015-01-04 21:18:15" "time": "2015-11-21 02:21:41"
}, },
{ {
"name": "seld/phar-utils", "name": "seld/phar-utils",

View File

@ -25,6 +25,7 @@ use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Composer\EventDispatcher\EventDispatcher; use Composer\EventDispatcher\EventDispatcher;
use Composer\Autoload\AutoloadGenerator; use Composer\Autoload\AutoloadGenerator;
use Composer\Semver\VersionParser; use Composer\Semver\VersionParser;
use Seld\JsonLint\JsonParser;
/** /**
* Creates a configured instance of composer. * Creates a configured instance of composer.
@ -219,6 +220,14 @@ class Factory
} }
$file->validateSchema(JsonFile::LAX_SCHEMA); $file->validateSchema(JsonFile::LAX_SCHEMA);
$jsonParser = new JsonParser;
try {
$jsonParser->parse(file_get_contents($localConfig), JsonParser::DETECT_KEY_CONFLICTS);
} catch (\Seld\JsonLint\DuplicateKeyException $e) {
$details = $e->getDetails();
$io->writeError('<warning>Key '.$details['key'].' is a duplicate in '.$localConfig.' at line '.$details['line'].'</warning>');
}
$localConfig = $file->read(); $localConfig = $file->read();
} }