Skip to content

Commit

Permalink
Remove leading 'v' character from version strings
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Dec 12, 2023
1 parent 0802f32 commit fce443f
Show file tree
Hide file tree
Showing 44 changed files with 498 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ sections, the `Vendor\Composer\VersionConstraintNormalizer` will ensure that
}
```

- useless [inline aliases]()https://getcomposer.org/doc/articles/aliases.md#require-inline-alias are removed
- useless [inline aliases](https://getcomposer.org/doc/articles/aliases.md#require-inline-alias) are removed

```diff
{
Expand All @@ -592,6 +592,19 @@ sections, the `Vendor\Composer\VersionConstraintNormalizer` will ensure that
}
```


- leaving `v` characters in version numbers are removed

```diff
{
"require": {
- "foo/bar": "^v1.2",
- "foo/baz": "v1.3.7"
+ "foo/bar": "^1.2",
+ "foo/baz": "1.3.7"
}
```

## Changelog

The maintainers of this package record notable changes to this project in a [changelog](CHANGELOG.md).
Expand Down
22 changes: 22 additions & 0 deletions src/Vendor/Composer/VersionConstraintNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function normalize(Json $json): Json
private function normalizeVersionConstraint(string $versionConstraint): string
{
$versionConstraint = self::normalizeVersionConstraintSeparators($versionConstraint);
$versionConstraint = self::removeLeadingVCharacter($versionConstraint);
$versionConstraint = self::replaceWildcardWithTilde($versionConstraint);
$versionConstraint = self::replaceTildeWithCaret($versionConstraint);
$versionConstraint = self::removeDuplicateVersionConstraints($versionConstraint);
Expand Down Expand Up @@ -169,6 +170,27 @@ private static function removeDuplicateVersionConstraints(string $versionConstra
}, $orConstraints)));
}

private static function removeLeadingVCharacter(string $versionConstraint): string
{
$split = \explode(
' ',
$versionConstraint,
);

foreach ($split as &$part) {
$part = \preg_replace(
'{^(|[!<>]=|[~<>^])v(\d+.*)$}',
'$1$2',
$part,
);
}

return \implode(
' ',
$split,
);
}

private static function removeOverlappingVersionConstraints(string $versionConstraint): string
{
$orConstraints = self::splitIntoOrConstraints($versionConstraint);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#caret-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-caret-stable/01-major-trimmed": "^1",
"leading-v-caret-stable/02-major-untrimmed": "^1",
"leading-v-caret-stable/03-major-minor-trimmed": "^1.2",
"leading-v-caret-stable/04-major-minor-untrimmed": "^1.2",
"leading-v-caret-stable/05-major-minor-patch-trimmed": "^1.2.3",
"leading-v-caret-stable/06-major-minor-patch-untrimmed": "^1.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#caret-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-caret-stable/01-major-trimmed": "^v1",
"leading-v-caret-stable/02-major-untrimmed": " ^v1 ",
"leading-v-caret-stable/03-major-minor-trimmed": "^v1.2",
"leading-v-caret-stable/04-major-minor-untrimmed": " ^v1.2 ",
"leading-v-caret-stable/05-major-minor-patch-trimmed": "^v1.2.3",
"leading-v-caret-stable/06-major-minor-patch-untrimmed": " ^v1.2.3 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#caret-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-caret-unstable/01-major-trimmed": "^0",
"leading-v-caret-unstable/02-major-untrimmed": "^0",
"leading-v-caret-unstable/03-major-minor-trimmed": "^0.1",
"leading-v-caret-unstable/04-major-minor-untrimmed": "^0.1",
"leading-v-caret-unstable/05-major-minor-patch-trimmed": "^0.1.2",
"leading-v-caret-unstable/06-major-minor-patch-untrimmed": "^0.1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#caret-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-caret-unstable/01-major-trimmed": "^v0",
"leading-v-caret-unstable/02-major-untrimmed": " ^v0 ",
"leading-v-caret-unstable/03-major-minor-trimmed": "^v0.1",
"leading-v-caret-unstable/04-major-minor-untrimmed": " ^v0.1 ",
"leading-v-caret-unstable/05-major-minor-patch-trimmed": "^v0.1.2",
"leading-v-caret-unstable/06-major-minor-patch-untrimmed": " ^v0.1.2 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#exact-version-constraint",
"value-contains-packages-and-version-constraints": {
"leading-v-exact-version-stable/01-major-trimmed": "1",
"leading-v-exact-version-stable/02-major-untrimmed": "1",
"leading-v-exact-version-stable/03-major-minor-trimmed": "1.2",
"leading-v-exact-version-stable/04-major-minor-untrimmed": "1.2",
"leading-v-exact-version-stable/05-major-minor-patch-trimmed": "1.2.3",
"leading-v-exact-version-stable/06-major-minor-patch-untrimmed": "1.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#exact-version-constraint",
"value-contains-packages-and-version-constraints": {
"leading-v-exact-version-stable/01-major-trimmed": "v1",
"leading-v-exact-version-stable/02-major-untrimmed": " v1 ",
"leading-v-exact-version-stable/03-major-minor-trimmed": "v1.2",
"leading-v-exact-version-stable/04-major-minor-untrimmed": " v1.2 ",
"leading-v-exact-version-stable/05-major-minor-patch-trimmed": "v1.2.3",
"leading-v-exact-version-stable/06-major-minor-patch-untrimmed": " v1.2.3 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#exact-version-constraint",
"value-contains-packages-and-version-constraints": {
"leading-v-exact-version-unstable/01-major-trimmed": "0",
"leading-v-exact-version-unstable/02-major-untrimmed": "0",
"leading-v-exact-version-unstable/03-major-minor-trimmed": "0.1",
"leading-v-exact-version-unstable/04-major-minor-untrimmed": "0.1",
"leading-v-exact-version-unstable/05-major-minor-patch-trimmed": "0.1.2",
"leading-v-exact-version-unstable/06-major-minor-patch-untrimmed": "0.1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#exact-version-constraint",
"value-contains-packages-and-version-constraints": {
"leading-v-exact-version-unstable/01-major-trimmed": "v0",
"leading-v-exact-version-unstable/02-major-untrimmed": " v0 ",
"leading-v-exact-version-unstable/03-major-minor-trimmed": "v0.1",
"leading-v-exact-version-unstable/04-major-minor-untrimmed": " v0.1 ",
"leading-v-exact-version-unstable/05-major-minor-patch-trimmed": "v0.1.2",
"leading-v-exact-version-unstable/06-major-minor-patch-untrimmed": " v0.1.2 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-stable/01-major-trimmed": ">1",
"leading-v-greater-than-stable/02-major-untrimmed": ">1",
"leading-v-greater-than-stable/03-major-minor-trimmed": ">1.2",
"leading-v-greater-than-stable/04-major-minor-untrimmed": ">1.2",
"leading-v-greater-than-stable/05-major-minor-patch-trimmed": ">1.2.3",
"leading-v-greater-than-stable/06-major-minor-patch-untrimmed": ">1.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-stable/01-major-trimmed": ">v1",
"leading-v-greater-than-stable/02-major-untrimmed": " >v1 ",
"leading-v-greater-than-stable/03-major-minor-trimmed": " >v1.2 ",
"leading-v-greater-than-stable/04-major-minor-untrimmed": " >v1.2 ",
"leading-v-greater-than-stable/05-major-minor-patch-trimmed": ">v1.2.3",
"leading-v-greater-than-stable/06-major-minor-patch-untrimmed": " >v1.2.3 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-unstable/01-major-trimmed": ">0",
"leading-v-greater-than-unstable/02-major-untrimmed": ">0",
"leading-v-greater-than-unstable/03-major-minor-trimmed": ">0.1",
"leading-v-greater-than-unstable/04-major-minor-untrimmed": ">0.1",
"leading-v-greater-than-unstable/05-major-minor-patch-trimmed": ">0.1.2",
"leading-v-greater-than-unstable/06-major-minor-patch-untrimmed": ">0.1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-unstable/01-major-trimmed": ">v0",
"leading-v-greater-than-unstable/02-major-untrimmed": " >v0 ",
"leading-v-greater-than-unstable/03-major-minor-trimmed": " >v0.1 ",
"leading-v-greater-than-unstable/04-major-minor-untrimmed": " >v0.1 ",
"leading-v-greater-than-unstable/05-major-minor-patch-trimmed": ">v0.1.2",
"leading-v-greater-than-unstable/06-major-minor-patch-untrimmed": " >v0.1.2 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-or-equal-stable/01-major-trimmed": ">=1",
"leading-v-greater-than-or-equal-stable/02-major-untrimmed": ">=1",
"leading-v-greater-than-or-equal-stable/03-major-minor-trimmed": ">=1.2",
"leading-v-greater-than-or-equal-stable/04-major-minor-untrimmed": ">=1.2",
"leading-v-greater-than-or-equal-stable/05-major-minor-patch-trimmed": ">=1.2.3",
"leading-v-greater-than-or-equal-stable/06-major-minor-patch-untrimmed": ">=1.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-or-equal-stable/01-major-trimmed": ">=v1",
"leading-v-greater-than-or-equal-stable/02-major-untrimmed": " >=v1 ",
"leading-v-greater-than-or-equal-stable/03-major-minor-trimmed": " >=v1.2 ",
"leading-v-greater-than-or-equal-stable/04-major-minor-untrimmed": " >=v1.2 ",
"leading-v-greater-than-or-equal-stable/05-major-minor-patch-trimmed": ">=v1.2.3",
"leading-v-greater-than-or-equal-stable/06-major-minor-patch-untrimmed": " >=v1.2.3 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-or-equal-unstable/01-major-trimmed": ">=0",
"leading-v-greater-than-or-equal-unstable/02-major-untrimmed": ">=0",
"leading-v-greater-than-or-equal-unstable/03-major-minor-trimmed": ">=0.1",
"leading-v-greater-than-or-equal-unstable/04-major-minor-untrimmed": ">=0.1",
"leading-v-greater-than-or-equal-unstable/05-major-minor-patch-trimmed": ">=0.1.2",
"leading-v-greater-than-or-equal-unstable/06-major-minor-patch-untrimmed": ">=0.1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-greater-than-or-equal-unstable/01-major-trimmed": ">=v0",
"leading-v-greater-than-or-equal-unstable/02-major-untrimmed": " >=v0 ",
"leading-v-greater-than-or-equal-unstable/03-major-minor-trimmed": " >=v0.1 ",
"leading-v-greater-than-or-equal-unstable/04-major-minor-untrimmed": " >=v0.1 ",
"leading-v-greater-than-or-equal-unstable/05-major-minor-patch-trimmed": ">=v0.1.2",
"leading-v-greater-than-or-equal-unstable/06-major-minor-patch-untrimmed": " >=v0.1.2 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#hyphenated-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-hyphenated-stable/01-major-surrounded-by-space-single-trimmed": "1 - 2",
"leading-v-hyphenated-stable/02-major-surrounded-by-space-single-untrimmed": "1 - 2",
"leading-v-hyphenated-stable/03-major-surrounded-by-space-double-trimmed": "1 - 2",
"leading-v-hyphenated-stable/04-major-surrounded-by-space-double-untrimmed": "1 - 2",
"leading-v-hyphenated-stable/05-major-minor-surrounded-by-space-single-trimmed": "1.2 - 2.3",
"leading-v-hyphenated-stable/06-major-minor-surrounded-by-space-single-untrimmed": "1.2 - 2.3",
"leading-v-hyphenated-stable/07-major-minor-surrounded-by-space-double-trimmed": "1.2 - 2.3",
"leading-v-hyphenated-stable/08-major-minor-surrounded-by-space-double-untrimmed": "1.2 - 2.3",
"leading-v-hyphenated-stable/09-major-minor-patch-surrounded-by-space-single-trimmed": "1.2.3 - 2.3.4",
"leading-v-hyphenated-stable/10-major-minor-patch-surrounded-by-space-single-untrimmed": "1.2.3 - 2.3.4",
"leading-v-hyphenated-stable/11-major-minor-patch-surrounded-by-space-double-trimmed": "1.2.3 - 2.3.4",
"leading-v-hyphenated-stable/12-major-minor-patch-surrounded-by-space-double-untrimmed": "1.2.3 - 2.3.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#hyphenated-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-hyphenated-stable/01-major-surrounded-by-space-single-trimmed": "v1 - v2",
"leading-v-hyphenated-stable/02-major-surrounded-by-space-single-untrimmed": " v1 - v2 ",
"leading-v-hyphenated-stable/03-major-surrounded-by-space-double-trimmed": "v1 - v2",
"leading-v-hyphenated-stable/04-major-surrounded-by-space-double-untrimmed": " v1 - v2 ",
"leading-v-hyphenated-stable/05-major-minor-surrounded-by-space-single-trimmed": "v1.2 - v2.3",
"leading-v-hyphenated-stable/06-major-minor-surrounded-by-space-single-untrimmed": " v1.2 - v2.3 ",
"leading-v-hyphenated-stable/07-major-minor-surrounded-by-space-double-trimmed": "v1.2 - v2.3",
"leading-v-hyphenated-stable/08-major-minor-surrounded-by-space-double-untrimmed": " v1.2 - v2.3 ",
"leading-v-hyphenated-stable/09-major-minor-patch-surrounded-by-space-single-trimmed": "v1.2.3 - v2.3.4",
"leading-v-hyphenated-stable/10-major-minor-patch-surrounded-by-space-single-untrimmed": " v1.2.3 - v2.3.4 ",
"leading-v-hyphenated-stable/11-major-minor-patch-surrounded-by-space-double-trimmed": "v1.2.3 - v2.3.4",
"leading-v-hyphenated-stable/12-major-minor-patch-surrounded-by-space-double-untrimmed": " v1.2.3 - v2.3.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#hyphenated-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-hyphenated-unstable/01-major-minor-surrounded-by-space-single-trimmed": "0.1 - 0.2",
"leading-v-hyphenated-unstable/02-major-minor-surrounded-by-space-single-untrimmed": "0.1 - 0.2",
"leading-v-hyphenated-unstable/03-major-minor-surrounded-by-space-double-trimmed": "0.1 - 0.2",
"leading-v-hyphenated-unstable/04-major-minor-surrounded-by-space-double-untrimmed": "0.1 - 0.2",
"leading-v-hyphenated-unstable/05-major-minor-patch-surrounded-by-space-single-trimmed": "0.1.2 - 0.2.3",
"leading-v-hyphenated-unstable/06-major-minor-patch-surrounded-by-space-single-untrimmed": "0.1.2 - 0.2.3",
"leading-v-hyphenated-unstable/07-major-minor-patch-surrounded-by-space-double-trimmed": "0.1.2 - 0.2.3",
"leading-v-hyphenated-unstable/08-major-minor-patch-surrounded-by-space-double-untrimmed": "0.1.2 - 0.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#hyphenated-version-range-",
"value-contains-packages-and-version-constraints": {
"leading-v-hyphenated-unstable/01-major-minor-surrounded-by-space-single-trimmed": "v0.1 - v0.2",
"leading-v-hyphenated-unstable/02-major-minor-surrounded-by-space-single-untrimmed": " v0.1 - v0.2 ",
"leading-v-hyphenated-unstable/03-major-minor-surrounded-by-space-double-trimmed": "v0.1 - v0.2",
"leading-v-hyphenated-unstable/04-major-minor-surrounded-by-space-double-untrimmed": " v0.1 - v0.2 ",
"leading-v-hyphenated-unstable/05-major-minor-patch-surrounded-by-space-single-trimmed": "v0.1.2 - v0.2.3",
"leading-v-hyphenated-unstable/06-major-minor-patch-surrounded-by-space-single-untrimmed": " v0.1.2 - v0.2.3 ",
"leading-v-hyphenated-unstable/07-major-minor-patch-surrounded-by-space-double-trimmed": "v0.1.2 - v0.2.3",
"leading-v-hyphenated-unstable/08-major-minor-patch-surrounded-by-space-double-untrimmed": " v0.1.2 - v0.2.3 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-less-than-stable/01-major-trimmed": "<1",
"leading-v-less-than-stable/02-major-untrimmed": "<1",
"leading-v-less-than-stable/03-major-minor-trimmed": "<1.2",
"leading-v-less-than-stable/04-major-minor-untrimmed": "<1.2",
"leading-v-less-than-stable/05-major-minor-patch-trimmed": "<1.2.3",
"leading-v-less-than-stable/06-major-minor-patch-untrimmed": "<1.2.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-less-than-stable/01-major-trimmed": "<v1",
"leading-v-less-than-stable/02-major-untrimmed": " <v1 ",
"leading-v-less-than-stable/03-major-minor-trimmed": " <v1.2 ",
"leading-v-less-than-stable/04-major-minor-untrimmed": " <v1.2 ",
"leading-v-less-than-stable/05-major-minor-patch-trimmed": "<v1.2.3",
"leading-v-less-than-stable/06-major-minor-patch-untrimmed": " <v1.2.3 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-less-than-unstable/01-major-trimmed": "<0",
"leading-v-less-than-unstable/02-major-untrimmed": "<0",
"leading-v-less-than-unstable/03-major-minor-trimmed": "<0.1",
"leading-v-less-than-unstable/04-major-minor-untrimmed": "<0.1",
"leading-v-less-than-unstable/05-major-minor-patch-trimmed": "<0.1.2",
"leading-v-less-than-unstable/06-major-minor-patch-untrimmed": "<0.1.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-less-than-unstable/01-major-trimmed": "<v0",
"leading-v-less-than-unstable/02-major-untrimmed": " <v0 ",
"leading-v-less-than-unstable/03-major-minor-trimmed": " <v0.1 ",
"leading-v-less-than-unstable/04-major-minor-untrimmed": " <v0.1 ",
"leading-v-less-than-unstable/05-major-minor-patch-trimmed": "<v0.1.2",
"leading-v-less-than-unstable/06-major-minor-patch-untrimmed": " <v0.1.2 "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"homepage": "https://getcomposer.org/doc/articles/versions.md#version-range",
"value-contains-packages-and-version-constraints": {
"leading-v-less-than-or-equal-stable/01-major-trimmed": "<=1",
"leading-v-less-than-or-equal-stable/02-major-untrimmed": "<=1",
"leading-v-less-than-or-equal-stable/03-major-minor-trimmed": "<=1.2",
"leading-v-less-than-or-equal-stable/04-major-minor-untrimmed": "<=1.2",
"leading-v-less-than-or-equal-stable/05-major-minor-patch-trimmed": "<=1.2.3",
"leading-v-less-than-or-equal-stable/06-major-minor-patch-untrimmed": "<=1.2.3"
}
}
Loading

0 comments on commit fce443f

Please sign in to comment.