From 9400431aa07bc30ad75d4eed56989c6e9e6bb3f3 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 20 Jan 2024 01:10:45 +0100 Subject: [PATCH] Add doc about rules and standard (#166) --- README.md | 1 + docs/configuration.md | 2 +- docs/rules.md | 38 +++++++++++++++++++ src/Rules/AbstractSpacingRule.php | 2 +- src/Rules/Delimiter/BlockNameSpacingRule.php | 2 +- src/Rules/Delimiter/DelimiterSpacingRule.php | 2 +- src/Rules/File/DirectoryNameRule.php | 3 ++ src/Rules/File/FileNameRule.php | 3 ++ .../Operator/OperatorNameSpacingRule.php | 2 +- src/Rules/Operator/OperatorSpacingRule.php | 2 +- .../Punctuation/PunctuationSpacingRule.php | 2 +- .../TrailingCommaSingleLineRule.php | 2 +- src/Rules/Whitespace/BlankEOFRule.php | 2 +- src/Rules/Whitespace/EmptyLinesRule.php | 2 +- src/Rules/Whitespace/IndentRule.php | 2 +- src/Rules/Whitespace/TrailingSpaceRule.php | 2 +- 16 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 docs/rules.md diff --git a/README.md b/README.md index 03931599..e4caead8 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/docs/configuration.md b/docs/configuration.md index 7b2fa8a6..043df7e1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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. diff --git a/docs/rules.md b/docs/rules.md new file mode 100644 index 00000000..0812b023 --- /dev/null +++ b/docs/rules.md @@ -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 diff --git a/src/Rules/AbstractSpacingRule.php b/src/Rules/AbstractSpacingRule.php index e099f828..3e379689 100644 --- a/src/Rules/AbstractSpacingRule.php +++ b/src/Rules/AbstractSpacingRule.php @@ -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 { diff --git a/src/Rules/Delimiter/BlockNameSpacingRule.php b/src/Rules/Delimiter/BlockNameSpacingRule.php index ee4e0d1c..bfaaf647 100644 --- a/src/Rules/Delimiter/BlockNameSpacingRule.php +++ b/src/Rules/Delimiter/BlockNameSpacingRule.php @@ -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 { diff --git a/src/Rules/Delimiter/DelimiterSpacingRule.php b/src/Rules/Delimiter/DelimiterSpacingRule.php index b33e5cba..e1e7572f 100644 --- a/src/Rules/Delimiter/DelimiterSpacingRule.php +++ b/src/Rules/Delimiter/DelimiterSpacingRule.php @@ -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 { diff --git a/src/Rules/File/DirectoryNameRule.php b/src/Rules/File/DirectoryNameRule.php index ebf867f4..8d2dbff0 100644 --- a/src/Rules/File/DirectoryNameRule.php +++ b/src/Rules/File/DirectoryNameRule.php @@ -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'; diff --git a/src/Rules/File/FileNameRule.php b/src/Rules/File/FileNameRule.php index 4cd59bcf..0af0c015 100644 --- a/src/Rules/File/FileNameRule.php +++ b/src/Rules/File/FileNameRule.php @@ -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'; diff --git a/src/Rules/Operator/OperatorNameSpacingRule.php b/src/Rules/Operator/OperatorNameSpacingRule.php index eadcd893..2a36610f 100644 --- a/src/Rules/Operator/OperatorNameSpacingRule.php +++ b/src/Rules/Operator/OperatorNameSpacingRule.php @@ -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 { diff --git a/src/Rules/Operator/OperatorSpacingRule.php b/src/Rules/Operator/OperatorSpacingRule.php index 31b96821..2861f871 100644 --- a/src/Rules/Operator/OperatorSpacingRule.php +++ b/src/Rules/Operator/OperatorSpacingRule.php @@ -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 { diff --git a/src/Rules/Punctuation/PunctuationSpacingRule.php b/src/Rules/Punctuation/PunctuationSpacingRule.php index d7211cb4..18810c48 100644 --- a/src/Rules/Punctuation/PunctuationSpacingRule.php +++ b/src/Rules/Punctuation/PunctuationSpacingRule.php @@ -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 { diff --git a/src/Rules/Punctuation/TrailingCommaSingleLineRule.php b/src/Rules/Punctuation/TrailingCommaSingleLineRule.php index f3a00119..3717ea9b 100644 --- a/src/Rules/Punctuation/TrailingCommaSingleLineRule.php +++ b/src/Rules/Punctuation/TrailingCommaSingleLineRule.php @@ -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 { diff --git a/src/Rules/Whitespace/BlankEOFRule.php b/src/Rules/Whitespace/BlankEOFRule.php index e1258093..ccea4573 100644 --- a/src/Rules/Whitespace/BlankEOFRule.php +++ b/src/Rules/Whitespace/BlankEOFRule.php @@ -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 { diff --git a/src/Rules/Whitespace/EmptyLinesRule.php b/src/Rules/Whitespace/EmptyLinesRule.php index edde2880..1ede69e9 100644 --- a/src/Rules/Whitespace/EmptyLinesRule.php +++ b/src/Rules/Whitespace/EmptyLinesRule.php @@ -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 { diff --git a/src/Rules/Whitespace/IndentRule.php b/src/Rules/Whitespace/IndentRule.php index 8abfcf75..0d88ff70 100644 --- a/src/Rules/Whitespace/IndentRule.php +++ b/src/Rules/Whitespace/IndentRule.php @@ -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 { diff --git a/src/Rules/Whitespace/TrailingSpaceRule.php b/src/Rules/Whitespace/TrailingSpaceRule.php index 45c4387f..17a97215 100644 --- a/src/Rules/Whitespace/TrailingSpaceRule.php +++ b/src/Rules/Whitespace/TrailingSpaceRule.php @@ -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 {