Skip to content

Commit 7da19b6

Browse files
committed
Eases language-specific preset definitions
1 parent ba28924 commit 7da19b6

File tree

7 files changed

+124
-125
lines changed

7 files changed

+124
-125
lines changed

src/Presets/CommonPreset.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stolt\LeanPackage\Presets;
6+
7+
class CommonPreset
8+
{
9+
protected function getCommonGlob(): array
10+
{
11+
return [
12+
'.*',
13+
'*.txt',
14+
'*.{md,MD}',
15+
'*.rst',
16+
'*.toml',
17+
'*.xml',
18+
'*.yml',
19+
'*.dist.*',
20+
'llms.*',
21+
'*.dist',
22+
'{B,b}uild*',
23+
'{D,d}ist',
24+
'{D,d}oc*',
25+
'{A,a}rt*',
26+
'{A,a}sset*',
27+
'{T,t}ool*',
28+
'{T,t}est*',
29+
'{S,s}pec*',
30+
'{E,e}xample*',
31+
'LICENSE',
32+
'{M,m}ake',
33+
'*.{png,gif,jpeg,jpg,webp}',
34+
];
35+
}
36+
}

src/Presets/Finder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ public function getAvailablePresets(): array
2525
{
2626
$dir = new \DirectoryIterator(\dirname(__FILE__));
2727
$availablePresets = [];
28+
2829
foreach ($dir as $fileinfo) {
2930
if (!$fileinfo->isDot()) {
3031
$presetsParts = \explode(self::PRESET_SUFFIX, $fileinfo->getBasename());
3132
if (\count($presetsParts) == 2) {
33+
if ($presetsParts[0] === 'Common') {
34+
continue;
35+
}
3236
$availablePresets[] = $presetsParts[0];
3337
}
3438
}

src/Presets/GoPreset.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,17 @@
66

77
use Stolt\LeanPackage\Preset;
88

9-
final class GoPreset implements Preset
9+
final class GoPreset extends CommonPreset implements Preset
1010
{
1111
public function getPresetGlob(): array
1212
{
13-
return [
14-
'.*',
15-
'*.lock',
16-
'*.txt',
17-
'*.rst',
18-
'*.{md,MD}',
19-
'*.xml',
20-
'*.yml',
21-
'*.dist.*',
22-
'*.dist',
23-
'{B,b}uild*',
24-
'{D,d}oc*',
25-
'{T,t}ool*',
26-
'{T,t}est*',
27-
'{S,s}pec*',
28-
'{E,e}xample*',
29-
'LICENSE',
30-
'{{M,m}ake,{V,v}agrant'
31-
];
13+
return \array_unique(\array_merge($this->getCommonGlob(), [
14+
'go.*',
15+
'cmd/**',
16+
'pkg/**',
17+
'internal/**',
18+
'*.go',
19+
'*_test.go',
20+
]));
3221
}
3322
}

src/Presets/PhpPreset.php

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,12 @@
66

77
use Stolt\LeanPackage\Preset;
88

9-
final class PhpPreset implements Preset
9+
final class PhpPreset extends CommonPreset implements Preset
1010
{
1111
public function getPresetGlob(): array
1212
{
13-
return [
14-
'.*',
13+
return \array_unique(\array_merge($this->getCommonGlob(), [
1514
'*.lock',
16-
'*.txt',
17-
'*.rst',
18-
'*.{md,MD}',
19-
'*.{png,gif,jpeg,jpg,webp}',
20-
'*.xml',
21-
'*.yml',
22-
'*.toml',
2315
'phpunit*',
2416
'appveyor.yml',
2517
'box.json',
@@ -37,20 +29,8 @@ public function getPresetGlob(): array
3729
'renovate.json',
3830
'*debugbar.json',
3931
'ecs*',
40-
'llms.*',
41-
'*.dist.*',
42-
'*.dist',
43-
'{B,b}uild*',
44-
'{D,d}oc*',
45-
'{T,t}ool*',
46-
'{T,t}est*',
47-
'{S,s}pec*',
48-
'{A,a}rt*',
49-
'{A,a}sset*',
50-
'{E,e}xample*',
51-
'LICENSE',
52-
'{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file',
53-
'RMT'
54-
];
32+
'RMT',
33+
'{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file'
34+
]));
5535
}
5636
}

src/Presets/PythonPreset.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,16 @@
66

77
use Stolt\LeanPackage\Preset;
88

9-
final class PythonPreset implements Preset
9+
final class PythonPreset extends CommonPreset implements Preset
1010
{
1111
public function getPresetGlob(): array
1212
{
13-
return [
14-
'.*',
15-
'*.txt',
16-
'*.rst',
13+
return \array_unique(\array_merge($this->getCommonGlob(), [
1714
'*.py[cod]',
18-
'*.toml',
1915
'setup.*',
2016
'requirements*.txt',
2117
'Pipfile',
2218
'Pipfile.lock',
23-
'*.{md,MD}',
24-
'*.xml',
25-
'*.yml',
26-
'*.dist.*',
27-
'*.dist',
28-
'{B,b}uild*',
29-
'{D,d}oc*',
30-
'{D,d}ist',
31-
'{T,t}ool*',
32-
'{T,t}est*',
33-
'{S,s}pec*',
34-
'{E,e}xample*',
35-
'LICENSE',
36-
'{{M,m}ake'
37-
];
19+
]));
3820
}
3921
}

tests/AnalyserTest.php

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,6 @@ public function hasGitattributesFileFailsOnNonExistingGitattributesFile(): void
418418
#[Test]
419419
public function collectExpectedExportIgnoresReturnsExpectedEntries(): void
420420
{
421-
$temporaryGitattributesFile = $this->temporaryDirectory
422-
. DIRECTORY_SEPARATOR
423-
. '.gitattributes';
424-
425421
$artifactFilenames = [
426422
'README.md',
427423
'Makefile',
@@ -434,7 +430,7 @@ public function collectExpectedExportIgnoresReturnsExpectedEntries(): void
434430
['documentation']
435431
);
436432

437-
$expectedExportIgnores = [
433+
$expectedExportIgnores =[
438434
'.buildignore',
439435
'.travis.yml',
440436
'documentation/',
@@ -446,6 +442,9 @@ public function collectExpectedExportIgnoresReturnsExpectedEntries(): void
446442

447443
$actualExportIgnores = $analyser->collectExpectedExportIgnores();
448444

445+
\sort($expectedExportIgnores);
446+
\sort($actualExportIgnores);
447+
449448
$this->assertEquals(
450449
$expectedExportIgnores,
451450
$actualExportIgnores
@@ -1526,51 +1525,58 @@ public function returnsExpectedDefaultGlobPatterns(): void
15261525
$analyser = (new Analyser(new Finder(new PhpPreset())))->setDirectory($this->temporaryDirectory);
15271526

15281527
$expectedDefaultGlobPatterns = [
1529-
'.*',
1528+
'*.dist',
1529+
'*.dist.*',
15301530
'*.lock',
1531-
'*.txt',
15321531
'*.rst',
1533-
'*.{md,MD}',
1534-
'*.{png,gif,jpeg,jpg,webp}',
1532+
'*.toml',
1533+
'*.txt',
15351534
'*.xml',
15361535
'*.yml',
1537-
'*.toml',
1538-
'phpunit*',
1539-
'appveyor.yml',
1540-
'box.json',
1541-
'composer-dependency-analyser*',
1542-
'collision-detector*',
1543-
'captainhook.json',
1544-
'peck.json',
1545-
'infection*',
1546-
'phpstan*',
1547-
'sonar*',
1548-
'rector*',
1549-
'phpkg.con*',
1550-
'package*',
1551-
'pint.json',
1552-
'renovate.json',
1553-
'*debugbar.json',
1554-
'ecs*',
1555-
'llms.*',
1556-
'*.dist.*',
1557-
'*.dist',
1558-
'{B,b}uild*',
1559-
'{D,d}oc*',
1560-
'{T,t}ool*',
1561-
'{T,t}est*',
1562-
'{S,s}pec*',
1563-
'{A,a}rt*',
1564-
'{A,a}sset*',
1565-
'{E,e}xample*',
1566-
'LICENSE',
1567-
'{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file',
1568-
'RMT'
1536+
'*.{md,MD}',
1537+
'*.{png,gif,jpeg,jpg,webp}',
1538+
'*debugbar.json',
1539+
'.*',
1540+
'LICENSE',
1541+
'RMT',
1542+
'appveyor.yml',
1543+
'box.json',
1544+
'captainhook.json',
1545+
'collision-detector*',
1546+
'composer-dependency-analyser*',
1547+
'ecs*',
1548+
'infection*',
1549+
'llms.*',
1550+
'package*',
1551+
'peck.json',
1552+
'phpkg.con*',
1553+
'phpstan*',
1554+
'phpunit*',
1555+
'pint.json',
1556+
'rector*',
1557+
'renovate.json',
1558+
'sonar*',
1559+
'{A,a}rt*',
1560+
'{A,a}sset*',
1561+
'{B,b}uild*',
1562+
'{D,d}ist',
1563+
'{D,d}oc*',
1564+
'{E,e}xample*',
1565+
'{M,m}ake',
1566+
'{S,s}pec*',
1567+
'{T,t}est*',
1568+
'{T,t}ool*',
1569+
'{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file',
15691570
];
15701571

1572+
$defaultGlobPattern = $analyser->getDefaultGlobPattern();
1573+
1574+
\sort($defaultGlobPattern);
1575+
\sort($expectedDefaultGlobPatterns);
1576+
15711577
$this->assertEquals(
15721578
$expectedDefaultGlobPatterns,
1573-
$analyser->getDefaultGlobPattern()
1579+
$defaultGlobPattern
15741580
);
15751581
}
15761582
}

tests/Commands/InitCommandTest.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,28 @@ public function createsExpectedDefaultLpvFile(): void
6363

6464
$expectedDefaultLpvFileContent = <<<CONTENT
6565
.*
66-
*.lock
6766
*.txt
68-
*.rst
6967
*.{md,MD}
70-
*.{png,gif,jpeg,jpg,webp}
68+
*.rst
69+
*.toml
7170
*.xml
7271
*.yml
73-
*.toml
72+
*.dist.*
73+
llms.*
74+
*.dist
75+
{B,b}uild*
76+
{D,d}ist
77+
{D,d}oc*
78+
{A,a}rt*
79+
{A,a}sset*
80+
{T,t}ool*
81+
{T,t}est*
82+
{S,s}pec*
83+
{E,e}xample*
84+
LICENSE
85+
{M,m}ake
86+
*.{png,gif,jpeg,jpg,webp}
87+
*.lock
7488
phpunit*
7589
appveyor.yml
7690
box.json
@@ -88,20 +102,8 @@ public function createsExpectedDefaultLpvFile(): void
88102
renovate.json
89103
*debugbar.json
90104
ecs*
91-
llms.*
92-
*.dist.*
93-
*.dist
94-
{B,b}uild*
95-
{D,d}oc*
96-
{T,t}ool*
97-
{T,t}est*
98-
{S,s}pec*
99-
{A,a}rt*
100-
{A,a}sset*
101-
{E,e}xample*
102-
LICENSE
103-
{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file
104105
RMT
106+
{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file
105107
CONTENT;
106108

107109
$this->assertSame($expectedDisplay, $commandTester->getDisplay());

0 commit comments

Comments
 (0)