Skip to content

Commit

Permalink
Add --no-config option (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary authored Feb 16, 2024
1 parent 7c9b784 commit 3ca3831
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/Commands/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected function configure()
[
new InputArgument('path', InputArgument::IS_ARRAY, 'The path to fix', [(string) getcwd()]),
new InputOption('config', '', InputOption::VALUE_REQUIRED, 'The configuration that should be used'),
new InputOption('no-config', '', InputOption::VALUE_NONE, 'Disable loading any configuration file'),
new InputOption('preset', '', InputOption::VALUE_REQUIRED, 'The preset that should be used'),
new InputOption('test', '', InputOption::VALUE_NONE, 'Test for code style errors without fixing them'),
new InputOption('dirty', '', InputOption::VALUE_NONE, 'Only fix files that have uncommitted changes'),
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/RepositoriesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public function register()
{
$this->app->singleton(ConfigurationJsonRepository::class, function () {
$input = resolve(InputInterface::class);
$config = $input->getOption('config') ?: Project::path().'/pint.json';

return new ConfigurationJsonRepository(
$input->getOption('config') ?: Project::path().'/pint.json',
$input->getOption('no-config') ? null : $config,
$input->getOption('preset'),
);
});
Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/ConfigurationJsonRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function preset()
*/
protected function get()
{
if ($this->fileExists((string) $this->path)) {
if (! is_null($this->path) && $this->fileExists((string) $this->path)) {
return tap(json_decode(file_get_contents($this->path), true), function ($configuration) {
if (! is_array($configuration)) {
abort(1, sprintf('The configuration file [%s] is not valid JSON.', $this->path));
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/PresetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@
->and($output)
->toContain('── Symfony');
});

it('ignores config when using no config option', function () {
$cwd = getcwd();
chdir(base_path('tests/Fixtures/no-config'));

[$statusCode, $output] = run('default', [
'--preset' => 'psr12',
'--no-config' => true,
]);

chdir($cwd);

expect($statusCode)->toBe(0)
->and($output)
->toContain('── PSR 12');
});
7 changes: 7 additions & 0 deletions tests/Fixtures/no-config/pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rules": {
"concat_space": {
"spacing": "none"
}
}
}
3 changes: 3 additions & 0 deletions tests/Fixtures/no-config/with-fixes-based-on-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$a = 'This has a fix for the ' . 'laravel preset';

0 comments on commit 3ca3831

Please sign in to comment.