From 692c40f76da35fba2407eaacffe449cb021f4287 Mon Sep 17 00:00:00 2001 From: Kei Date: Wed, 10 Jul 2024 01:37:26 +0700 Subject: [PATCH] formatting --- README.md | 76 ++++++-------------------- docs/advanced_configuration.md | 60 ++++++++++++++++++++ src/Commands/GenerateConfigCommand.php | 7 ++- 3 files changed, 82 insertions(+), 61 deletions(-) create mode 100644 docs/advanced_configuration.md diff --git a/README.md b/README.md index 2a29e95..cc46b7f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ **Realodix Relax** is built on top of [`PHP-CS-Fixer`][php-cs-fixer] and makes it simple to to sharing identical PHP CS Fixer rules across all of your projects without copy-and-pasting configuration files. + ## Installation You can install this package by using [composer](https://getcomposer.org/): @@ -14,6 +15,7 @@ You can install this package by using [composer](https://getcomposer.org/): composer require --dev realodix/relax ``` + ## Running Relax ```sh @@ -22,6 +24,7 @@ composer require --dev realodix/relax For more details, see PHP-CS-Fixer [documentation](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/usage.rst). + ## Configuring Relax In your PHP CS Fixer configuration file, use the following contents: @@ -49,6 +52,9 @@ A ruleset is a named list of rules that can be used to fix code style issues in | [`relax`][rs_relax] | Inherits `laravel` with some tweaks | | [`spatie`][rs_spatie] | The rule set used by Spatie | +[rs_laravel]: src/RuleSet/Sets/Laravel.php +[rs_relax]: src/RuleSet/Sets/Realodix.php +[rs_spatie]: src/RuleSet/Sets/Spatie.php #### Custom Fixers @@ -56,7 +62,7 @@ A ruleset is a named list of rules that can be used to fix code style issues in :bulb: They're all registered, so you don't need to re-register via `registerCustomFixers()`. -#### Finder Sets + ## Advanced Configuration +See [docs/advanced_configuration.md](docs/advanced_configuration.md) for more details. -Relax is built on top of [`PHP-CS-Fixer`][php-cs-fixer]. Therefore, you can make configurations just like you can do in PHP-CS-Fixer. For more details, see [PHP-CS-Fixer: Config](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/config.rst) documentation and [MLocati: PHP-CS-Fixer Configurator](https://mlocati.github.io/php-cs-fixer-configurator). - -```php - true, - - // Add rule or override predefined rule - 'visibility_required' => true, - - // Override predefined rule - 'braces' => false, - - // Add custom fixers - 'CustomFixer/rule_1' => true, - 'CustomFixer/rule_2' => true, -]; - -$finder = Finder::create() - ->in(__DIR__) - ->ignoreDotFiles(false) - ->exclude(['Bar']) - ->notName('*.foo.php') - ->append(['.php-cs-fixer.dist.php']); - -return Config::create('laravel') - ->setRules($localRules) - ->setFinder($finder) - ->setRiskyAllowed(false) - ->registerCustomFixers(new \PhpCsFixerCustomFixers\CustomFixer()); -``` - -If you wish to completely define rules locally without using existing rule sets, you can do that: - -```php - true, - 'array_syntax' => ['syntax' => 'short'], - 'ordered_imports' => ['sort_algorithm' => 'alpha'], -]; - -return Config::create() - ->setRules($localRules); -``` ## Custom Rule Set @@ -163,15 +113,21 @@ And use it! use Realodix\Relax\Config; use Vendor\Package\MyRuleSet; -return Config::create(new MyRuleSet()); +$finder = (new PhpCsFixer\Finder()) + ->in(__DIR__); + +return Config::create(new MyRuleSet()) + ->setFinder($finder); ``` + ## Troubleshooting For general help and support join our [GitHub Discussions](../../discussions). Please report bugs to the [GitHub Issue Tracker](../../issues). + ## License This package is licensed under the [MIT License](/LICENSE). diff --git a/docs/advanced_configuration.md b/docs/advanced_configuration.md new file mode 100644 index 0000000..9fe0dc8 --- /dev/null +++ b/docs/advanced_configuration.md @@ -0,0 +1,60 @@ +## Advanced Configuration + +You can find the full documentation on this page: +- [PHP-CS-Fixer: Config](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/config.rst) +- [PHP-CS-Fixer: Rules](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/rules/index.rst) +- [MLocati: PHP-CS-Fixer Configurator](https://mlocati.github.io/php-cs-fixer-configurator) + + +```php + true, + + // Add rule or override predefined rule + 'visibility_required' => true, + + // Override predefined rule + 'braces' => false, + + // Add custom fixers + 'CustomFixer/rule_1' => true, + 'CustomFixer/rule_2' => true, +]; + +$finder = Finder::create() + ->in(__DIR__) + ->ignoreDotFiles(false) + ->exclude(['Bar']) + ->notName('*.foo.php') + ->append(['.php-cs-fixer.dist.php']); + +return Config::create('laravel') + ->setRules($localRules) + ->setFinder($finder) + ->setRiskyAllowed(false) + ->registerCustomFixers(new \PhpCsFixerCustomFixers\CustomFixer()); +``` + +If you wish to completely define rules locally without using existing rule sets, you can do that: + +```php + true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], +]; + +return Config::create() + ->setRules($localRules); +``` diff --git a/src/Commands/GenerateConfigCommand.php b/src/Commands/GenerateConfigCommand.php index e4bd5e6..c5f8885 100644 --- a/src/Commands/GenerateConfigCommand.php +++ b/src/Commands/GenerateConfigCommand.php @@ -79,13 +79,18 @@ protected function generateAndSaveCode($output): bool $code = <<<'CODE' in(__DIR__) + return Config::create('relax') - ->setRules($localRules); + ->setRules($localRules) + ->setFinder($finder); CODE; if (file_put_contents($this->getOutputFilename(), $code) === false) {