Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for config files with .php extension #247

Merged
merged 8 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ For more complex needs, have a look at the [custom ruleset documentation](doc/ru
Using configuration, you can easily store per-project settings:

```php
// ~/.twig_cs.dist
// ~/.twig_cs.dist.php
<?php

return \FriendsOfTwig\Twigcs\Config\Config::create()
Expand All @@ -140,15 +140,22 @@ you must use the `--config` option:

```
cd ~/dirA
twigcs --config ~/dirB/.twig_cs.dist # Will lint templates in ~/dirA with the config of ~/dirB
twigcs --config ~/dirB/.twig_cs.dist.php # Will lint templates in ~/dirA with the config of ~/dirB
```

By default, the files `.twig_cs` and `.twig_cs.dist` are looked up in your current working directory (CWD).
By default, the files

- `.twig_cs.php`
- `.twig_cs`
- `.twig_cs.dist.php`
- `.twig_cs.dist`
Comment on lines +148 to +151
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yguedidi

I have turned this into a list, making the order perhaps a bit more clear. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed better!


are looked up in your current working directory (CWD).

You can also provide finders inside config files, they will completely replace the path in the CLI:

```php
// ~/.twig_cs.dist
// ~/.twig_cs.dist.php
<?php

$finderA = FriendsOfTwig\Twigcs\Finder\TemplateFinder::create()->in(__DIR__.'/dirA');
Expand Down
4 changes: 3 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
<MixedInferredReturnType occurrences="1">
<code>string</code>
</MixedInferredReturnType>
<MixedOperand occurrences="3">
<MixedOperand occurrences="5">
<code>$configDir</code>
<code>$configDir</code>
<code>$configDir</code>
<code>$configDir</code>
<code>$cwd</code>
Expand Down
2 changes: 2 additions & 0 deletions src/Config/ConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ private function computeConfigFiles()
$configDir = $this->cwd;

return [
$configDir.\DIRECTORY_SEPARATOR.'.twig_cs.php',
$configDir.\DIRECTORY_SEPARATOR.'.twig_cs',
$configDir.\DIRECTORY_SEPARATOR.'.twig_cs.dist.php',
$configDir.\DIRECTORY_SEPARATOR.'.twig_cs.dist',
];
}
Expand Down
25 changes: 25 additions & 0 deletions tests/Config/ConfigResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,34 @@ public function testGetConfigFileReturnsConfigFileWhenConfigOptionHasNotBeenSpec
public function provideDefaultConfigFileNameAndAvailableDefaultConfigFileNames(): array
{
return [
[
'.twig_cs.php',
[
'.twig_cs',
'.twig_cs.dist',
'.twig_cs.dist.php',
'.twig_cs.php',
],
],
[
'.twig_cs',
[
'.twig_cs',
'.twig_cs.dist',
'.twig_cs.dist.php',
],
],
[
'.twig_cs.dist.php',
[
'.twig_cs.dist',
'.twig_cs.dist.php',
],
],
[
'.twig_cs.dist',
[
'.twig_cs.dist',
],
],
];
Expand Down Expand Up @@ -278,6 +301,8 @@ public function provideDefaultConfigFileName(): \Generator
$defaultConfigFileNames = [
'.twig_cs',
'.twig_cs.dist',
'.twig_cs.dist.php',
'.twig_cs.php',
];

foreach ($defaultConfigFileNames as $defaultConfigFileName) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Console/LintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function testConfigFileWithoutCliPath()
{
$this->commandTester->execute([
'paths' => null,
'--config' => 'tests/data/config/external/.twig_cs.dist',
'--config' => 'tests/data/config/external/.twig_cs.dist.php',
]);

$output = $this->commandTester->getDisplay();
Expand All @@ -209,7 +209,7 @@ public function testConfigFileWithCliPath()
{
$this->commandTester->execute([
'paths' => ['tests/data/syntax_error'],
'--config' => 'tests/data/config/external/.twig_cs.dist',
'--config' => 'tests/data/config/external/.twig_cs.dist.php',
]);

$output = $this->commandTester->getDisplay();
Expand All @@ -227,7 +227,7 @@ public function testConfigFileWithCliPath()
public function testConfigFileWithDisplayAndSeverity()
{
$this->commandTester->execute([
'--config' => 'tests/data/config/external/.twig_cs_with_display_blocking.dist',
'--config' => 'tests/data/config/external/.twig_cs_with_display_blocking.dist.php',
]);

$output = $this->commandTester->getDisplay();
Expand Down Expand Up @@ -271,7 +271,7 @@ public function testConfigFileSamePathWithRulesetOverrides()
public function testUnusedWithFileLoader()
{
$this->commandTester->execute([
'--config' => 'tests/data/config/loaders/.twig_cs.dist',
'--config' => 'tests/data/config/loaders/.twig_cs.dist.php',
]);

$output = $this->commandTester->getDisplay();
Expand Down
20 changes: 0 additions & 20 deletions tests/data/config/namespaced_loaders/.twig_cs.dist

This file was deleted.

3 changes: 0 additions & 3 deletions tests/data/config/namespaced_loaders/a/child.html.twig

This file was deleted.

4 changes: 0 additions & 4 deletions tests/data/config/namespaced_loaders/b/parent.html.twig

This file was deleted.