Skip to content

Commit

Permalink
Add doc about rules and standard (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Jan 20, 2024
1 parent 3639e64 commit 9400431
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ Removes any space before and after opening and closing of arrays and hashes.
- [CLI options](docs/command.md)
- [Configuration file](docs/configuration.md)
- [How to disable a rule on a specific file or line](docs/identifiers.md)
- [Rules & Standard](docs/rules.md)
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
By default, the twig-cs-fixer standard is enabled with the twig coding standard rules and the following rules:

- `BlankEOFRule`: ensures that files end with one blank line.
- `BlockNameSpacingRule`: ensure there is one space before and after block names.
- `BlockNameSpacingRule`: ensures there is one space before and after block names.
- `EmptyLinesRule`: ensures that 2 empty lines do not follow each other.
- `IndentRule`: ensures that files are not indented with tabs.
- `TrailingCommaSingleLineRule`: ensures that single-line arrays, objects and argument lists do not have a trailing comma.
Expand Down
38 changes: 38 additions & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Rules & Standard

## Rules

- **BlockNameSpacingRule**: ensures there is one space before and after block names.
- **DelimiterSpacingRule**: ensures there is one space before '}}', '%}' and '#}', and after '{{', '{%', '{#'.
- **DirectoryNameRule**: ensures directory name is snake_case (configurable).
- **FileNameRule**: ensures file name is snake_case (configurable).
- **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 ','.
- **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.
- **TrailingSpaceRule**: ensures that files have no trailing spaces.

## Standards

**Twig**:
- DelimiterSpacingRule
- OperatorNameSpacingRule
- OperatorSpacingRule
- PunctuationSpacingRule

**TwigCsFixer**:
- Twig
- BlankEOFRule
- BlockNameSpacingRule
- EmptyLinesRule
- IndentRule
- TrailingCommaSingleLineRule
- TrailingSpaceRule

**Symfony**:
- Twig
- DirectoryNameRule
- FileNameRule
2 changes: 1 addition & 1 deletion src/Rules/AbstractSpacingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use TwigCsFixer\Token\Token;

/**
* Ensure there is one space before or after some tokens
* Ensures there is one space before or after some tokens
*/
abstract class AbstractSpacingRule extends AbstractRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Delimiter/BlockNameSpacingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use TwigCsFixer\Token\Token;

/**
* Ensure there is one space before and after block names.
* Ensures there is one space before and after block names.
*/
final class BlockNameSpacingRule extends AbstractSpacingRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Delimiter/DelimiterSpacingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use TwigCsFixer\Token\Token;

/**
* Ensure there is one space before '}}', '%}' and '#}', and after '{{', '{%', '{#'.
* Ensures there is one space before '}}', '%}' and '#}', and after '{{', '{%', '{#'.
*/
final class DelimiterSpacingRule extends AbstractSpacingRule
{
Expand Down
3 changes: 3 additions & 0 deletions src/Rules/File/DirectoryNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use TwigCsFixer\Rules\AbstractRule;
use TwigCsFixer\Rules\ConfigurableRuleInterface;

/**
* Ensures directory name is snake_case (Configurable).
*/
final class DirectoryNameRule extends AbstractRule implements ConfigurableRuleInterface
{
public const SNAKE_CASE = 'snake_case';
Expand Down
3 changes: 3 additions & 0 deletions src/Rules/File/FileNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use TwigCsFixer\Rules\AbstractRule;
use TwigCsFixer\Rules\ConfigurableRuleInterface;

/**
* Ensures file name is snake_case (Configurable).
*/
final class FileNameRule extends AbstractRule implements ConfigurableRuleInterface
{
public const SNAKE_CASE = 'snake_case';
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Operator/OperatorNameSpacingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use TwigCsFixer\Token\Token;

/**
* Ensure there is no consecutive spaces inside operator names.
* Ensures there is no consecutive spaces inside operator names.
*/
final class OperatorNameSpacingRule extends AbstractRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Operator/OperatorSpacingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Webmozart\Assert\Assert;

/**
* Ensure there is one space before and after an operator except for '..'.
* Ensures there is one space before and after an operator except for '..'.
*/
final class OperatorSpacingRule extends AbstractSpacingRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Punctuation/PunctuationSpacingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Webmozart\Assert\Assert;

/**
* Ensure there is no space before and after a punctuation except for ':' and ','.
* Ensures there is no space before and after a punctuation except for ':' and ','.
*/
final class PunctuationSpacingRule extends AbstractSpacingRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Punctuation/TrailingCommaSingleLineRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Webmozart\Assert\Assert;

/**
* Ensure that single-line arrays, objects and arguments list does not have a trailing comma.
* Ensures that single-line arrays, objects and argument lists do not have a trailing comma.
*/
final class TrailingCommaSingleLineRule extends AbstractRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Whitespace/BlankEOFRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use TwigCsFixer\Token\Token;

/**
* Ensure that files ends with one blank line.
* Ensures that files end with one blank line.
*/
final class BlankEOFRule extends AbstractRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Whitespace/EmptyLinesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Webmozart\Assert\Assert;

/**
* Checks that there are not 2 empty lines following each other.
* Ensures that 2 empty lines do not follow each other.
*/
final class EmptyLinesRule extends AbstractRule
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Whitespace/IndentRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use TwigCsFixer\Token\Token;

/**
* Ensure that files are not indented with tabs.
* Ensures that files are not indented with tabs.
*/
final class IndentRule extends AbstractRule implements ConfigurableRuleInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Whitespace/TrailingSpaceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use TwigCsFixer\Token\Token;

/**
* Ensure that files has no trailing space.
* Ensures that files have no trailing spaces.
*/
final class TrailingSpaceRule extends AbstractRule
{
Expand Down

0 comments on commit 9400431

Please sign in to comment.