Skip to content

Commit cdbd295

Browse files
authored
[Feature] Add Rule "changelog_has_new_release" (#63)
* parsing release * no generate docs for no described parameters * optimize search type * fix lint * change rule * virtual default value * default value * wrap def val * lint when 2 lines modified * up test * check old tags * add test for set * add test for release parser * add test * improve set * remove empty comments from src/ * fix stat analyse * up version * test * print filename
1 parent 4bdc7d5 commit cdbd295

File tree

279 files changed

+945
-615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+945
-615
lines changed

.mr-linter.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rules:
1717

1818
"@mr-linter/description_not_empty": {}
1919

20-
"@mr-linter/update_changelog":
20+
"@mr-linter/changelog_has_new_release":
2121
when:
2222
targetBranch:
2323
equals: "master"

CHANGELOG.md

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ This file contains changelogs.
66

77
-----------------------------------------------------------------
88

9+
## [v0.19.0 (2023-09-11)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.18.1..0.19.0)
10+
11+
### Added
12+
* Added Rule `@mr-linter/changelog_has_new_release` on contains new release
13+
14+
### Removed
15+
* Removed Rule `@mr-linter/update_changelog`
16+
17+
[💾 Assets](https://github.com/ArtARTs36/php-merge-request-linter/releases/tag/0.19.0)
18+
19+
-----------------------------------------------------------------
20+
921
## [v0.18.1 (2023-09-04)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.18.0..0.18.1)
1022

1123
### Added
@@ -15,8 +27,6 @@ This file contains changelogs.
1527

1628
-----------------------------------------------------------------
1729

18-
-----------------------------------------------------------------
19-
2030
## [v0.18.0 (2023-09-03)](https://github.com/ArtARTs36/php-merge-request-linter/compare/0.17.1..0.18.0)
2131

2232
### Added

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ docs:
9292

9393
docs-docker: docker-build
9494
docker run \
95+
--rm \
9596
--volume ./:/app \
9697
--env-file .env \
9798
--entrypoint "make" \
@@ -132,6 +133,7 @@ lint-docker: docker-build
132133

133134
lint-fix-docker: docker-build
134135
docker run \
136+
--rm \
135137
--volume ./:/app/ \
136138
--env-file .env \
137139
--entrypoint "composer" \

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"require": {
1212
"php": "^8.2",
13-
"artarts36/str": "^2.4.1",
13+
"artarts36/str": "^2.5.0",
1414
"symfony/console": "^4.0 | ^5.0 | ^6.0",
1515
"guzzlehttp/psr7": "^2",
1616
"artarts36/local-file-system": "^0.1.2",

composer.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/Builder/ConfigJsonSchema/RuleParamMetadata.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @param array<string|int> $enum
1313
* @param array<RuleParamMetadata> $nestedObjectParams
1414
* @param array<RuleParamMetadata> $genericObjectParams
15+
* @param array<mixed> $virtualDefaultValues
1516
*/
1617
public function __construct(
1718
public string $name,
@@ -25,6 +26,7 @@ public function __construct(
2526
public array $genericObjectParams,
2627
public mixed $defaultValue,
2728
public bool $hasDefaultValue,
29+
public array $virtualDefaultValues,
2830
) {
2931
}
3032
}

docs/Builder/ConfigJsonSchema/RulesMetadataLoader.php

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ private function buildParams(string $class): array
4949
$metadataParams = [];
5050

5151
foreach ($params as $param) {
52+
if ($param->description === '') {
53+
continue;
54+
}
55+
5256
$enumValues = [];
5357

5458
if ($param->type->class !== null && enum_exists($param->type->class)) {
@@ -82,6 +86,7 @@ private function buildParams(string $class): array
8286
$genericObject,
8387
$param->hasDefaultValue ? $param->getDefaultValue() : null,
8488
$param->hasDefaultValue,
89+
$param->getVirtualDefaultValues(),
8590
);
8691
}
8792

docs/Builder/RulesPageBuilder.php

+23-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use ArtARTs36\MergeRequestLinter\Infrastructure\Text\Renderer\TwigRenderer;
1010
use ArtARTs36\MergeRequestLinter\Shared\DataStructure\Arrayee;
1111
use ArtARTs36\MergeRequestLinter\Shared\DataStructure\Collection;
12+
use ArtARTs36\MergeRequestLinter\Shared\Reflection\Reflector\Reflector;
1213

1314
class RulesPageBuilder
1415
{
@@ -79,15 +80,23 @@ private function buildParams(array $metadataParams, bool &$ruleHasParamsExamples
7980
$name = $prefix . '.' . $param->name;
8081
}
8182

83+
$defaultValues = $this->resolveDefaultValues($param);
84+
85+
$isRequired = $param->required && count($defaultValues) === 0;
86+
87+
if ($isRequired && $param->type->isClass()) {
88+
$isRequired = ! Reflector::canConstructWithoutParameters($param->type->class);
89+
}
90+
8291
$params[] = [
8392
'name' => $name,
8493
'type' => $param->jsonType,
85-
'required' => $param->required,
94+
'required' => $isRequired,
8695
'generic' => $param->type->isGeneric() ? JsonType::to($param->type->generic) : null,
8796
'description' => $param->description,
8897
'examples' => $examples,
8998
'isGenericObject' => $param->type->generic && class_exists($param->type->generic),
90-
'defaultValue' => $this->resolveDefaultValue($param),
99+
'defaultValues' => $defaultValues,
91100
];
92101

93102
if ($param->type->isGeneric()) {
@@ -107,8 +116,8 @@ private function buildParams(array $metadataParams, bool &$ruleHasParamsExamples
107116
'generic' => $param->type->isGeneric() ? JsonType::to($param->type->generic) : null,
108117
'description' => $param->description,
109118
'examples' => $examples,
110-
'isGenericObject' => $param->type->generic && class_exists($param->type->generic),
111-
'defaultValue' => $this->resolveDefaultValue($param),
119+
'isGenericObject' => true,
120+
'defaultValues' => new Arrayee($this->resolveDefaultValues($param)),
112121
];
113122

114123
$params = array_merge($params, $this->buildParams(
@@ -129,24 +138,28 @@ private function buildParams(array $metadataParams, bool &$ruleHasParamsExamples
129138
return $params;
130139
}
131140

132-
private function resolveDefaultValue(RuleParamMetadata $param): mixed
141+
private function resolveDefaultValues(RuleParamMetadata $param): array
133142
{
143+
if (count($param->virtualDefaultValues) > 0) {
144+
return $param->virtualDefaultValues;
145+
}
146+
134147
if (! $param->hasDefaultValue) {
135-
return 'none';
148+
return [];
136149
}
137150

138151
if ($param->type->class !== null) {
139152
if (is_a($param->type->class, Collection::class, true)) {
140-
return 'none';
153+
return [];
141154
}
142155

143156
if (enum_exists($param->type->class)) {
144-
return $param->defaultValue->value;
157+
return [$param->defaultValue->value];
145158
}
146159

147-
return $param->defaultValue;
160+
return [$param->defaultValue];
148161
}
149162

150-
return $param->defaultValue;
163+
return [$param->defaultValue];
151164
}
152165
}

docs/Builder/templates/rules.md.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ The following rules are available:
2828
| Name | Description | Type | Required | Default value | Examples |
2929
|------|-------------|------|----------|---------------|----------|
3030
{% for param in rule.params %}
31-
| {{ param.name }} | {{ param.description }} | {{ param.type }} {% if param.generic %} of {{ param.generic }}s {% endif %} | {{ param.required ? 'true' : 'false' }} | {{ param.defaultValue }} | {% for example in param.examples %} {{ example }}{% if loop.last == false %},{% endif%} {% endfor %} |
31+
| {{ param.name }} | {{ param.description }} | {{ param.type }} {% if param.generic %} of {{ param.generic }}s {% endif %} | {{ param.required ? 'true' : 'false' }} | {% if param.defaultValues.isEmpty %} none {% else %}{% for defValue in param.defaultValues %}{% if defValue is iterable %}`[{{ defValue | join(', ') }}]`{% else %}{% if defValue is null %}NULL{% else %}`{{ defValue }}`{% endif %}{% endif%} {% endfor %}{% endif %} | {% for example in param.examples %} {{ example }}{% if loop.last == false %},{% endif%} {% endfor %} |
3232
{% endfor %}
3333
{% else %}
3434
| Name | Description | Type | Required | Default value |
3535
|------|-------------|------|----------|---------------|
3636
{% for param in rule.params %}
37-
| {{ param.name }} | {{ param.description }} | {{ param.type }} {% if param.generic %} of {{ param.generic }}s {% endif %} | {{ param.required ? 'true' : 'false' }} | {{ param.defaultValue }} |
37+
| {{ param.name }} | {{ param.description }} | {{ param.type }} {% if param.generic %} of {{ param.generic }}s {% endif %} | {{ param.required ? 'true' : 'false' }} | {% if param.defaultValues.isEmpty %} none {% else %}{% for defValue in param.defaultValues %}{% if defValue is iterable %}`[{{ defValue | join(', ') }}]`{% else %}{% if defValue is null %}NULL{% else %}`{{ defValue }}`{% endif %}{% endif%} {% endfor %}{% endif %} |
3838
{% endfor %}
3939
{% endif %}
4040
{% endif %}

0 commit comments

Comments
 (0)