Skip to content

Commit

Permalink
Improve documentation about configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Apr 16, 2024
1 parent 9716b59 commit 6ac3640
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
13 changes: 11 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ a `TwigCsFixer\Config\Config` class:
<?php

$ruleset = new TwigCsFixer\Ruleset\Ruleset();
$ruleset->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);
Expand Down
19 changes: 17 additions & 2 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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**:
Expand Down

0 comments on commit 6ac3640

Please sign in to comment.