From edfa847ea335d28e2b6f8c0cfa68dc6b4de79211 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 16 Apr 2024 13:33:19 +0200 Subject: [PATCH] Improve documentation about configuration (#209) --- docs/configuration.md | 13 +++++++++++-- docs/rules.md | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index e0bc2a4f..4ebe774c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -19,8 +19,17 @@ a `TwigCsFixer\Config\Config` class: addStandard(new TwigCsFixer\Standard\Twig()); -$ruleset->addRule(new TwigCsFixer\Rules\Whitespace\EmptyLinesRule()); + +// You can start from a default standard +$ruleset->addStandard(new TwigCsFixer\Standard\TwigCsFixer()); + +// And then add/remove/override some rules +$ruleset->addRule(new TwigCsFixer\Rules\File\FileExtensionRule()()); +$ruleset->removeRule(new TwigCsFixer\Rules\Whitespace\EmptyLinesRule()); +$ruleset->overrideRule(new TwigCsFixer\Rules\Punctuation\PunctuationSpacingRule( + ['}' => 1], + ['{' => 1], +)); $config = new TwigCsFixer\Config\Config(); $config->setRuleset($ruleset); diff --git a/docs/rules.md b/docs/rules.md index 22ef9fd9..8da67a42 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -9,11 +9,11 @@ - **IncludeFunctionRule**: ensures that include function is used instead of function tag. - **OperatorNameSpacingRule**: ensures there is no consecutive spaces inside operator names. - **OperatorSpacingRule**: ensures there is one space before and after an operator except for '..'. -- **PunctuationSpacingRule**: ensures there is no space before and after a punctuation except for ':' and ','. +- **PunctuationSpacingRule**: ensures there is no space before and after a punctuation except for ':' and ',' (configurable). - **TrailingCommaSingleLineRule**: ensures that single-line arrays, objects and argument lists do not have a trailing comma. - **BlankEOFRule**: ensures that files ends with one blank line. - **EmptyLinesRule**: ensures that 2 empty lines do not follow each other. -- **IndentRule**: ensures that files are not indented with tabs. +- **IndentRule**: ensures that files are not indented with tabs (configurable). - **TrailingSpaceRule**: ensures that files have no trailing spaces. ### Non-fixable @@ -25,6 +25,21 @@ To use these rules, you have to [allow non-fixable rules](configuration.md#non-f - **VariableNameRule**: ensures that variable name uses snake_case (configurable). - **FileExtensionRule**: ensures that file name uses two extensions (e.g. index.html.twig). +### Configurable rules + +Some rules are configurable, those rule are implementing `\TwigCsFixer\Rules\ConfigurableRuleInterface`. + +The easiest way to see how to configure such rules is to look at the `__construct` definition +of those rules. For instance: +```php +new TwigCsFixer\Rules\Punctuation\PunctuationSpacingRule( + ['}' => 1], + ['{' => 1], +); + +new TwigCsFixer\Rules\Whitespace\IndentRule(3); +``` + ## Standards **Twig**: