Skip to content

Commit 55736ef

Browse files
author
Konrad Michalik
authored
Merge pull request #74 from move-elevator/disable-duplicate-values-validator
feat: skip DuplicateValuesValidator by default
2 parents 412eb18 + bc46080 commit 55736ef

6 files changed

Lines changed: 110 additions & 19 deletions

File tree

docs/config-file.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ to customize validation behavior, specify paths and control which validators are
88
>
99
> See the [JSON Schema](../schema/translation-validator.schema.json) section for more details.
1010
11+
> [!NOTE]
12+
> **DuplicateValuesValidator is disabled by default** (opt-in)
13+
>
14+
> The `DuplicateValuesValidator` is skipped by default to reduce noise in validation results.
15+
> You can enable it by explicitly including it in the `only` option or by setting an empty `skip` array.
16+
1117
See the [Configuration Schema](schema.md) for details on available options.
1218

1319
## Formats
@@ -42,6 +48,37 @@ $config->setPaths(['translations/', 'locale/'])
4248
return $config;
4349
```
4450

51+
### Enabling DuplicateValuesValidator
52+
53+
To enable the `DuplicateValuesValidator`, explicitly include it in the `only` option:
54+
55+
```php
56+
<?php
57+
58+
declare(strict_types=1);
59+
60+
use MoveElevator\ComposerTranslationValidator\Config\TranslationValidatorConfig;
61+
use MoveElevator\ComposerTranslationValidator\Validator\DuplicateValuesValidator;
62+
63+
$config = new TranslationValidatorConfig();
64+
$config->setPaths(['translations/'])
65+
->setOnly([
66+
DuplicateValuesValidator::class,
67+
]);
68+
69+
return $config;
70+
```
71+
72+
Or remove it from the skip list:
73+
74+
```php
75+
$config = new TranslationValidatorConfig();
76+
$config->setPaths(['translations/'])
77+
->setSkip([]); // Empty skip list enables all validators including DuplicateValuesValidator
78+
79+
return $config;
80+
```
81+
4582
## Configuration in JSON file
4683

4784
Create a JSON file with the following structure:
@@ -79,6 +116,28 @@ Create a JSON file with the following structure:
79116
}
80117
```
81118

119+
### Enabling DuplicateValuesValidator in JSON
120+
121+
To enable the `DuplicateValuesValidator`:
122+
123+
```json
124+
{
125+
"paths": ["translations/"],
126+
"skip": []
127+
}
128+
```
129+
130+
Or use the `only` option:
131+
132+
```json
133+
{
134+
"paths": ["translations/"],
135+
"only": [
136+
"MoveElevator\\ComposerTranslationValidator\\Validator\\DuplicateValuesValidator"
137+
]
138+
}
139+
```
140+
82141
## Configuration in YAML file
83142

84143
Create a YAML file with the following structure:
@@ -114,6 +173,25 @@ format: cli
114173
verbose: false
115174
```
116175
176+
### Enabling DuplicateValuesValidator in YAML
177+
178+
To enable the `DuplicateValuesValidator`:
179+
180+
```yaml
181+
paths:
182+
- translations/
183+
skip: []
184+
```
185+
186+
Or use the `only` option:
187+
188+
```yaml
189+
paths:
190+
- translations/
191+
only:
192+
- MoveElevator\ComposerTranslationValidator\Validator\DuplicateValuesValidator
193+
```
194+
117195
## Configuration in composer.json
118196

119197
You can also specify the path to a configuration file in your `composer.json`:

docs/validators.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,27 @@ Identifies identical translation values that might indicate copy-paste errors or
8585

8686
**Result:** ![Warning](https://img.shields.io/badge/WARNING-yellow)
8787

88+
> [!NOTE]
89+
> This validator is disabled by default (opt-in).
90+
91+
The `DuplicateValuesValidator` is skipped by default to reduce noise in validation results, as duplicate values are often intentional (e.g., common button labels like "OK" or "Cancel").
92+
93+
To enable this validator, use one of the following methods:
94+
95+
**Via CLI:**
96+
```bash
97+
composer validate-translations translations/ --only "MoveElevator\\ComposerTranslationValidator\\Validator\\DuplicateValuesValidator"
98+
```
99+
100+
**Clear the skip entry via configuration file (YAML):**
101+
```yaml
102+
paths:
103+
- translations/
104+
skip: []
105+
```
106+
107+
See the [configuration documentation](config-file.md) for more details.
108+
88109
### Example
89110
90111
**File: `errors.en.yaml`**
@@ -121,19 +142,7 @@ composer -d tests validate-translations Fixtures/examples/duplicate-values --onl
121142
</details>
122143

123144
> [!TIP]
124-
> While sometimes duplicate values are intentional, they often reveal incomplete translations or copy-paste mistakes.
125-
> If you want to suppress these warnings, you can skip this validator using the `--skip` option or using the configuration file.
126-
>
127-
> Example command to skip this validator:
128-
> ```bash
129-
> composer validate-translations ./translations --skip "MoveElevator\\ComposerTranslationValidator\\Validator\\DuplicateValuesValidator"
130-
> ```
131-
>
132-
> or within your configuration file , e.g. `translation-validator.yaml`:
133-
> ```yaml
134-
> skip:
135-
> - MoveElevator\ComposerTranslationValidator\Validator\DuplicateKeysValidator
136-
> ```
145+
> While sometimes duplicate values are intentional (e.g., common UI elements like "OK", "Cancel", or "Close"), they often reveal incomplete translations or copy-paste mistakes that need attention.
137146
138147
---
139148

src/Command/ValidateTranslationCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function configure(): void
120120
<comment>Available Validators:</comment>
121121
• <info>MismatchValidator</info> - Detects mismatches between source and target
122122
• <info>DuplicateKeysValidator</info> - Finds duplicate translation keys
123-
• <info>DuplicateValuesValidator</info> - Finds duplicate translation values
123+
• <info>DuplicateValuesValidator</info> - Finds duplicate translation values (opt-in, disabled by default)
124124
• <info>EmptyValuesValidator</info> - Finds empty or whitespace-only translation values
125125
• <info>EncodingValidator</info> - Validates file encoding and character issues
126126
• <info>HtmlTagValidator</info> - Validates HTML tag consistency across translations

src/Config/TranslationValidatorConfig.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace MoveElevator\ComposerTranslationValidator\Config;
1515

16+
use MoveElevator\ComposerTranslationValidator\Validator\DuplicateValuesValidator;
17+
1618
/**
1719
* TranslationValidatorConfig.
1820
*
@@ -37,7 +39,9 @@ class TranslationValidatorConfig
3739
private array $only = [];
3840

3941
/** @var string[] */
40-
private array $skip = [];
42+
private array $skip = [
43+
DuplicateValuesValidator::class,
44+
];
4145

4246
/** @var string[] */
4347
private array $exclude = [];

tests/src/Config/ConfigFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testCreateFromArrayWithEmptyData(): void
7373
$this->assertSame([], $config->getFileDetectors());
7474
$this->assertSame([], $config->getParsers());
7575
$this->assertSame([], $config->getOnly());
76-
$this->assertSame([], $config->getSkip());
76+
$this->assertSame([\MoveElevator\ComposerTranslationValidator\Validator\DuplicateValuesValidator::class], $config->getSkip());
7777
$this->assertSame([], $config->getExclude());
7878
$this->assertFalse($config->getStrict());
7979
$this->assertFalse($config->getDryRun());

tests/src/Config/TranslationValidatorConfigTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testSkipAndGetSkip(): void
106106
{
107107
$validator = 'SkipValidator';
108108
$this->config->skip($validator);
109-
$this->assertSame([$validator], $this->config->getSkip());
109+
$this->assertSame([\MoveElevator\ComposerTranslationValidator\Validator\DuplicateValuesValidator::class, $validator], $this->config->getSkip());
110110
}
111111

112112
public function testSetAndGetSkip(): void
@@ -164,7 +164,7 @@ public function testDefaultValues(): void
164164
$this->assertSame([], $this->config->getFileDetectors());
165165
$this->assertSame([], $this->config->getParsers());
166166
$this->assertSame([], $this->config->getOnly());
167-
$this->assertSame([], $this->config->getSkip());
167+
$this->assertSame([\MoveElevator\ComposerTranslationValidator\Validator\DuplicateValuesValidator::class], $this->config->getSkip());
168168
$this->assertSame([], $this->config->getExclude());
169169
$this->assertFalse($this->config->getStrict());
170170
$this->assertFalse($this->config->getDryRun());
@@ -264,7 +264,7 @@ public function testToArrayWithDefaultValues(): void
264264
'file-detectors' => [],
265265
'parsers' => [],
266266
'only' => [],
267-
'skip' => [],
267+
'skip' => [\MoveElevator\ComposerTranslationValidator\Validator\DuplicateValuesValidator::class],
268268
'exclude' => [],
269269
'strict' => false,
270270
'dry-run' => false,

0 commit comments

Comments
 (0)