diff --git a/src/Rules/File/FileNameRule.php b/src/Rules/File/FileNameRule.php index d863c3b8..46ffb094 100644 --- a/src/Rules/File/FileNameRule.php +++ b/src/Rules/File/FileNameRule.php @@ -27,6 +27,7 @@ public function __construct( private string $case = self::SNAKE_CASE, private ?string $baseDirectory = null, private array $ignoredSubDirectories = [], + private string $optionalPrefix = '', ) { } @@ -36,6 +37,7 @@ public function getConfiguration(): array 'case' => $this->case, 'baseDirectory' => $this->baseDirectory, 'ignoredSubDirectories' => $this->ignoredSubDirectories, + 'optionalPrefix' => $this->optionalPrefix, ]; } @@ -59,6 +61,12 @@ protected function process(int $tokenPosition, array $tokens): void // in order to avoid conflict with some file extensions. $fileName = explode('.', FileHelper::removeDot($fileName))[0]; + $prefix = ''; + if (str_starts_with($fileName, $this->optionalPrefix)) { + $prefix = $this->optionalPrefix; + $fileName = substr($fileName, \strlen($this->optionalPrefix)); + } + $expected = match ($this->case) { self::SNAKE_CASE => StringUtil::toSnakeCase($fileName), self::CAMEL_CASE => StringUtil::toCamelCase($fileName), @@ -68,7 +76,7 @@ protected function process(int $tokenPosition, array $tokens): void if ($expected !== $fileName) { $this->addFileError( - sprintf('The file name must use %s; expected %s.', $this->case, $expected), + sprintf('The file name must use %s; expected %s.', $this->case, $prefix.$expected), $token, ); } diff --git a/src/Standard/Symfony.php b/src/Standard/Symfony.php index 97929be9..0fae1db3 100644 --- a/src/Standard/Symfony.php +++ b/src/Standard/Symfony.php @@ -13,6 +13,7 @@ * * @see https://twig.symfony.com/doc/3.x/coding_standards.html * @see https://symfony.com/doc/current/templates.html#template-naming + * @see https://symfony.com/doc/current/best_practices.html#templates */ final class Symfony implements StandardInterface { @@ -20,7 +21,7 @@ public function getRules(): array { return [ ...(new Twig())->getRules(), - new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles']), + new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles'], optionalPrefix: '_'), new DirectoryNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles']), new FileExtensionRule(), ]; diff --git a/tests/Rules/AbstractRuleTestCase.php b/tests/Rules/AbstractRuleTestCase.php index 21a79fe8..01902c36 100644 --- a/tests/Rules/AbstractRuleTestCase.php +++ b/tests/Rules/AbstractRuleTestCase.php @@ -55,25 +55,30 @@ protected function checkRule( } } - $messages = $report->getFileViolations($filePath); + $violations = $report->getFileViolations($filePath); - /** @var array $messageIds */ - $messageIds = []; - foreach ($messages as $message) { - if (Violation::LEVEL_FATAL === $message->getLevel()) { - $errorMessage = $message->getMessage(); - $line = $message->getLine(); + /** @var array $messages */ + $messages = []; + foreach ($violations as $violation) { + $message = $violation->getMessage(); + if (Violation::LEVEL_FATAL === $violation->getLevel()) { + $line = $violation->getLine(); if (null !== $line) { - $errorMessage = sprintf('Line %s: %s', $line, $errorMessage); + $message = sprintf('Line %s: %s', $line, $message); } - static::fail($errorMessage); + static::fail($message); } - $messageIds[] = $message->getIdentifier()?->toString(); + $id = $violation->getIdentifier()?->toString() ?? ''; + if (isset($messages[$id])) { + static::fail(sprintf('Two violations have the same identifier "%s".', $id)); + } + + $messages[$id] = $message; } - static::assertSame($expects, $messageIds); + static::assertSame($expects, $messages); } private function generateFilePath(): string diff --git a/tests/Rules/Delimiter/BlockNameSpacing/BlockNameSpacingRuleTest.php b/tests/Rules/Delimiter/BlockNameSpacing/BlockNameSpacingRuleTest.php index e50d5875..7a30001d 100644 --- a/tests/Rules/Delimiter/BlockNameSpacing/BlockNameSpacingRuleTest.php +++ b/tests/Rules/Delimiter/BlockNameSpacing/BlockNameSpacingRuleTest.php @@ -12,10 +12,10 @@ final class BlockNameSpacingRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new BlockNameSpacingRule(), [ - 'BlockNameSpacing.After:1:5', - 'BlockNameSpacing.Before:1:5', - 'BlockNameSpacing.After:3:3', - 'BlockNameSpacing.Before:3:3', + 'BlockNameSpacing.After:1:5' => 'Expecting 1 whitespace after "extends"; found 0', + 'BlockNameSpacing.Before:1:5' => 'Expecting 1 whitespace before "extends"; found 2', + 'BlockNameSpacing.After:3:3' => 'Expecting 1 whitespace after "if"; found 4', + 'BlockNameSpacing.Before:3:3' => 'Expecting 1 whitespace before "if"; found 0', ]); } } diff --git a/tests/Rules/Delimiter/DelimiterSpacing/DelimiterSpacingRuleTest.php b/tests/Rules/Delimiter/DelimiterSpacing/DelimiterSpacingRuleTest.php index 07e03e8d..381d6389 100644 --- a/tests/Rules/Delimiter/DelimiterSpacing/DelimiterSpacingRuleTest.php +++ b/tests/Rules/Delimiter/DelimiterSpacing/DelimiterSpacingRuleTest.php @@ -12,10 +12,10 @@ final class DelimiterSpacingRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new DelimiterSpacingRule(), [ - 'DelimiterSpacing.After:15:1', - 'DelimiterSpacing.Before:15:12', - 'DelimiterSpacing.After:15:15', - 'DelimiterSpacing.Before:15:25', + 'DelimiterSpacing.After:15:1' => 'Expecting 1 whitespace after "{%-"; found 0', + 'DelimiterSpacing.Before:15:12' => 'Expecting 1 whitespace before "-%}"; found 2', + 'DelimiterSpacing.After:15:15' => 'Expecting 1 whitespace after "{%-"; found 2', + 'DelimiterSpacing.Before:15:25' => 'Expecting 1 whitespace before "-%}"; found 0', ]); } } diff --git a/tests/Rules/File/DirectoryName/DirectoryNameRuleTest.php b/tests/Rules/File/DirectoryName/DirectoryNameRuleTest.php index 8b6975e7..01cdc766 100644 --- a/tests/Rules/File/DirectoryName/DirectoryNameRuleTest.php +++ b/tests/Rules/File/DirectoryName/DirectoryNameRuleTest.php @@ -52,7 +52,9 @@ public function testRuleInvalidTemplatesDirectory(): void { $this->checkRule( new DirectoryNameRule(baseDirectory: __DIR__.'/templates'), - ['DirectoryName.Error'], + [ + 'DirectoryName.Error' => 'The directory name must use snake_case; expected directory_name_rule_test.', + ], __DIR__.'/templates/directoryNameRuleTest/DirectoryNameRuleTest.twig' ); } @@ -64,7 +66,9 @@ public function testRulePascalCase(): void public function testRuleInvalidDirectory(): void { - $this->checkRule(new DirectoryNameRule(baseDirectory: __DIR__.'/..'), ['DirectoryName.Error']); + $this->checkRule(new DirectoryNameRule(baseDirectory: __DIR__.'/..'), [ + 'DirectoryName.Error' => 'The directory name must use snake_case; expected directory_name.', + ]); } public function testRuleKebabCase(): void diff --git a/tests/Rules/File/FileExtension/FileExtensionRuleTest.php b/tests/Rules/File/FileExtension/FileExtensionRuleTest.php index 313ac73b..87409793 100644 --- a/tests/Rules/File/FileExtension/FileExtensionRuleTest.php +++ b/tests/Rules/File/FileExtension/FileExtensionRuleTest.php @@ -11,7 +11,9 @@ final class FileExtensionRuleTest extends AbstractRuleTestCase { public function testRule(): void { - $this->checkRule(new FileExtensionRule(), ['FileExtension.Error']); + $this->checkRule(new FileExtensionRule(), [ + 'FileExtension.Error' => 'The file must use two extensions; found ".twig".', + ]); } public function testRuleIgnoredFile(): void @@ -26,7 +28,9 @@ public function testRuleValidFile(): void public function testRuleInvalidDotFile(): void { - $this->checkRule(new FileExtensionRule(), ['FileExtension.Error'], __DIR__.'/.dotfile.twig'); + $this->checkRule(new FileExtensionRule(), [ + 'FileExtension.Error' => 'The file must use two extensions; found ".twig".', + ], __DIR__.'/.dotfile.twig'); } public function testRuleValidDotFileWithFormatExtension(): void diff --git a/tests/Rules/File/FileName/FileNameRuleTest.php b/tests/Rules/File/FileName/FileNameRuleTest.php index 8ea86248..1d9c4b35 100644 --- a/tests/Rules/File/FileName/FileNameRuleTest.php +++ b/tests/Rules/File/FileName/FileNameRuleTest.php @@ -16,6 +16,7 @@ public function testConfiguration(): void 'case' => FileNameRule::SNAKE_CASE, 'baseDirectory' => null, 'ignoredSubDirectories' => [], + 'optionalPrefix' => '', ], (new FileNameRule())->getConfiguration() ); @@ -25,11 +26,13 @@ public function testConfiguration(): void 'case' => FileNameRule::PASCAL_CASE, 'baseDirectory' => 'foo', 'ignoredSubDirectories' => ['bar'], + 'optionalPrefix' => '_', ], (new FileNameRule( FileNameRule::PASCAL_CASE, 'foo', - ['bar'] + ['bar'], + '_' ))->getConfiguration() ); } @@ -37,14 +40,14 @@ public function testConfiguration(): void public function testRule(): void { $this->checkRule(new FileNameRule(), [ - 'FileName.Error', + 'FileName.Error' => 'The file name must use snake_case; expected file_name_rule_test.', ]); } public function testRuleDotfile(): void { $this->checkRule(new FileNameRule(), [ - 'FileName.Error', + 'FileName.Error' => 'The file name must use snake_case; expected file_name_rule_test.', ], __DIR__.'/.FileNameRuleTest.twig'); } @@ -81,7 +84,7 @@ public function testRuleValidFileWithDot(): void public function testRuleBaseDir(): void { $this->checkRule(new FileNameRule(baseDirectory: __DIR__.'/..'), [ - 'FileName.Error', + 'FileName.Error' => 'The file name must use snake_case; expected file_name_rule_test.', ]); } @@ -89,4 +92,17 @@ public function testRuleIgnoredPath(): void { $this->checkRule(new FileNameRule(baseDirectory: __DIR__.'/..', ignoredSubDirectories: ['FileName']), []); } + + public function testRuleOptionalPrefix(): void + { + $this->checkRule(new FileNameRule(), [ + 'FileName.Error' => 'The file name must use snake_case; expected file_name_rule_test.', + ], __DIR__.'/_file_name_rule_test.twig'); + + $this->checkRule(new FileNameRule(optionalPrefix: '_'), [], __DIR__.'/_file_name_rule_test.twig'); + + $this->checkRule(new FileNameRule(FileNameRule::CAMEL_CASE, optionalPrefix: '_'), [ + 'FileName.Error' => 'The file name must use camelCase; expected _fileNameRuleTest.', + ], __DIR__.'/_file_name_rule_test.twig'); + } } diff --git a/tests/Rules/File/FileName/_file_name_rule_test.twig b/tests/Rules/File/FileName/_file_name_rule_test.twig new file mode 100644 index 00000000..4a584e49 --- /dev/null +++ b/tests/Rules/File/FileName/_file_name_rule_test.twig @@ -0,0 +1 @@ +Nothing diff --git a/tests/Rules/Function/IncludeFunction/IncludeFunctionRuleTest.php b/tests/Rules/Function/IncludeFunction/IncludeFunctionRuleTest.php index d343f955..9512092e 100644 --- a/tests/Rules/Function/IncludeFunction/IncludeFunctionRuleTest.php +++ b/tests/Rules/Function/IncludeFunction/IncludeFunctionRuleTest.php @@ -19,22 +19,22 @@ public function testRule(): void new PunctuationSpacingRule(), ], [ - 'IncludeFunction.Error:1:4', - 'IncludeFunction.Error:2:4', - 'IncludeFunction.Error:3:4', - 'IncludeFunction.Error:4:4', - 'IncludeFunction.Error:5:4', - 'IncludeFunction.Error:6:4', - 'IncludeFunction.Error:7:4', - 'IncludeFunction.Error:8:4', - 'IncludeFunction.Error:9:4', - 'IncludeFunction.Error:10:4', - 'IncludeFunction.Error:11:4', - 'IncludeFunction.Error:12:4', - 'IncludeFunction.Error:13:4', - 'IncludeFunction.Error:14:4', - 'IncludeFunction.Error:15:5', - 'IncludeFunction.Error:16:5', + 'IncludeFunction.Error:1:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:2:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:3:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:4:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:5:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:6:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:7:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:8:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:9:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:10:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:11:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:12:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:13:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:14:4' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:15:5' => 'Include function must be used instead of include tag.', + 'IncludeFunction.Error:16:5' => 'Include function must be used instead of include tag.', ] ); } diff --git a/tests/Rules/Operator/OperatorNameSpacing/OperatorNameSpacingRuleTest.php b/tests/Rules/Operator/OperatorNameSpacing/OperatorNameSpacingRuleTest.php index ad0259b1..e31f6c3d 100644 --- a/tests/Rules/Operator/OperatorNameSpacing/OperatorNameSpacingRuleTest.php +++ b/tests/Rules/Operator/OperatorNameSpacing/OperatorNameSpacingRuleTest.php @@ -12,9 +12,9 @@ final class OperatorNameSpacingRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new OperatorNameSpacingRule(), [ - 'OperatorNameSpacing.Error:2:13', - 'OperatorNameSpacing.Error:3:13', - 'OperatorNameSpacing.Error:4:10', + 'OperatorNameSpacing.Error:2:13' => 'A single line operator should not have consecutive spaces.', + 'OperatorNameSpacing.Error:3:13' => 'A single line operator should not have consecutive spaces.', + 'OperatorNameSpacing.Error:4:10' => 'A single line operator should not have consecutive spaces.', ]); } } diff --git a/tests/Rules/Operator/OperatorSpacing/OperatorSpacingRuleTest.php b/tests/Rules/Operator/OperatorSpacing/OperatorSpacingRuleTest.php index fa3cde27..34d0aeb7 100644 --- a/tests/Rules/Operator/OperatorSpacing/OperatorSpacingRuleTest.php +++ b/tests/Rules/Operator/OperatorSpacing/OperatorSpacingRuleTest.php @@ -12,50 +12,50 @@ final class OperatorSpacingRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new OperatorSpacingRule(), [ - 'OperatorSpacing.After:1:5', - 'OperatorSpacing.Before:1:5', - 'OperatorSpacing.After:2:5', - 'OperatorSpacing.Before:2:5', - 'OperatorSpacing.After:3:5', - 'OperatorSpacing.Before:3:5', - 'OperatorSpacing.After:4:5', - 'OperatorSpacing.Before:4:5', - 'OperatorSpacing.After:5:5', - 'OperatorSpacing.Before:5:5', - 'OperatorSpacing.After:6:5', - 'OperatorSpacing.Before:6:5', - 'OperatorSpacing.After:7:5', - 'OperatorSpacing.Before:7:5', - 'OperatorSpacing.After:8:7', - 'OperatorSpacing.Before:8:7', - 'OperatorSpacing.After:9:10', - 'OperatorSpacing.Before:9:10', - 'OperatorSpacing.After:9:19', - 'OperatorSpacing.Before:9:19', - 'OperatorSpacing.After:10:5', - 'OperatorSpacing.Before:10:5', - 'OperatorSpacing.After:11:4', - 'OperatorSpacing.After:12:11', - 'OperatorSpacing.Before:12:11', - 'OperatorSpacing.After:13:11', - 'OperatorSpacing.Before:13:11', - 'OperatorSpacing.After:14:7', - 'OperatorSpacing.Before:14:7', - 'OperatorSpacing.After:15:7', - 'OperatorSpacing.Before:15:7', - 'OperatorSpacing.After:19:5', - 'OperatorSpacing.Before:19:5', - 'OperatorSpacing.After:20:5', - 'OperatorSpacing.Before:20:5', - 'OperatorSpacing.After:22:6', - 'OperatorSpacing.After:33:10', - 'OperatorSpacing.Before:33:10', - 'OperatorSpacing.After:35:13', - 'OperatorSpacing.Before:35:13', - 'OperatorSpacing.After:36:13', - 'OperatorSpacing.Before:36:13', - 'OperatorSpacing.After:37:13', - 'OperatorSpacing.Before:37:13', + 'OperatorSpacing.After:1:5' => 'Expecting 1 whitespace after "+"; found 0', + 'OperatorSpacing.Before:1:5' => 'Expecting 1 whitespace before "+"; found 0', + 'OperatorSpacing.After:2:5' => 'Expecting 1 whitespace after "-"; found 0', + 'OperatorSpacing.Before:2:5' => 'Expecting 1 whitespace before "-"; found 0', + 'OperatorSpacing.After:3:5' => 'Expecting 1 whitespace after "/"; found 0', + 'OperatorSpacing.Before:3:5' => 'Expecting 1 whitespace before "/"; found 0', + 'OperatorSpacing.After:4:5' => 'Expecting 1 whitespace after "*"; found 0', + 'OperatorSpacing.Before:4:5' => 'Expecting 1 whitespace before "*"; found 0', + 'OperatorSpacing.After:5:5' => 'Expecting 1 whitespace after "%"; found 0', + 'OperatorSpacing.Before:5:5' => 'Expecting 1 whitespace before "%"; found 0', + 'OperatorSpacing.After:6:5' => 'Expecting 1 whitespace after "//"; found 0', + 'OperatorSpacing.Before:6:5' => 'Expecting 1 whitespace before "//"; found 0', + 'OperatorSpacing.After:7:5' => 'Expecting 1 whitespace after "**"; found 0', + 'OperatorSpacing.Before:7:5' => 'Expecting 1 whitespace before "**"; found 0', + 'OperatorSpacing.After:8:7' => 'Expecting 1 whitespace after "~"; found 0', + 'OperatorSpacing.Before:8:7' => 'Expecting 1 whitespace before "~"; found 0', + 'OperatorSpacing.After:9:10' => 'Expecting 1 whitespace after "?"; found 2', + 'OperatorSpacing.Before:9:10' => 'Expecting 1 whitespace before "?"; found 2', + 'OperatorSpacing.After:9:19' => 'Expecting 1 whitespace after ":"; found 2', + 'OperatorSpacing.Before:9:19' => 'Expecting 1 whitespace before ":"; found 2', + 'OperatorSpacing.After:10:5' => 'Expecting 1 whitespace after "=="; found 0', + 'OperatorSpacing.Before:10:5' => 'Expecting 1 whitespace before "=="; found 0', + 'OperatorSpacing.After:11:4' => 'Expecting 1 whitespace after "not"; found 3', + 'OperatorSpacing.After:12:11' => 'Expecting 1 whitespace after "and"; found 3', + 'OperatorSpacing.Before:12:11' => 'Expecting 1 whitespace before "and"; found 2', + 'OperatorSpacing.After:13:11' => 'Expecting 1 whitespace after "or"; found 3', + 'OperatorSpacing.Before:13:11' => 'Expecting 1 whitespace before "or"; found 2', + 'OperatorSpacing.After:14:7' => 'Expecting 1 whitespace after "in"; found 3', + 'OperatorSpacing.Before:14:7' => 'Expecting 1 whitespace before "in"; found 2', + 'OperatorSpacing.After:15:7' => 'Expecting 1 whitespace after "is"; found 3', + 'OperatorSpacing.Before:15:7' => 'Expecting 1 whitespace before "is"; found 2', + 'OperatorSpacing.After:19:5' => 'Expecting 1 whitespace after "?:"; found 0', + 'OperatorSpacing.Before:19:5' => 'Expecting 1 whitespace before "?:"; found 0', + 'OperatorSpacing.After:20:5' => 'Expecting 1 whitespace after "??"; found 0', + 'OperatorSpacing.Before:20:5' => 'Expecting 1 whitespace before "??"; found 0', + 'OperatorSpacing.After:22:6' => 'Expecting 1 whitespace after "+"; found 0', + 'OperatorSpacing.After:33:10' => 'Expecting 1 whitespace after "+"; found 0', + 'OperatorSpacing.Before:33:10' => 'Expecting 1 whitespace before "+"; found 0', + 'OperatorSpacing.After:35:13' => 'Expecting 1 whitespace after "starts with"; found 2', + 'OperatorSpacing.Before:35:13' => 'Expecting 1 whitespace before "starts with"; found 2', + 'OperatorSpacing.After:36:13' => 'Expecting 1 whitespace after "ends with"; found 2', + 'OperatorSpacing.Before:36:13' => 'Expecting 1 whitespace before "ends with"; found 2', + 'OperatorSpacing.After:37:13' => 'Expecting 1 whitespace after "matches"; found 2', + 'OperatorSpacing.Before:37:13' => 'Expecting 1 whitespace before "matches"; found 2', ]); } diff --git a/tests/Rules/Punctuation/PunctuationSpacing/PunctuationSpacingRuleTest.php b/tests/Rules/Punctuation/PunctuationSpacing/PunctuationSpacingRuleTest.php index f56c1092..0bcfed58 100644 --- a/tests/Rules/Punctuation/PunctuationSpacing/PunctuationSpacingRuleTest.php +++ b/tests/Rules/Punctuation/PunctuationSpacing/PunctuationSpacingRuleTest.php @@ -12,21 +12,21 @@ final class PunctuationSpacingRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new PunctuationSpacingRule(), [ - 'PunctuationSpacing.After:3:4', - 'PunctuationSpacing.Before:3:10', - 'PunctuationSpacing.After:4:4', - 'PunctuationSpacing.Before:4:10', - 'PunctuationSpacing.Before:4:16', - 'PunctuationSpacing.Before:4:22', - 'PunctuationSpacing.Before:4:28', - 'PunctuationSpacing.After:5:12', - 'PunctuationSpacing.Before:5:16', - 'PunctuationSpacing.Before:5:20', - 'PunctuationSpacing.Before:5:24', - 'PunctuationSpacing.After:6:6', - 'PunctuationSpacing.Before:6:6', - 'PunctuationSpacing.Before:7:12', - 'PunctuationSpacing.Before:7:15', + 'PunctuationSpacing.After:3:4' => 'Expecting 0 whitespace after "("; found 1', + 'PunctuationSpacing.Before:3:10' => 'Expecting 0 whitespace before ")"; found 1', + 'PunctuationSpacing.After:4:4' => 'Expecting 0 whitespace after "{"; found 1', + 'PunctuationSpacing.Before:4:10' => 'Expecting 0 whitespace before ":"; found 1', + 'PunctuationSpacing.Before:4:16' => 'Expecting 0 whitespace before ","; found 1', + 'PunctuationSpacing.Before:4:22' => 'Expecting 0 whitespace before ":"; found 1', + 'PunctuationSpacing.Before:4:28' => 'Expecting 0 whitespace before "}"; found 1', + 'PunctuationSpacing.After:5:12' => 'Expecting 0 whitespace after "["; found 1', + 'PunctuationSpacing.Before:5:16' => 'Expecting 0 whitespace before ","; found 1', + 'PunctuationSpacing.Before:5:20' => 'Expecting 0 whitespace before ","; found 1', + 'PunctuationSpacing.Before:5:24' => 'Expecting 0 whitespace before "]"; found 1', + 'PunctuationSpacing.After:6:6' => 'Expecting 0 whitespace after "|"; found 1', + 'PunctuationSpacing.Before:6:6' => 'Expecting 0 whitespace before "|"; found 1', + 'PunctuationSpacing.Before:7:12' => 'Expecting 0 whitespace before "}"; found 1', + 'PunctuationSpacing.Before:7:15' => 'Expecting 0 whitespace before "]"; found 1', ]); } } diff --git a/tests/Rules/Punctuation/TrailingCommaSingleLine/TrailingCommaSingleLineRuleTest.php b/tests/Rules/Punctuation/TrailingCommaSingleLine/TrailingCommaSingleLineRuleTest.php index 357ec010..06362835 100644 --- a/tests/Rules/Punctuation/TrailingCommaSingleLine/TrailingCommaSingleLineRuleTest.php +++ b/tests/Rules/Punctuation/TrailingCommaSingleLine/TrailingCommaSingleLineRuleTest.php @@ -12,9 +12,9 @@ final class TrailingCommaSingleLineRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new TrailingCommaSingleLineRule(), [ - 'TrailingCommaSingleLine.Error:2:9', - 'TrailingCommaSingleLine.Error:4:13', - 'TrailingCommaSingleLine.Error:6:12', + 'TrailingCommaSingleLine.Error:2:9' => 'Single-line arrays, objects and parameters lists should not have trailing comma.', + 'TrailingCommaSingleLine.Error:4:13' => 'Single-line arrays, objects and parameters lists should not have trailing comma.', + 'TrailingCommaSingleLine.Error:6:12' => 'Single-line arrays, objects and parameters lists should not have trailing comma.', ]); } } diff --git a/tests/Rules/Variable/VariableName/VariableNameRuleTest.php b/tests/Rules/Variable/VariableName/VariableNameRuleTest.php index 7ef024c4..47460fd8 100644 --- a/tests/Rules/Variable/VariableName/VariableNameRuleTest.php +++ b/tests/Rules/Variable/VariableName/VariableNameRuleTest.php @@ -25,33 +25,33 @@ public function testConfiguration(): void public function testRule(): void { $this->checkRule(new VariableNameRule(), [ - 'VariableName.Error:2:8', - 'VariableName.Error:4:8', - 'VariableName.Error:6:8', - 'VariableName.Error:7:8', - 'VariableName.Error:7:16', - 'VariableName.Error:9:8', + 'VariableName.Error:2:8' => 'The var name must use snake_case; expected foo_bar.', + 'VariableName.Error:4:8' => 'The var name must use snake_case; expected foo_bar.', + 'VariableName.Error:6:8' => 'The var name must use snake_case; expected user_foo.', + 'VariableName.Error:7:8' => 'The var name must use snake_case; expected key_foo.', + 'VariableName.Error:7:16' => 'The var name must use snake_case; expected user_foo.', + 'VariableName.Error:9:8' => 'The var name must use snake_case; expected foo_bar.', ]); } public function testRuleCamelCase(): void { $this->checkRule(new VariableNameRule(VariableNameRule::CAMEL_CASE), [ - 'VariableName.Error:3:8', - 'VariableName.Error:4:8', - 'VariableName.Error:9:8', + 'VariableName.Error:3:8' => 'The var name must use camelCase; expected fooBar.', + 'VariableName.Error:4:8' => 'The var name must use camelCase; expected fooBar.', + 'VariableName.Error:9:8' => 'The var name must use camelCase; expected fooBar.', ]); } public function testRulePascalCase(): void { $this->checkRule(new VariableNameRule(VariableNameRule::PASCAL_CASE), [ - 'VariableName.Error:1:8', - 'VariableName.Error:2:8', - 'VariableName.Error:3:8', - 'VariableName.Error:6:8', - 'VariableName.Error:7:8', - 'VariableName.Error:7:16', + 'VariableName.Error:1:8' => 'The var name must use PascalCase; expected Foo.', + 'VariableName.Error:2:8' => 'The var name must use PascalCase; expected FooBar.', + 'VariableName.Error:3:8' => 'The var name must use PascalCase; expected FooBar.', + 'VariableName.Error:6:8' => 'The var name must use PascalCase; expected UserFoo.', + 'VariableName.Error:7:8' => 'The var name must use PascalCase; expected KeyFoo.', + 'VariableName.Error:7:16' => 'The var name must use PascalCase; expected UserFoo.', ]); } } diff --git a/tests/Rules/Whitespace/BlankEOF/BlankEOFRuleTest.php b/tests/Rules/Whitespace/BlankEOF/BlankEOFRuleTest.php index b5e88cb9..5922ac6f 100644 --- a/tests/Rules/Whitespace/BlankEOF/BlankEOFRuleTest.php +++ b/tests/Rules/Whitespace/BlankEOF/BlankEOFRuleTest.php @@ -12,11 +12,11 @@ final class BlankEOFRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new BlankEOFRule(), [ - 'BlankEOF.Error:4:1', + 'BlankEOF.Error:4:1' => 'A file must end with 1 blank line; found 2', ]); $this->checkRule(new BlankEOFRule(), [ - 'BlankEOF.Error:2:7', + 'BlankEOF.Error:2:7' => 'A file must end with 1 blank line; found 0', ], __DIR__.'/BlankEOFRuleTest2.twig'); } @@ -25,7 +25,7 @@ public function testRuleForEmptyFile(): void $this->checkRule(new BlankEOFRule(), [], __DIR__.'/BlankEOFRuleTest.empty.twig'); $this->checkRule(new BlankEOFRule(), [ - 'BlankEOF.Error:3:1', + 'BlankEOF.Error:3:1' => 'A file must end with 1 blank line; found 3', ], __DIR__.'/BlankEOFRuleTest.empty2.twig'); } } diff --git a/tests/Rules/Whitespace/EmptyLines/EmptyLinesRuleTest.php b/tests/Rules/Whitespace/EmptyLines/EmptyLinesRuleTest.php index b456799d..58b93611 100644 --- a/tests/Rules/Whitespace/EmptyLines/EmptyLinesRuleTest.php +++ b/tests/Rules/Whitespace/EmptyLines/EmptyLinesRuleTest.php @@ -12,9 +12,9 @@ final class EmptyLinesRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new EmptyLinesRule(), [ - 'EmptyLines.Error:2:1', - 'EmptyLines.Error:5:1', - 'EmptyLines.Error:10:1', + 'EmptyLines.Error:2:1' => 'More than 1 empty line is not allowed, found 2', + 'EmptyLines.Error:5:1' => 'More than 1 empty line is not allowed, found 2', + 'EmptyLines.Error:10:1' => 'More than 1 empty line is not allowed, found 3', ]); } } diff --git a/tests/Rules/Whitespace/Indent/IndentRuleTest.php b/tests/Rules/Whitespace/Indent/IndentRuleTest.php index 5d7894f2..405f898f 100644 --- a/tests/Rules/Whitespace/Indent/IndentRuleTest.php +++ b/tests/Rules/Whitespace/Indent/IndentRuleTest.php @@ -18,8 +18,8 @@ public function testConfiguration(): void public function testRule(): void { $this->checkRule(new IndentRule(), [ - 'Indent.Error:2:1', - 'Indent.Error:4:1', + 'Indent.Error:2:1' => 'A file must not be indented with tabs.', + 'Indent.Error:4:1' => 'A file must not be indented with tabs.', ]); } @@ -28,8 +28,8 @@ public function testRuleWithSpaceRatio(): void $this->checkRule( new IndentRule(2), [ - 'Indent.Error:2:1', - 'Indent.Error:4:1', + 'Indent.Error:2:1' => 'A file must not be indented with tabs.', + 'Indent.Error:4:1' => 'A file must not be indented with tabs.', ], __DIR__.'/IndentRuleTest.twig', __DIR__.'/IndentRuleTest.fixed2.twig', diff --git a/tests/Rules/Whitespace/TrailingSpace/TrailingSpaceRuleTest.php b/tests/Rules/Whitespace/TrailingSpace/TrailingSpaceRuleTest.php index 34b5e0c2..0d787577 100644 --- a/tests/Rules/Whitespace/TrailingSpace/TrailingSpaceRuleTest.php +++ b/tests/Rules/Whitespace/TrailingSpace/TrailingSpaceRuleTest.php @@ -12,16 +12,16 @@ final class TrailingSpaceRuleTest extends AbstractRuleTestCase public function testRule(): void { $this->checkRule(new TrailingSpaceRule(), [ - 'TrailingSpace.Error:2:33', - 'TrailingSpace.Error:4:23', + 'TrailingSpace.Error:2:33' => 'A line should not end with blank space(s).', + 'TrailingSpace.Error:4:23' => 'A line should not end with blank space(s).', ]); } public function testRuleWithTab(): void { $this->checkRule(new TrailingSpaceRule(), [ - 'TrailingSpace.Error:2:32', - 'TrailingSpace.Error:4:21', + 'TrailingSpace.Error:2:32' => 'A line should not end with blank space(s).', + 'TrailingSpace.Error:4:21' => 'A line should not end with blank space(s).', ], __DIR__.'/TrailingSpaceRuleTest.tab.twig'); } @@ -34,7 +34,7 @@ public function testRuleWithEmptyFile(): void ); $this->checkRule(new TrailingSpaceRule(), [ - 'TrailingSpace.Error:1:2', + 'TrailingSpace.Error:1:2' => 'A line should not end with blank space(s).', ], __DIR__.'/TrailingSpaceRuleTest.empty2.twig'); } } diff --git a/tests/Standard/SymfonyTest.php b/tests/Standard/SymfonyTest.php index 1170732f..c9449715 100644 --- a/tests/Standard/SymfonyTest.php +++ b/tests/Standard/SymfonyTest.php @@ -27,7 +27,7 @@ public function testGetRules(): void new OperatorSpacingRule(), new PunctuationSpacingRule(), new VariableNameRule(), - new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles']), + new FileNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles'], optionalPrefix: '_'), new DirectoryNameRule(baseDirectory: 'templates', ignoredSubDirectories: ['bundles']), new FileExtensionRule(), ], $standard->getRules());