From 26d8bef21683591dbc508b33b5b6c27dca6dce2e Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 28 Nov 2023 14:44:04 +0100 Subject: [PATCH] Rename Sniff to Rule (#155) --- README.md | 18 ++--- src/Cache/CacheEncoder.php | 8 +-- src/Cache/Signature.php | 22 +++--- src/Command/TwigCsFixerCommand.php | 2 +- src/Report/Report.php | 26 +++---- src/Report/Reporter/CheckstyleReporter.php | 10 +-- src/Report/Reporter/GithubReporter.php | 6 +- src/Report/Reporter/JUnitReporter.php | 4 +- src/Report/Reporter/TextReporter.php | 6 +- .../{SniffViolation.php => Violation.php} | 10 +-- .../AbstractRule.php} | 18 ++--- .../AbstractSpacingRule.php} | 4 +- .../BlankEOFRule.php} | 4 +- .../BlockNameSpacingRule.php} | 4 +- .../ConfigurableRuleInterface.php} | 4 +- .../DelimiterSpacingRule.php} | 4 +- .../EmptyLinesRule.php} | 4 +- .../IndentSniff.php => Rules/IndentRule.php} | 4 +- .../OperatorNameSpacingRule.php} | 4 +- .../OperatorSpacingRule.php} | 4 +- .../PunctuationSpacingRule.php} | 4 +- .../RuleInterface.php} | 4 +- .../TrailingCommaSingleLineRule.php} | 4 +- .../TrailingSpaceRule.php} | 4 +- src/Ruleset/Ruleset.php | 28 ++++---- src/Runner/Fixer.php | 8 +-- src/Runner/Linter.php | 44 ++++++------ src/Standard/Generic.php | 28 ++++---- src/Standard/StandardInterface.php | 6 +- src/Standard/Twig.php | 18 ++--- tests/Cache/CacheEncoderTest.php | 20 +++--- .../FileHandler/CacheFileHandlerTest.php | 2 +- tests/Cache/FileHandler/Fixtures/notWritable | 2 +- tests/Cache/FileHandler/Fixtures/readable | 2 +- tests/Cache/FileHandler/Fixtures/writable | 2 +- tests/Cache/SignatureTest.php | 34 +++++----- tests/Command/Fixtures/.twig-cs-fixer.php | 4 +- tests/Command/TwigCsFixerCommandTest.php | 4 +- tests/Config/ConfigTest.php | 4 +- .../.twig-cs-fixer.php | 4 +- .../.twig-cs-fixer.php | 4 +- tests/Report/ReportTest.php | 68 +++++++++---------- .../Reporter/CheckstyleReporterTest.php | 24 +++---- tests/Report/Reporter/GithubReporterTest.php | 10 +-- tests/Report/Reporter/JUnitReporterTest.php | 14 ++-- tests/Report/Reporter/NullReporterTest.php | 10 +-- tests/Report/Reporter/TextReporterTest.php | 24 +++---- tests/Report/SniffViolationTest.php | 24 +++---- .../AbstractRuleTestCase.php} | 16 ++--- .../BlankEOF/BlankEOFTest.empty.twig | 0 .../BlankEOF/BlankEOFTest.empty2.fixed.twig | 0 .../BlankEOF/BlankEOFTest.empty2.twig | 0 .../BlankEOF/BlankEOFTest.fixed.twig | 0 tests/Rules/BlankEOF/BlankEOFTest.php | 31 +++++++++ .../BlankEOF/BlankEOFTest.twig | 0 .../BlankEOF/BlankEOFTest2.fixed.twig | 0 .../BlankEOF/BlankEOFTest2.twig | 0 .../BlockNameSpacingTest.fixed.twig | 0 .../BlockNameSpacing/BlockNameSpacingTest.php | 21 ++++++ .../BlockNameSpacingTest.twig | 0 .../DelimiterSpacingTest.fixed.twig | 0 .../DelimiterSpacing/DelimiterSpacingTest.php | 21 ++++++ .../DelimiterSpacingTest.twig | 0 .../EmptyLines/EmptyLinesTest.fixed.twig | 0 tests/Rules/EmptyLines/EmptyLinesTest.php | 20 ++++++ .../EmptyLines/EmptyLinesTest.twig | 0 .../Fixtures/FakeRule.php} | 6 +- .../Indent/IndentTest.fixed.twig | 0 .../Indent/IndentTest.fixed2.twig | 0 tests/Rules/Indent/IndentTest.php | 38 +++++++++++ tests/{Sniff => Rules}/Indent/IndentTest.twig | 0 .../OperatorNameSpacingTest.fixed.twig | 0 .../OperatorNameSpacingTest.php | 20 ++++++ .../OperatorNameSpacingTest.twig | 0 .../OperatorSpacingTest.fixed.twig | 0 .../OperatorSpacing/OperatorSpacingTest.php | 18 ++--- .../OperatorSpacingTest.tab.fixed.twig | 0 .../OperatorSpacingTest.tab.twig | 0 .../OperatorSpacing/OperatorSpacingTest.twig | 0 .../PunctuationSpacingTest.fixed.twig | 0 .../PunctuationSpacingTest.php | 12 ++-- .../PunctuationSpacingTest.twig | 0 .../SniffTest.php => Rules/RuleTest.php} | 26 +++---- .../SpacingRuleTest.php} | 12 ++-- .../TrailingCommaSingleLineTest.fixed.twig | 0 .../TrailingCommaSingleLineTest.php | 20 ++++++ .../TrailingCommaSingleLineTest.twig | 0 .../TrailingSpaceTest.empty.twig | 0 .../TrailingSpaceTest.empty2.fixed.twig | 0 .../TrailingSpaceTest.empty2.twig | 0 .../TrailingSpaceTest.fixed.twig | 0 .../Rules/TrailingSpace/TrailingSpaceTest.php | 40 +++++++++++ .../TrailingSpaceTest.tab.fixed.twig | 0 .../TrailingSpace/TrailingSpaceTest.tab.twig | 0 .../TrailingSpace/TrailingSpaceTest.twig | 0 tests/Ruleset/RulesetTest.php | 32 ++++----- tests/Runner/FixerTest.php | 32 ++++----- tests/Runner/LinterTest.php | 12 ++-- tests/Sniff/BlankEOF/BlankEOFTest.php | 31 --------- .../BlockNameSpacing/BlockNameSpacingTest.php | 21 ------ .../DelimiterSpacing/DelimiterSpacingTest.php | 21 ------ tests/Sniff/EmptyLines/EmptyLinesTest.php | 20 ------ tests/Sniff/Indent/IndentTest.php | 38 ----------- .../OperatorNameSpacingTest.php | 20 ------ .../TrailingCommaSingleLineTest.php | 20 ------ .../Sniff/TrailingSpace/TrailingSpaceTest.php | 40 ----------- tests/Standard/GenericTest.php | 44 ++++++------ tests/Standard/TwigTest.php | 20 +++--- 108 files changed, 611 insertions(+), 611 deletions(-) rename src/Report/{SniffViolation.php => Violation.php} (90%) rename src/{Sniff/AbstractSniff.php => Rules/AbstractRule.php} (86%) rename src/{Sniff/AbstractSpacingSniff.php => Rules/AbstractSpacingRule.php} (97%) rename src/{Sniff/BlankEOFSniff.php => Rules/BlankEOFRule.php} (94%) rename src/{Sniff/BlockNameSpacingSniff.php => Rules/BlockNameSpacingRule.php} (89%) rename src/{Sniff/ConfigurableSniffInterface.php => Rules/ConfigurableRuleInterface.php} (59%) rename src/{Sniff/DelimiterSpacingSniff.php => Rules/DelimiterSpacingRule.php} (92%) rename src/{Sniff/EmptyLinesSniff.php => Rules/EmptyLinesRule.php} (95%) rename src/{Sniff/IndentSniff.php => Rules/IndentRule.php} (88%) rename src/{Sniff/OperatorNameSpacingSniff.php => Rules/OperatorNameSpacingRule.php} (91%) rename src/{Sniff/OperatorSpacingSniff.php => Rules/OperatorSpacingRule.php} (96%) rename src/{Sniff/PunctuationSpacingSniff.php => Rules/PunctuationSpacingRule.php} (94%) rename src/{Sniff/SniffInterface.php => Rules/RuleInterface.php} (89%) rename src/{Sniff/TrailingCommaSingleLineSniff.php => Rules/TrailingCommaSingleLineRule.php} (93%) rename src/{Sniff/TrailingSpaceSniff.php => Rules/TrailingSpaceRule.php} (90%) rename tests/{Sniff/AbstractSniffTestCase.php => Rules/AbstractRuleTestCase.php} (86%) rename tests/{Sniff => Rules}/BlankEOF/BlankEOFTest.empty.twig (100%) rename tests/{Sniff => Rules}/BlankEOF/BlankEOFTest.empty2.fixed.twig (100%) rename tests/{Sniff => Rules}/BlankEOF/BlankEOFTest.empty2.twig (100%) rename tests/{Sniff => Rules}/BlankEOF/BlankEOFTest.fixed.twig (100%) create mode 100644 tests/Rules/BlankEOF/BlankEOFTest.php rename tests/{Sniff => Rules}/BlankEOF/BlankEOFTest.twig (100%) rename tests/{Sniff => Rules}/BlankEOF/BlankEOFTest2.fixed.twig (100%) rename tests/{Sniff => Rules}/BlankEOF/BlankEOFTest2.twig (100%) rename tests/{Sniff => Rules}/BlockNameSpacing/BlockNameSpacingTest.fixed.twig (100%) create mode 100644 tests/Rules/BlockNameSpacing/BlockNameSpacingTest.php rename tests/{Sniff => Rules}/BlockNameSpacing/BlockNameSpacingTest.twig (100%) rename tests/{Sniff => Rules}/DelimiterSpacing/DelimiterSpacingTest.fixed.twig (100%) create mode 100644 tests/Rules/DelimiterSpacing/DelimiterSpacingTest.php rename tests/{Sniff => Rules}/DelimiterSpacing/DelimiterSpacingTest.twig (100%) rename tests/{Sniff => Rules}/EmptyLines/EmptyLinesTest.fixed.twig (100%) create mode 100644 tests/Rules/EmptyLines/EmptyLinesTest.php rename tests/{Sniff => Rules}/EmptyLines/EmptyLinesTest.twig (100%) rename tests/{Sniff/Fixtures/FakeSniff.php => Rules/Fixtures/FakeRule.php} (50%) rename tests/{Sniff => Rules}/Indent/IndentTest.fixed.twig (100%) rename tests/{Sniff => Rules}/Indent/IndentTest.fixed2.twig (100%) create mode 100644 tests/Rules/Indent/IndentTest.php rename tests/{Sniff => Rules}/Indent/IndentTest.twig (100%) rename tests/{Sniff => Rules}/OperatorNameSpacing/OperatorNameSpacingTest.fixed.twig (100%) create mode 100644 tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.php rename tests/{Sniff => Rules}/OperatorNameSpacing/OperatorNameSpacingTest.twig (100%) rename tests/{Sniff => Rules}/OperatorSpacing/OperatorSpacingTest.fixed.twig (100%) rename tests/{Sniff => Rules}/OperatorSpacing/OperatorSpacingTest.php (74%) rename tests/{Sniff => Rules}/OperatorSpacing/OperatorSpacingTest.tab.fixed.twig (100%) rename tests/{Sniff => Rules}/OperatorSpacing/OperatorSpacingTest.tab.twig (100%) rename tests/{Sniff => Rules}/OperatorSpacing/OperatorSpacingTest.twig (100%) rename tests/{Sniff => Rules}/PunctuationSpacing/PunctuationSpacingTest.fixed.twig (100%) rename tests/{Sniff => Rules}/PunctuationSpacing/PunctuationSpacingTest.php (56%) rename tests/{Sniff => Rules}/PunctuationSpacing/PunctuationSpacingTest.twig (100%) rename tests/{Sniff/SniffTest.php => Rules/RuleTest.php} (85%) rename tests/{Sniff/SpacingSniffTest.php => Rules/SpacingRuleTest.php} (86%) rename tests/{Sniff => Rules}/TrailingCommaSingleLine/TrailingCommaSingleLineTest.fixed.twig (100%) create mode 100644 tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php rename tests/{Sniff => Rules}/TrailingCommaSingleLine/TrailingCommaSingleLineTest.twig (100%) rename tests/{Sniff => Rules}/TrailingSpace/TrailingSpaceTest.empty.twig (100%) rename tests/{Sniff => Rules}/TrailingSpace/TrailingSpaceTest.empty2.fixed.twig (100%) rename tests/{Sniff => Rules}/TrailingSpace/TrailingSpaceTest.empty2.twig (100%) rename tests/{Sniff => Rules}/TrailingSpace/TrailingSpaceTest.fixed.twig (100%) create mode 100644 tests/Rules/TrailingSpace/TrailingSpaceTest.php rename tests/{Sniff => Rules}/TrailingSpace/TrailingSpaceTest.tab.fixed.twig (100%) rename tests/{Sniff => Rules}/TrailingSpace/TrailingSpaceTest.tab.twig (100%) rename tests/{Sniff => Rules}/TrailingSpace/TrailingSpaceTest.twig (100%) delete mode 100644 tests/Sniff/BlankEOF/BlankEOFTest.php delete mode 100644 tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.php delete mode 100644 tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.php delete mode 100644 tests/Sniff/EmptyLines/EmptyLinesTest.php delete mode 100644 tests/Sniff/Indent/IndentTest.php delete mode 100644 tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.php delete mode 100644 tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php delete mode 100644 tests/Sniff/TrailingSpace/TrailingSpaceTest.php diff --git a/README.md b/README.md index 96278015..642f4ab1 100644 --- a/README.md +++ b/README.md @@ -61,16 +61,16 @@ Removes any space before and after opening and closing of arrays and hashes. ### Standard -By default, the generic standard is enabled with the twig coding standard rules and the following sniffs: +By default, the generic standard is enabled with the twig coding standard rules and the following rules: - - `BlankEOFSniff`: ensures that files end with one blank line. - - `BlockNameSpacingSniff`: ensure there is one space before and after block names. - - `EmptyLinesSniff`: ensures that 2 empty lines do not follow each other. - - `IndentSniff`: ensures that files are not indented with tabs. - - `TrailingCommaSingleLineSniff`: ensures that single-line arrays, objects and argument lists do not have a trailing comma. - - `TrailingSpaceSniff`: ensures that files have no trailing spaces. + - `BlankEOFRule`: ensures that files end with one blank line. + - `BlockNameSpacingRule`: ensure 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. + - `TrailingSpaceRule`: ensures that files have no trailing spaces. -If you want to use the basic Twig standard, another standard and/or add/disable a sniff, you can provide +If you want to use the basic Twig standard, another standard and/or add/disable a rule, you can provide your own configuration with a `.twig-cs-fixer.php` file which returns a `TwigCsFixer\Config\Config` class: ```php @@ -78,7 +78,7 @@ your own configuration with a `.twig-cs-fixer.php` file which returns a `TwigCsF $ruleset = new TwigCsFixer\Ruleset\Ruleset(); $ruleset->addStandard(new TwigCsFixer\Standard\Generic()); -$ruleset->removeSniff(TwigCsFixer\Sniff\EmptyLinesSniff::class); +$ruleset->removeRule(TwigCsFixer\Rules\EmptyLinesRule::class); $config = new TwigCsFixer\Config\Config(); $config->setRuleset($ruleset); diff --git a/src/Cache/CacheEncoder.php b/src/Cache/CacheEncoder.php index 9b861129..93a64b12 100644 --- a/src/Cache/CacheEncoder.php +++ b/src/Cache/CacheEncoder.php @@ -31,13 +31,13 @@ public static function fromJson(string $json): Cache Assert::string($data['php_version']); Assert::keyExists($data, 'fixer_version'); Assert::string($data['fixer_version']); - Assert::keyExists($data, 'sniffs'); - Assert::isArray($data['sniffs']); + Assert::keyExists($data, 'rules'); + Assert::isArray($data['rules']); $signature = new Signature( $data['php_version'], $data['fixer_version'], - $data['sniffs'], + $data['rules'], ); $cache = new Cache($signature); @@ -64,7 +64,7 @@ public static function toJson(Cache $cache): string return json_encode([ 'php_version' => $signature->getPhpVersion(), 'fixer_version' => $signature->getFixerVersion(), - 'sniffs' => $signature->getSniffs(), + 'rules' => $signature->getRules(), 'hashes' => $cache->getHashes(), ], \JSON_THROW_ON_ERROR); } diff --git a/src/Cache/Signature.php b/src/Cache/Signature.php index 3d2dc3bb..a5fa871d 100644 --- a/src/Cache/Signature.php +++ b/src/Cache/Signature.php @@ -4,18 +4,18 @@ namespace TwigCsFixer\Cache; +use TwigCsFixer\Rules\ConfigurableRuleInterface; use TwigCsFixer\Ruleset\Ruleset; -use TwigCsFixer\Sniff\ConfigurableSniffInterface; final class Signature { /** - * @param array $sniffs + * @param array $rules */ public function __construct( private string $phpVersion, private string $fixerVersion, - private array $sniffs + private array $rules ) { } @@ -24,14 +24,14 @@ public static function fromRuleset( string $fixerVersion, Ruleset $ruleset, ): self { - $sniffs = []; - foreach ($ruleset->getSniffs() as $sniff) { - $sniffs[$sniff::class] = $sniff instanceof ConfigurableSniffInterface - ? $sniff->getConfiguration() + $rules = []; + foreach ($ruleset->getRules() as $rule) { + $rules[$rule::class] = $rule instanceof ConfigurableRuleInterface + ? $rule->getConfiguration() : null; } - return new self($phpVersion, $fixerVersion, $sniffs); + return new self($phpVersion, $fixerVersion, $rules); } public function getPhpVersion(): string @@ -47,15 +47,15 @@ public function getFixerVersion(): string /** * @return array */ - public function getSniffs(): array + public function getRules(): array { - return $this->sniffs; + return $this->rules; } public function equals(self $signature): bool { return $this->phpVersion === $signature->getPhpVersion() && $this->fixerVersion === $signature->getFixerVersion() - && $this->sniffs === $signature->getSniffs(); + && $this->rules === $signature->getRules(); } } diff --git a/src/Command/TwigCsFixerCommand.php b/src/Command/TwigCsFixerCommand.php index c2cbec0b..6322e5aa 100644 --- a/src/Command/TwigCsFixerCommand.php +++ b/src/Command/TwigCsFixerCommand.php @@ -23,7 +23,7 @@ use Webmozart\Assert\Assert; /** - * TwigCsFixer stands for "Twig Code Sniffer Fixer" and will check twig template of your project. + * TwigCsFixer stands for "Twig Code Style Fixer" and will check twig template of your project. */ final class TwigCsFixerCommand extends Command { diff --git a/src/Report/Report.php b/src/Report/Report.php index e59c7558..94082154 100644 --- a/src/Report/Report.php +++ b/src/Report/Report.php @@ -18,7 +18,7 @@ final class Report public const MESSAGE_TYPE_FATAL = 'FATAL'; /** - * @var array> + * @var array> */ private array $violationsByFile = []; @@ -43,9 +43,9 @@ public function __construct(iterable $files) } } - public function addViolation(SniffViolation $sniffViolation): self + public function addViolation(Violation $violation): self { - $filename = $sniffViolation->getFilename(); + $filename = $violation->getFilename(); if (!isset($this->violationsByFile[$filename])) { throw new InvalidArgumentException( sprintf('The file "%s" is not handled by this report.', $filename) @@ -53,26 +53,26 @@ public function addViolation(SniffViolation $sniffViolation): self } // Update stats - switch ($sniffViolation->getLevel()) { - case SniffViolation::LEVEL_NOTICE: + switch ($violation->getLevel()) { + case Violation::LEVEL_NOTICE: $this->totalNotices++; break; - case SniffViolation::LEVEL_WARNING: + case Violation::LEVEL_WARNING: $this->totalWarnings++; break; - case SniffViolation::LEVEL_ERROR: - case SniffViolation::LEVEL_FATAL: + case Violation::LEVEL_ERROR: + case Violation::LEVEL_FATAL: $this->totalErrors++; break; } - $this->violationsByFile[$filename][] = $sniffViolation; + $this->violationsByFile[$filename][] = $violation; return $this; } /** - * @return list + * @return list */ public function getFileViolations(string $filename, ?string $level = null): array { @@ -89,13 +89,13 @@ public function getFileViolations(string $filename, ?string $level = null): arra return array_values( array_filter( $this->violationsByFile[$filename], - static fn (SniffViolation $message): bool => $message->getLevel() >= SniffViolation::getLevelAsInt($level) + static fn (Violation $message): bool => $message->getLevel() >= Violation::getLevelAsInt($level) ) ); } /** - * @return list + * @return list */ public function getViolations(?string $level = null): array { @@ -108,7 +108,7 @@ public function getViolations(?string $level = null): array return array_values( array_filter( $messages, - static fn (SniffViolation $message): bool => $message->getLevel() >= SniffViolation::getLevelAsInt($level) + static fn (Violation $message): bool => $message->getLevel() >= Violation::getLevelAsInt($level) ) ); } diff --git a/src/Report/Reporter/CheckstyleReporter.php b/src/Report/Reporter/CheckstyleReporter.php index ef114b14..5aff7409 100644 --- a/src/Report/Reporter/CheckstyleReporter.php +++ b/src/Report/Reporter/CheckstyleReporter.php @@ -6,7 +6,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class CheckstyleReporter implements ReporterInterface { @@ -28,7 +28,7 @@ public function display(OutputInterface $output, Report $report, ?string $level foreach ($fileViolations as $violation) { $line = (string) $violation->getLine(); $linePosition = (string) $violation->getLinePosition(); - $sniffName = $violation->getSniffName(); + $ruleName = $violation->getRuleName(); $text .= ' getLevel())).'"'; + $text .= ' severity="'.strtolower(Violation::getLevelAsString($violation->getLevel())).'"'; $text .= ' message="'.$this->xmlEncode($violation->getMessage()).'"'; - if (null !== $sniffName) { - $text .= ' source="'.$sniffName.'"'; + if (null !== $ruleName) { + $text .= ' source="'.$ruleName.'"'; } $text .= '/>'."\n"; } diff --git a/src/Report/Reporter/GithubReporter.php b/src/Report/Reporter/GithubReporter.php index f6f00bf2..25089f55 100644 --- a/src/Report/Reporter/GithubReporter.php +++ b/src/Report/Reporter/GithubReporter.php @@ -6,7 +6,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; /** * Allow errors to be reported in pull-requests diff when run in a GitHub Action @@ -22,8 +22,8 @@ public function display(OutputInterface $output, Report $report, ?string $level $violations = $report->getViolations($level); foreach ($violations as $violation) { $text = match ($violation->getLevel()) { - SniffViolation::LEVEL_NOTICE => '::notice', - SniffViolation::LEVEL_WARNING => '::warning', + Violation::LEVEL_NOTICE => '::notice', + Violation::LEVEL_WARNING => '::warning', default => '::error', }; diff --git a/src/Report/Reporter/JUnitReporter.php b/src/Report/Reporter/JUnitReporter.php index c3a7eb0f..e986615c 100644 --- a/src/Report/Reporter/JUnitReporter.php +++ b/src/Report/Reporter/JUnitReporter.php @@ -6,7 +6,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class JUnitReporter implements ReporterInterface { @@ -29,7 +29,7 @@ public function display(OutputInterface $output, Report $report, ?string $level foreach ($violations as $violation) { $text .= $this->createTestCase( sprintf('%s:%s', $violation->getFilename(), $violation->getLine() ?? 0), - strtolower(SniffViolation::getLevelAsString($violation->getLevel())), + strtolower(Violation::getLevelAsString($violation->getLevel())), $violation->getMessage() ); } diff --git a/src/Report/Reporter/TextReporter.php b/src/Report/Reporter/TextReporter.php index 94889e49..19898a6e 100644 --- a/src/Report/Reporter/TextReporter.php +++ b/src/Report/Reporter/TextReporter.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use TwigCsFixer\Report\Report; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; /** * Human-readable output with context. @@ -68,7 +68,7 @@ public function display(OutputInterface $output, Report $report, ?string $level $rows[] = new TableSeparator(); } - $messageLevel = SniffViolation::getLevelAsString($violation->getLevel()); + $messageLevel = Violation::getLevelAsString($violation->getLevel()); $rows[] = [ new TableCell(sprintf('%s', $messageLevel)), implode("\n", $formattedText), @@ -119,7 +119,7 @@ private function getContext(string $template, int $line): array return array_map(fn (string $code): string => substr($code, min($indents)), $result); } - private function formatErrorMessage(SniffViolation $message): string + private function formatErrorMessage(Violation $message): string { return sprintf( sprintf('%s', self::ERROR_LINE_FORMAT), diff --git a/src/Report/SniffViolation.php b/src/Report/Violation.php similarity index 90% rename from src/Report/SniffViolation.php rename to src/Report/Violation.php index fedc705c..62c1e01b 100644 --- a/src/Report/SniffViolation.php +++ b/src/Report/Violation.php @@ -7,9 +7,9 @@ use InvalidArgumentException; /** - * Wrapper class that represents a violation to a sniff with context. + * Wrapper class that represents a violation to a rule with context. */ -final class SniffViolation +final class Violation { public const LEVEL_NOTICE = 0; public const LEVEL_WARNING = 1; @@ -22,7 +22,7 @@ public function __construct( private string $filename, private ?int $line = null, private ?int $linePosition = null, - private ?string $sniffName = null + private ?string $ruleName = null ) { } @@ -77,8 +77,8 @@ public function getLinePosition(): ?int return $this->linePosition; } - public function getSniffName(): ?string + public function getRuleName(): ?string { - return $this->sniffName; + return $this->ruleName; } } diff --git a/src/Sniff/AbstractSniff.php b/src/Rules/AbstractRule.php similarity index 86% rename from src/Sniff/AbstractSniff.php rename to src/Rules/AbstractRule.php index 016fbad9..c665d54a 100644 --- a/src/Sniff/AbstractSniff.php +++ b/src/Rules/AbstractRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Report\Report; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; use TwigCsFixer\Runner\FixerInterface; use TwigCsFixer\Token\Token; -abstract class AbstractSniff implements SniffInterface +abstract class AbstractRule implements RuleInterface { private ?Report $report = null; @@ -108,22 +108,22 @@ protected function findPrevious(int|string|array $type, array $tokens, int $star protected function addWarning(string $message, Token $token): void { - $this->addMessage(SniffViolation::LEVEL_WARNING, $message, $token); + $this->addMessage(Violation::LEVEL_WARNING, $message, $token); } protected function addError(string $message, Token $token): void { - $this->addMessage(SniffViolation::LEVEL_ERROR, $message, $token); + $this->addMessage(Violation::LEVEL_ERROR, $message, $token); } protected function addFixableWarning(string $message, Token $token): ?FixerInterface { - return $this->addFixableMessage(SniffViolation::LEVEL_WARNING, $message, $token); + return $this->addFixableMessage(Violation::LEVEL_WARNING, $message, $token); } protected function addFixableError(string $message, Token $token): ?FixerInterface { - return $this->addFixableMessage(SniffViolation::LEVEL_ERROR, $message, $token); + return $this->addFixableMessage(Violation::LEVEL_ERROR, $message, $token); } private function addMessage(int $messageType, string $message, Token $token): void @@ -134,7 +134,7 @@ private function addMessage(int $messageType, string $message, Token $token): vo return; } - $sniffViolation = new SniffViolation( + $violation = new Violation( $messageType, $message, $token->getFilename(), @@ -143,7 +143,7 @@ private function addMessage(int $messageType, string $message, Token $token): vo $this->getName(), ); - $report->addViolation($sniffViolation); + $report->addViolation($violation); } private function addFixableMessage(int $messageType, string $message, Token $token): ?FixerInterface diff --git a/src/Sniff/AbstractSpacingSniff.php b/src/Rules/AbstractSpacingRule.php similarity index 97% rename from src/Sniff/AbstractSpacingSniff.php rename to src/Rules/AbstractSpacingRule.php index 4a35228b..67ae13d2 100644 --- a/src/Sniff/AbstractSpacingSniff.php +++ b/src/Rules/AbstractSpacingRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; /** * Ensure there is one space before or after some tokens */ -abstract class AbstractSpacingSniff extends AbstractSniff +abstract class AbstractSpacingRule extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { diff --git a/src/Sniff/BlankEOFSniff.php b/src/Rules/BlankEOFRule.php similarity index 94% rename from src/Sniff/BlankEOFSniff.php rename to src/Rules/BlankEOFRule.php index 4a88e2b8..ec39b133 100644 --- a/src/Sniff/BlankEOFSniff.php +++ b/src/Rules/BlankEOFRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; /** * Ensure that files ends with one blank line. */ -final class BlankEOFSniff extends AbstractSniff +final class BlankEOFRule extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { diff --git a/src/Sniff/BlockNameSpacingSniff.php b/src/Rules/BlockNameSpacingRule.php similarity index 89% rename from src/Sniff/BlockNameSpacingSniff.php rename to src/Rules/BlockNameSpacingRule.php index ef71d532..fb0eea40 100644 --- a/src/Sniff/BlockNameSpacingSniff.php +++ b/src/Rules/BlockNameSpacingRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; /** * Ensure there is one space before and after block names. */ -final class BlockNameSpacingSniff extends AbstractSpacingSniff +final class BlockNameSpacingRule extends AbstractSpacingRule { /** * @param array $tokens diff --git a/src/Sniff/ConfigurableSniffInterface.php b/src/Rules/ConfigurableRuleInterface.php similarity index 59% rename from src/Sniff/ConfigurableSniffInterface.php rename to src/Rules/ConfigurableRuleInterface.php index 9e69d861..679c55d8 100644 --- a/src/Sniff/ConfigurableSniffInterface.php +++ b/src/Rules/ConfigurableRuleInterface.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; -interface ConfigurableSniffInterface extends SniffInterface +interface ConfigurableRuleInterface extends RuleInterface { /** * @return array diff --git a/src/Sniff/DelimiterSpacingSniff.php b/src/Rules/DelimiterSpacingRule.php similarity index 92% rename from src/Sniff/DelimiterSpacingSniff.php rename to src/Rules/DelimiterSpacingRule.php index 30286643..84c4b9d8 100644 --- a/src/Sniff/DelimiterSpacingSniff.php +++ b/src/Rules/DelimiterSpacingRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; /** * Ensure there is one space before '}}', '%}' and '#}', and after '{{', '{%', '{#'. */ -final class DelimiterSpacingSniff extends AbstractSpacingSniff +final class DelimiterSpacingRule extends AbstractSpacingRule { /** * @param array $tokens diff --git a/src/Sniff/EmptyLinesSniff.php b/src/Rules/EmptyLinesRule.php similarity index 95% rename from src/Sniff/EmptyLinesSniff.php rename to src/Rules/EmptyLinesRule.php index 26475aa3..273201ef 100644 --- a/src/Sniff/EmptyLinesSniff.php +++ b/src/Rules/EmptyLinesRule.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; use Webmozart\Assert\Assert; @@ -10,7 +10,7 @@ /** * Checks that there are not 2 empty lines following each other. */ -final class EmptyLinesSniff extends AbstractSniff +final class EmptyLinesRule extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { diff --git a/src/Sniff/IndentSniff.php b/src/Rules/IndentRule.php similarity index 88% rename from src/Sniff/IndentSniff.php rename to src/Rules/IndentRule.php index 33d9dffa..661de4ca 100644 --- a/src/Sniff/IndentSniff.php +++ b/src/Rules/IndentRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; /** * Ensure that files are not indented with tabs. */ -final class IndentSniff extends AbstractSniff implements ConfigurableSniffInterface +final class IndentRule extends AbstractRule implements ConfigurableRuleInterface { public function __construct(private int $spaceRatio = 4) { diff --git a/src/Sniff/OperatorNameSpacingSniff.php b/src/Rules/OperatorNameSpacingRule.php similarity index 91% rename from src/Sniff/OperatorNameSpacingSniff.php rename to src/Rules/OperatorNameSpacingRule.php index 1d618536..9669984a 100644 --- a/src/Sniff/OperatorNameSpacingSniff.php +++ b/src/Rules/OperatorNameSpacingRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; /** * Ensure there is no consecutive spaces inside operator names. */ -final class OperatorNameSpacingSniff extends AbstractSniff +final class OperatorNameSpacingRule extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { diff --git a/src/Sniff/OperatorSpacingSniff.php b/src/Rules/OperatorSpacingRule.php similarity index 96% rename from src/Sniff/OperatorSpacingSniff.php rename to src/Rules/OperatorSpacingRule.php index 57171e08..10b0b12f 100644 --- a/src/Sniff/OperatorSpacingSniff.php +++ b/src/Rules/OperatorSpacingRule.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; use Webmozart\Assert\Assert; @@ -10,7 +10,7 @@ /** * Ensure there is one space before and after an operator except for '..'. */ -final class OperatorSpacingSniff extends AbstractSpacingSniff +final class OperatorSpacingRule extends AbstractSpacingRule { /** * @param array $tokens diff --git a/src/Sniff/PunctuationSpacingSniff.php b/src/Rules/PunctuationSpacingRule.php similarity index 94% rename from src/Sniff/PunctuationSpacingSniff.php rename to src/Rules/PunctuationSpacingRule.php index 56036fc5..2d8ee330 100644 --- a/src/Sniff/PunctuationSpacingSniff.php +++ b/src/Rules/PunctuationSpacingRule.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; use Webmozart\Assert\Assert; @@ -10,7 +10,7 @@ /** * Ensure there is no space before and after a punctuation except for ':' and ','. */ -final class PunctuationSpacingSniff extends AbstractSpacingSniff +final class PunctuationSpacingRule extends AbstractSpacingRule { private const SPACE_BEFORE = [ ')' => 0, diff --git a/src/Sniff/SniffInterface.php b/src/Rules/RuleInterface.php similarity index 89% rename from src/Sniff/SniffInterface.php rename to src/Rules/RuleInterface.php index 9161c774..c2d3bae5 100644 --- a/src/Sniff/SniffInterface.php +++ b/src/Rules/RuleInterface.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Report\Report; use TwigCsFixer\Runner\FixerInterface; use TwigCsFixer\Token\Token; -interface SniffInterface +interface RuleInterface { /** * Messages will be added to the given `$report` object. diff --git a/src/Sniff/TrailingCommaSingleLineSniff.php b/src/Rules/TrailingCommaSingleLineRule.php similarity index 93% rename from src/Sniff/TrailingCommaSingleLineSniff.php rename to src/Rules/TrailingCommaSingleLineRule.php index 10a673e5..c586c937 100644 --- a/src/Sniff/TrailingCommaSingleLineSniff.php +++ b/src/Rules/TrailingCommaSingleLineRule.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; use Webmozart\Assert\Assert; @@ -10,7 +10,7 @@ /** * Ensure that single-line arrays, objects and arguments list does not have a trailing comma. */ -final class TrailingCommaSingleLineSniff extends AbstractSniff +final class TrailingCommaSingleLineRule extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { diff --git a/src/Sniff/TrailingSpaceSniff.php b/src/Rules/TrailingSpaceRule.php similarity index 90% rename from src/Sniff/TrailingSpaceSniff.php rename to src/Rules/TrailingSpaceRule.php index 144032f9..deae9904 100644 --- a/src/Sniff/TrailingSpaceSniff.php +++ b/src/Rules/TrailingSpaceRule.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace TwigCsFixer\Sniff; +namespace TwigCsFixer\Rules; use TwigCsFixer\Token\Token; /** * Ensure that files has no trailing space. */ -final class TrailingSpaceSniff extends AbstractSniff +final class TrailingSpaceRule extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { diff --git a/src/Ruleset/Ruleset.php b/src/Ruleset/Ruleset.php index 0b4501b1..92e02984 100644 --- a/src/Ruleset/Ruleset.php +++ b/src/Ruleset/Ruleset.php @@ -4,45 +4,45 @@ namespace TwigCsFixer\Ruleset; -use TwigCsFixer\Sniff\SniffInterface; +use TwigCsFixer\Rules\RuleInterface; use TwigCsFixer\Standard\StandardInterface; /** - * Set of rules to be used by TwigCsFixer and contains all sniffs. + * Set of rules to be used by TwigCsFixer and contains all rules. */ final class Ruleset { /** - * @var array, SniffInterface> + * @var array, RuleInterface> */ - private array $sniffs = []; + private array $rules = []; /** - * @return array, SniffInterface> + * @return array, RuleInterface> */ - public function getSniffs(): array + public function getRules(): array { - return $this->sniffs; + return $this->rules; } /** * @return $this */ - public function addSniff(SniffInterface $sniff): self + public function addRule(RuleInterface $rule): self { - $this->sniffs[$sniff::class] = $sniff; + $this->rules[$rule::class] = $rule; return $this; } /** - * @param class-string $class + * @param class-string $class * * @return $this */ - public function removeSniff(string $class): self + public function removeRule(string $class): self { - unset($this->sniffs[$class]); + unset($this->rules[$class]); return $this; } @@ -52,8 +52,8 @@ public function removeSniff(string $class): self */ public function addStandard(StandardInterface $standard): self { - foreach ($standard->getSniffs() as $sniff) { - $this->addSniff($sniff); + foreach ($standard->getRules() as $rule) { + $this->addRule($rule); } return $this; diff --git a/src/Runner/Fixer.php b/src/Runner/Fixer.php index fc60dbf9..026b147a 100644 --- a/src/Runner/Fixer.php +++ b/src/Runner/Fixer.php @@ -38,7 +38,7 @@ final class Fixer implements FixerInterface * A list of tokens that have already been fixed. * * We don't allow the same token to be fixed more than once each time through a file - * as this can easily cause conflicts between sniffs. + * as this can easily cause conflicts between rules. * * @var array */ @@ -87,9 +87,9 @@ public function fixFile(string $content, Ruleset $ruleset): string $this->startFile($stream); - $sniffs = $ruleset->getSniffs(); - foreach ($sniffs as $sniff) { - $sniff->fixFile($stream, $this); + $rules = $ruleset->getRules(); + foreach ($rules as $rule) { + $rule->fixFile($stream, $this); } $this->loops++; diff --git a/src/Runner/Linter.php b/src/Runner/Linter.php index 2f786b20..daa96c15 100644 --- a/src/Runner/Linter.php +++ b/src/Runner/Linter.php @@ -13,7 +13,7 @@ use TwigCsFixer\Exception\CannotFixFileException; use TwigCsFixer\Exception\CannotTokenizeException; use TwigCsFixer\Report\Report; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; use TwigCsFixer\Ruleset\Ruleset; use TwigCsFixer\Token\TokenizerInterface; @@ -45,13 +45,13 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $content = @file_get_contents($filePath); if (false === $content) { - $sniffViolation = new SniffViolation( - SniffViolation::LEVEL_FATAL, + $violation = new Violation( + Violation::LEVEL_FATAL, 'Unable to read file.', $filePath ); - $report->addViolation($sniffViolation); + $report->addViolation($violation); continue; } @@ -64,14 +64,14 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $twigSource = new Source($content, $filePath); $this->env->parse($this->env->tokenize($twigSource)); } catch (Error $error) { - $sniffViolation = new SniffViolation( - SniffViolation::LEVEL_FATAL, + $violation = new Violation( + Violation::LEVEL_FATAL, sprintf('File is invalid: %s', $error->getRawMessage()), $filePath, $error->getTemplateLine() ); - $report->addViolation($sniffViolation); + $report->addViolation($violation); continue; } @@ -85,22 +85,22 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $report->addFixedFile($filePath); } } catch (CannotTokenizeException $exception) { - $sniffViolation = new SniffViolation( - SniffViolation::LEVEL_FATAL, + $violation = new Violation( + Violation::LEVEL_FATAL, sprintf('Unable to tokenize file: %s', $exception->getMessage()), $filePath ); - $report->addViolation($sniffViolation); + $report->addViolation($violation); continue; } catch (CannotFixFileException $exception) { - $sniffViolation = new SniffViolation( - SniffViolation::LEVEL_FATAL, + $violation = new Violation( + Violation::LEVEL_FATAL, sprintf('Unable to fix file: %s', $exception->getMessage()), $filePath ); - $report->addViolation($sniffViolation); + $report->addViolation($violation); } } @@ -110,20 +110,20 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = $twigSource = new Source($content, $filePath); $stream = $this->tokenizer->tokenize($twigSource); } catch (CannotTokenizeException $exception) { - $sniffViolation = new SniffViolation( - SniffViolation::LEVEL_FATAL, + $violation = new Violation( + Violation::LEVEL_FATAL, sprintf('Unable to tokenize file: %s', $exception->getMessage()), $filePath ); - $report->addViolation($sniffViolation); + $report->addViolation($violation); continue; } restore_error_handler(); - $sniffs = $ruleset->getSniffs(); - foreach ($sniffs as $sniff) { - $sniff->lintFile($stream, $report); + $rules = $ruleset->getRules(); + foreach ($rules as $rule) { + $rule->lintFile($stream, $report); } // Only cache the file if there is no error in order to @@ -140,13 +140,13 @@ public function run(iterable $files, Ruleset $ruleset, ?FixerInterface $fixer = private function setErrorHandler(Report $report, string $file): void { set_error_handler(static function (int $type, string $message) use ($report, $file): bool { - $sniffViolation = new SniffViolation( - SniffViolation::LEVEL_NOTICE, + $violation = new Violation( + Violation::LEVEL_NOTICE, $message, $file ); - $report->addViolation($sniffViolation); + $report->addViolation($violation); return true; }, \E_USER_DEPRECATED); diff --git a/src/Standard/Generic.php b/src/Standard/Generic.php index 756de0f3..9d3ed730 100644 --- a/src/Standard/Generic.php +++ b/src/Standard/Generic.php @@ -4,28 +4,28 @@ namespace TwigCsFixer\Standard; -use TwigCsFixer\Sniff\BlankEOFSniff; -use TwigCsFixer\Sniff\BlockNameSpacingSniff; -use TwigCsFixer\Sniff\EmptyLinesSniff; -use TwigCsFixer\Sniff\IndentSniff; -use TwigCsFixer\Sniff\TrailingCommaSingleLineSniff; -use TwigCsFixer\Sniff\TrailingSpaceSniff; +use TwigCsFixer\Rules\BlankEOFRule; +use TwigCsFixer\Rules\BlockNameSpacingRule; +use TwigCsFixer\Rules\EmptyLinesRule; +use TwigCsFixer\Rules\IndentRule; +use TwigCsFixer\Rules\TrailingCommaSingleLineRule; +use TwigCsFixer\Rules\TrailingSpaceRule; /** * Default standard from this fixer. */ final class Generic implements StandardInterface { - public function getSniffs(): array + public function getRules(): array { return [ - ...(new Twig())->getSniffs(), - new BlankEOFSniff(), - new BlockNameSpacingSniff(), - new EmptyLinesSniff(), - new IndentSniff(), - new TrailingCommaSingleLineSniff(), - new TrailingSpaceSniff(), + ...(new Twig())->getRules(), + new BlankEOFRule(), + new BlockNameSpacingRule(), + new EmptyLinesRule(), + new IndentRule(), + new TrailingCommaSingleLineRule(), + new TrailingSpaceRule(), ]; } } diff --git a/src/Standard/StandardInterface.php b/src/Standard/StandardInterface.php index fe2b253a..cc4c41f7 100644 --- a/src/Standard/StandardInterface.php +++ b/src/Standard/StandardInterface.php @@ -4,12 +4,12 @@ namespace TwigCsFixer\Standard; -use TwigCsFixer\Sniff\SniffInterface; +use TwigCsFixer\Rules\RuleInterface; interface StandardInterface { /** - * @return SniffInterface[] + * @return RuleInterface[] */ - public function getSniffs(): array; + public function getRules(): array; } diff --git a/src/Standard/Twig.php b/src/Standard/Twig.php index 569800c6..9fc67bd2 100644 --- a/src/Standard/Twig.php +++ b/src/Standard/Twig.php @@ -4,10 +4,10 @@ namespace TwigCsFixer\Standard; -use TwigCsFixer\Sniff\DelimiterSpacingSniff; -use TwigCsFixer\Sniff\OperatorNameSpacingSniff; -use TwigCsFixer\Sniff\OperatorSpacingSniff; -use TwigCsFixer\Sniff\PunctuationSpacingSniff; +use TwigCsFixer\Rules\DelimiterSpacingRule; +use TwigCsFixer\Rules\OperatorNameSpacingRule; +use TwigCsFixer\Rules\OperatorSpacingRule; +use TwigCsFixer\Rules\PunctuationSpacingRule; /** * Standard from twig. @@ -16,13 +16,13 @@ */ class Twig implements StandardInterface { - public function getSniffs(): array + public function getRules(): array { return [ - new DelimiterSpacingSniff(), - new OperatorNameSpacingSniff(), - new OperatorSpacingSniff(), - new PunctuationSpacingSniff(), + new DelimiterSpacingRule(), + new OperatorNameSpacingRule(), + new OperatorSpacingRule(), + new PunctuationSpacingRule(), ]; } } diff --git a/tests/Cache/CacheEncoderTest.php b/tests/Cache/CacheEncoderTest.php index d0f295c2..303b90e6 100644 --- a/tests/Cache/CacheEncoderTest.php +++ b/tests/Cache/CacheEncoderTest.php @@ -10,7 +10,7 @@ use TwigCsFixer\Cache\Cache; use TwigCsFixer\Cache\CacheEncoder; use TwigCsFixer\Cache\Signature; -use TwigCsFixer\Sniff\OperatorSpacingSniff; +use TwigCsFixer\Rules\OperatorSpacingRule; final class CacheEncoderTest extends TestCase { @@ -31,15 +31,15 @@ public static function fromJsonFailureDataProvider(): iterable yield ['']; yield ['null']; yield ['{}']; - yield ['{"php_version":12,"fixer_version":13,"sniffs":[],"hashes":"yes"}']; - yield ['{"php_version":12,"fixer_version":13,"sniffs":[],"hashes":["yes"]}']; - yield ['{"php_version":"7.4","fixer_version":13,"sniffs":[],"hashes":["yes"]}']; - yield ['{"php_version":"7.4","fixer_version":"1.3","sniffs":[],"hashes":["yes"]}']; + yield ['{"php_version":12,"fixer_version":13,"rules":[],"hashes":"yes"}']; + yield ['{"php_version":12,"fixer_version":13,"rules":[],"hashes":["yes"]}']; + yield ['{"php_version":"7.4","fixer_version":13,"rules":[],"hashes":["yes"]}']; + yield ['{"php_version":"7.4","fixer_version":"1.3","rules":[],"hashes":["yes"]}']; } public function testFromJsonSuccess(): void { - $cache = CacheEncoder::fromJson('{"php_version":"7.4","fixer_version":"1.3","sniffs":{"TwigCsFixer\\\\Sniff\\\\OperatorSpacingSniff":null},"hashes":{"folder/file.twig":"bnmdsa678dsa","anotherfolder/anotherfile.twig":"123bnmdsa678dsa"}}'); + $cache = CacheEncoder::fromJson('{"php_version":"7.4","fixer_version":"1.3","rules":{"TwigCsFixer\\\\Rules\\\\OperatorSpacingRule":null},"hashes":{"folder/file.twig":"bnmdsa678dsa","anotherfolder/anotherfile.twig":"123bnmdsa678dsa"}}'); $signature = $cache->getSignature(); static::assertEquals('7.4', $signature->getPhpVersion()); @@ -50,18 +50,18 @@ public function testFromJsonSuccess(): void $cache->getHashes() ); static::assertSame( - [OperatorSpacingSniff::class => null], - $signature->getSniffs() + [OperatorSpacingRule::class => null], + $signature->getRules() ); } public function testToJsonSuccess(): void { - $signature = new Signature('7.4', '1.3', [OperatorSpacingSniff::class => null]); + $signature = new Signature('7.4', '1.3', [OperatorSpacingRule::class => null]); $cache = new Cache($signature); static::assertSame( - '{"php_version":"7.4","fixer_version":"1.3","sniffs":{"TwigCsFixer\\\\Sniff\\\\OperatorSpacingSniff":null},"hashes":[]}', + '{"php_version":"7.4","fixer_version":"1.3","rules":{"TwigCsFixer\\\\Rules\\\\OperatorSpacingRule":null},"hashes":[]}', CacheEncoder::toJson($cache) ); } diff --git a/tests/Cache/FileHandler/CacheFileHandlerTest.php b/tests/Cache/FileHandler/CacheFileHandlerTest.php index 11a0ff72..551690ab 100644 --- a/tests/Cache/FileHandler/CacheFileHandlerTest.php +++ b/tests/Cache/FileHandler/CacheFileHandlerTest.php @@ -91,7 +91,7 @@ public function testWriteSuccess(): void $cacheFileHandler->write(new Cache(new Signature('8.0', '1', []))); $content = file_get_contents($file); - static::assertSame('{"php_version":"8.0","fixer_version":"1","sniffs":[],"hashes":[]}', $content); + static::assertSame('{"php_version":"8.0","fixer_version":"1","rules":[],"hashes":[]}', $content); $permissions = fileperms($file); static::assertNotFalse($permissions); diff --git a/tests/Cache/FileHandler/Fixtures/notWritable b/tests/Cache/FileHandler/Fixtures/notWritable index 417b52ea..e0ab5c29 100644 --- a/tests/Cache/FileHandler/Fixtures/notWritable +++ b/tests/Cache/FileHandler/Fixtures/notWritable @@ -1 +1 @@ -{"php_version":"8.0","fixer_version":"1","sniffs":[],"hashes":[]} +{"php_version":"8.0","fixer_version":"1","rules":[],"hashes":[]} diff --git a/tests/Cache/FileHandler/Fixtures/readable b/tests/Cache/FileHandler/Fixtures/readable index 417b52ea..e0ab5c29 100644 --- a/tests/Cache/FileHandler/Fixtures/readable +++ b/tests/Cache/FileHandler/Fixtures/readable @@ -1 +1 @@ -{"php_version":"8.0","fixer_version":"1","sniffs":[],"hashes":[]} +{"php_version":"8.0","fixer_version":"1","rules":[],"hashes":[]} diff --git a/tests/Cache/FileHandler/Fixtures/writable b/tests/Cache/FileHandler/Fixtures/writable index 417b52ea..e0ab5c29 100644 --- a/tests/Cache/FileHandler/Fixtures/writable +++ b/tests/Cache/FileHandler/Fixtures/writable @@ -1 +1 @@ -{"php_version":"8.0","fixer_version":"1","sniffs":[],"hashes":[]} +{"php_version":"8.0","fixer_version":"1","rules":[],"hashes":[]} diff --git a/tests/Cache/SignatureTest.php b/tests/Cache/SignatureTest.php index 421b52f2..9478ebe5 100644 --- a/tests/Cache/SignatureTest.php +++ b/tests/Cache/SignatureTest.php @@ -6,32 +6,32 @@ use PHPUnit\Framework\TestCase; use TwigCsFixer\Cache\Signature; +use TwigCsFixer\Rules\ConfigurableRuleInterface; +use TwigCsFixer\Rules\OperatorSpacingRule; +use TwigCsFixer\Rules\RuleInterface; use TwigCsFixer\Ruleset\Ruleset; -use TwigCsFixer\Sniff\ConfigurableSniffInterface; -use TwigCsFixer\Sniff\OperatorSpacingSniff; -use TwigCsFixer\Sniff\SniffInterface; final class SignatureTest extends TestCase { public function testSignature(): void { - $signature = new Signature('8.0', '1', [OperatorSpacingSniff::class => null]); + $signature = new Signature('8.0', '1', [OperatorSpacingRule::class => null]); static::assertSame('8.0', $signature->getPhpVersion()); static::assertSame('1', $signature->getFixerVersion()); - static::assertSame([OperatorSpacingSniff::class => null], $signature->getSniffs()); + static::assertSame([OperatorSpacingRule::class => null], $signature->getRules()); } public function testSignatureFromRuleset(): void { $ruleset = new Ruleset(); - $sniff = self::createStub(SniffInterface::class); - $ruleset->addSniff($sniff); + $rule = self::createStub(RuleInterface::class); + $ruleset->addRule($rule); - $configurableSniff = self::createStub(ConfigurableSniffInterface::class); - $configurableSniff->method('getConfiguration')->willReturn(['a' => 1]); - $ruleset->addSniff($configurableSniff); + $configurableRule = self::createStub(ConfigurableRuleInterface::class); + $configurableRule->method('getConfiguration')->willReturn(['a' => 1]); + $ruleset->addRule($configurableRule); $signature = Signature::fromRuleset('8.0', '1', $ruleset); @@ -39,10 +39,10 @@ public function testSignatureFromRuleset(): void static::assertSame('1', $signature->getFixerVersion()); static::assertSame( [ - $sniff::class => null, - $configurableSniff::class => ['a' => 1], + $rule::class => null, + $configurableRule::class => ['a' => 1], ], - $signature->getSniffs() + $signature->getRules() ); } @@ -60,10 +60,10 @@ public function testEquals(Signature $signature1, Signature $signature2, bool $e */ public static function equalsDataProvider(): iterable { - $signature1 = new Signature('8.0', '1', [OperatorSpacingSniff::class => null]); - $signature2 = new Signature('8.0', '1', [OperatorSpacingSniff::class => null]); - $signature3 = new Signature('8.1', '1', [OperatorSpacingSniff::class => null]); - $signature4 = new Signature('8.0', '2', [OperatorSpacingSniff::class => null]); + $signature1 = new Signature('8.0', '1', [OperatorSpacingRule::class => null]); + $signature2 = new Signature('8.0', '1', [OperatorSpacingRule::class => null]); + $signature3 = new Signature('8.1', '1', [OperatorSpacingRule::class => null]); + $signature4 = new Signature('8.0', '2', [OperatorSpacingRule::class => null]); $signature5 = new Signature('8.0', '1', []); yield [$signature1, $signature1, true]; diff --git a/tests/Command/Fixtures/.twig-cs-fixer.php b/tests/Command/Fixtures/.twig-cs-fixer.php index 93977b35..b843a148 100644 --- a/tests/Command/Fixtures/.twig-cs-fixer.php +++ b/tests/Command/Fixtures/.twig-cs-fixer.php @@ -3,13 +3,13 @@ declare(strict_types=1); use TwigCsFixer\Config\Config; +use TwigCsFixer\Rules\DelimiterSpacingRule; use TwigCsFixer\Ruleset\Ruleset; -use TwigCsFixer\Sniff\DelimiterSpacingSniff; use TwigCsFixer\Standard\Generic; $ruleset = new Ruleset(); $ruleset->addStandard(new Generic()); -$ruleset->removeSniff(DelimiterSpacingSniff::class); +$ruleset->removeRule(DelimiterSpacingRule::class); $config = new Config(); $config->setRuleset($ruleset); diff --git a/tests/Command/TwigCsFixerCommandTest.php b/tests/Command/TwigCsFixerCommandTest.php index f5edb463..4f38c40c 100644 --- a/tests/Command/TwigCsFixerCommandTest.php +++ b/tests/Command/TwigCsFixerCommandTest.php @@ -267,7 +267,7 @@ public function testExecuteWithCacheFile(): void $newCache = new Cache(new Signature( '0', $signature->getFixerVersion(), - $signature->getSniffs(), + $signature->getRules(), )); foreach ($hashes as $file => $hash) { $newCache->set($file, $hash); @@ -290,7 +290,7 @@ public function testExecuteWithCacheFile(): void $newCache = new Cache(new Signature( $signature->getPhpVersion(), '0', - $signature->getSniffs(), + $signature->getRules(), )); foreach ($hashes as $file => $hash) { $newCache->set($file, $hash); diff --git a/tests/Config/ConfigTest.php b/tests/Config/ConfigTest.php index 3c0b6602..0e8a06c6 100644 --- a/tests/Config/ConfigTest.php +++ b/tests/Config/ConfigTest.php @@ -31,8 +31,8 @@ public function testConfigRuleset(): void $ruleset = $config->getRuleset(); static::assertEquals( - array_values($genericStandard->getSniffs()), - array_values($ruleset->getSniffs()) + array_values($genericStandard->getRules()), + array_values($ruleset->getRules()) ); $ruleset = new Ruleset(); diff --git a/tests/Config/Fixtures/directoryWithCustomRuleset/.twig-cs-fixer.php b/tests/Config/Fixtures/directoryWithCustomRuleset/.twig-cs-fixer.php index 4b55f33f..a4e28c11 100644 --- a/tests/Config/Fixtures/directoryWithCustomRuleset/.twig-cs-fixer.php +++ b/tests/Config/Fixtures/directoryWithCustomRuleset/.twig-cs-fixer.php @@ -3,13 +3,13 @@ declare(strict_types=1); use TwigCsFixer\Config\Config; +use TwigCsFixer\Rules\DelimiterSpacingRule; use TwigCsFixer\Ruleset\Ruleset; -use TwigCsFixer\Sniff\DelimiterSpacingSniff; use TwigCsFixer\Standard\Generic; $ruleset = new Ruleset(); $ruleset->addStandard(new Generic()); -$ruleset->removeSniff(DelimiterSpacingSniff::class); +$ruleset->removeRule(DelimiterSpacingRule::class); $config = new Config('Custom'); $config->setRuleset($ruleset); diff --git a/tests/Config/Fixtures/directoryWithInvalidConfig/.twig-cs-fixer.php b/tests/Config/Fixtures/directoryWithInvalidConfig/.twig-cs-fixer.php index e08ec600..72f70272 100644 --- a/tests/Config/Fixtures/directoryWithInvalidConfig/.twig-cs-fixer.php +++ b/tests/Config/Fixtures/directoryWithInvalidConfig/.twig-cs-fixer.php @@ -2,12 +2,12 @@ declare(strict_types=1); +use TwigCsFixer\Rules\DelimiterSpacingRule; use TwigCsFixer\Ruleset\Ruleset; -use TwigCsFixer\Sniff\DelimiterSpacingSniff; use TwigCsFixer\Standard\Generic; $ruleset = new Ruleset(); $ruleset->addStandard(new Generic()); -$ruleset->removeSniff(DelimiterSpacingSniff::class); +$ruleset->removeRule(DelimiterSpacingRule::class); return $ruleset; diff --git a/tests/Report/ReportTest.php b/tests/Report/ReportTest.php index 21856c03..e7529f05 100644 --- a/tests/Report/ReportTest.php +++ b/tests/Report/ReportTest.php @@ -7,7 +7,7 @@ use PHPUnit\Framework\TestCase; use SplFileInfo; use TwigCsFixer\Report\Report; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class ReportTest extends TestCase { @@ -34,21 +34,21 @@ public function testReport(): void new SplFileInfo($file3), ]); - $sniffViolation1 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file); - $sniffViolation2 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file); - $sniffViolation3 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file2); - $sniffViolation4 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file); - $sniffViolation5 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file2); - $sniffViolation6 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file3); - $sniffViolation7 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); - - $report->addViolation($sniffViolation1); - $report->addViolation($sniffViolation2); - $report->addViolation($sniffViolation3); - $report->addViolation($sniffViolation4); - $report->addViolation($sniffViolation5); - $report->addViolation($sniffViolation6); - $report->addViolation($sniffViolation7); + $violation1 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file); + $violation2 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file); + $violation3 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file2); + $violation4 = new Violation(Violation::LEVEL_ERROR, 'Error', $file); + $violation5 = new Violation(Violation::LEVEL_ERROR, 'Error', $file2); + $violation6 = new Violation(Violation::LEVEL_ERROR, 'Error', $file3); + $violation7 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); + + $report->addViolation($violation1); + $report->addViolation($violation2); + $report->addViolation($violation3); + $report->addViolation($violation4); + $report->addViolation($violation5); + $report->addViolation($violation6); + $report->addViolation($violation7); static::assertSame(1, $report->getTotalNotices()); static::assertSame(2, $report->getTotalWarnings()); @@ -57,49 +57,49 @@ public function testReport(): void static::assertSame(3, $report->getTotalFiles()); static::assertSame( - [$sniffViolation1, $sniffViolation2, $sniffViolation4, $sniffViolation7], + [$violation1, $violation2, $violation4, $violation7], $report->getFileViolations($file) ); static::assertSame( - [$sniffViolation3, $sniffViolation5], + [$violation3, $violation5], $report->getFileViolations($file2) ); static::assertSame( - [$sniffViolation6], + [$violation6], $report->getFileViolations($file3) ); static::assertSame( [ - $sniffViolation1, - $sniffViolation2, - $sniffViolation4, - $sniffViolation7, - $sniffViolation3, - $sniffViolation5, - $sniffViolation6, + $violation1, + $violation2, + $violation4, + $violation7, + $violation3, + $violation5, + $violation6, ], $report->getViolations() ); static::assertSame( - [$sniffViolation4, $sniffViolation7], + [$violation4, $violation7], $report->getFileViolations($file, Report::MESSAGE_TYPE_ERROR) ); static::assertSame( - [$sniffViolation5], + [$violation5], $report->getFileViolations($file2, Report::MESSAGE_TYPE_ERROR) ); static::assertSame( - [$sniffViolation6], + [$violation6], $report->getFileViolations($file3, Report::MESSAGE_TYPE_ERROR) ); static::assertSame( [ - $sniffViolation4, - $sniffViolation7, - $sniffViolation5, - $sniffViolation6, + $violation4, + $violation7, + $violation5, + $violation6, ], $report->getViolations(Report::MESSAGE_TYPE_ERROR) ); @@ -110,7 +110,7 @@ public function testAddViolationForAnotherFile(): void $report = new Report([new SplFileInfo('file.twig')]); $this->expectExceptionMessage('The file "another_file.twig" is not handled by this report.'); - $report->addViolation(new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Message', 'another_file.twig')); + $report->addViolation(new Violation(Violation::LEVEL_NOTICE, 'Message', 'another_file.twig')); } public function testGetViolationForAnotherFile(): void diff --git a/tests/Report/Reporter/CheckstyleReporterTest.php b/tests/Report/Reporter/CheckstyleReporterTest.php index c6d7a2fd..3bb4c653 100644 --- a/tests/Report/Reporter/CheckstyleReporterTest.php +++ b/tests/Report/Reporter/CheckstyleReporterTest.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\CheckstyleReporter; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class CheckstyleReporterTest extends TestCase { @@ -26,19 +26,19 @@ public function testDisplayErrors(string $expected, ?string $level): void $file3 = __DIR__.'/Fixtures/file3.twig'; $report = new Report([new SplFileInfo($file), new SplFileInfo($file2), new SplFileInfo($file3)]); - $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeSniff'); + $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeRule'); $report->addViolation($violation0); - $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningSniff'); + $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningRule'); $report->addViolation($violation1); - $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorSniff'); + $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorRule'); $report->addViolation($violation2); - $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); + $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); $report->addViolation($violation3); - $violation4 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Sniff'); + $violation4 = new Violation(Violation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Rule'); $report->addViolation($violation4); - $violation5 = new SniffViolation(SniffViolation::LEVEL_FATAL, '\'"<&>"\'', $file3); + $violation5 = new Violation(Violation::LEVEL_FATAL, '\'"<&>"\'', $file3); $report->addViolation($violation5); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); @@ -59,13 +59,13 @@ public static function displayDataProvider(): iterable - - - + + + - + @@ -83,7 +83,7 @@ public static function displayDataProvider(): iterable - + diff --git a/tests/Report/Reporter/GithubReporterTest.php b/tests/Report/Reporter/GithubReporterTest.php index ab5b5d29..b31ce34c 100644 --- a/tests/Report/Reporter/GithubReporterTest.php +++ b/tests/Report/Reporter/GithubReporterTest.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\GithubReporter; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class GithubReporterTest extends TestCase { @@ -24,13 +24,13 @@ public function testDisplayErrors(string $expected, ?string $level): void $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeSniff'); + $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeRule'); $report->addViolation($violation0); - $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningSniff'); + $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningRule'); $report->addViolation($violation1); - $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorSniff'); + $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorRule'); $report->addViolation($violation2); - $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal'."\n".'with new line', $file); + $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal'."\n".'with new line', $file); $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); diff --git a/tests/Report/Reporter/JUnitReporterTest.php b/tests/Report/Reporter/JUnitReporterTest.php index 2c57c313..c8420d49 100644 --- a/tests/Report/Reporter/JUnitReporterTest.php +++ b/tests/Report/Reporter/JUnitReporterTest.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\JUnitReporter; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class JUnitReporterTest extends TestCase { @@ -26,19 +26,19 @@ public function testDisplayErrors(string $expected, ?string $level): void $file3 = __DIR__.'/Fixtures/file3.twig'; $report = new Report([new SplFileInfo($file), new SplFileInfo($file2), new SplFileInfo($file3)]); - $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeSniff'); + $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1, 11, 'NoticeRule'); $report->addViolation($violation0); - $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningSniff'); + $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2, 22, 'WarningRule'); $report->addViolation($violation1); - $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorSniff'); + $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3, 33, 'ErrorRule'); $report->addViolation($violation2); - $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); + $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); $report->addViolation($violation3); - $violation4 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Sniff'); + $violation4 = new Violation(Violation::LEVEL_NOTICE, 'Notice2', $file2, 1, 11, 'Notice2Rule'); $report->addViolation($violation4); - $violation5 = new SniffViolation(SniffViolation::LEVEL_FATAL, '\'"<&>"\'', $file3); + $violation5 = new Violation(Violation::LEVEL_FATAL, '\'"<&>"\'', $file3); $report->addViolation($violation5); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); diff --git a/tests/Report/Reporter/NullReporterTest.php b/tests/Report/Reporter/NullReporterTest.php index eaf39877..d6243b98 100644 --- a/tests/Report/Reporter/NullReporterTest.php +++ b/tests/Report/Reporter/NullReporterTest.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\NullReporter; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class NullReporterTest extends TestCase { @@ -24,13 +24,13 @@ public function testDisplayErrors(?string $level): void $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1); + $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1); $report->addViolation($violation0); - $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2); + $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2); $report->addViolation($violation1); - $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3); + $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3); $report->addViolation($violation2); - $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); + $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); diff --git a/tests/Report/Reporter/TextReporterTest.php b/tests/Report/Reporter/TextReporterTest.php index d5ed2411..e354bf1d 100644 --- a/tests/Report/Reporter/TextReporterTest.php +++ b/tests/Report/Reporter/TextReporterTest.php @@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface; use TwigCsFixer\Report\Report; use TwigCsFixer\Report\Reporter\TextReporter; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class TextReporterTest extends TestCase { @@ -24,13 +24,13 @@ public function testDisplayErrors(string $expected, ?string $level): void $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation0 = new SniffViolation(SniffViolation::LEVEL_NOTICE, 'Notice', $file, 1); + $violation0 = new Violation(Violation::LEVEL_NOTICE, 'Notice', $file, 1); $report->addViolation($violation0); - $violation1 = new SniffViolation(SniffViolation::LEVEL_WARNING, 'Warning', $file, 2); + $violation1 = new Violation(Violation::LEVEL_WARNING, 'Warning', $file, 2); $report->addViolation($violation1); - $violation2 = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3); + $violation2 = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3); $report->addViolation($violation2); - $violation3 = new SniffViolation(SniffViolation::LEVEL_FATAL, 'Fatal', $file); + $violation3 = new Violation(Violation::LEVEL_FATAL, 'Fatal', $file); $report->addViolation($violation3); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); @@ -115,7 +115,7 @@ public function testDisplayMultipleFiles(): void $file2 = __DIR__.'/Fixtures/file2.twig'; $report = new Report([new SplFileInfo($file), new SplFileInfo($file2)]); - $violation = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 3); + $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 3); $report->addViolation($violation); $output = new BufferedOutput(); @@ -147,7 +147,7 @@ public function testDisplayNotFoundFile(): void $file = __DIR__.'/Fixtures/fileNotFound.twig'; $report = new Report([new SplFileInfo($file)]); - $violation = new SniffViolation(SniffViolation::LEVEL_ERROR, 'Error', $file, 1); + $violation = new Violation(Violation::LEVEL_ERROR, 'Error', $file, 1); $report->addViolation($violation); $output = new BufferedOutput(); @@ -177,7 +177,7 @@ public function testDisplayBlock(string $expected, int $level): void $file = __DIR__.'/Fixtures/file.twig'; $report = new Report([new SplFileInfo($file)]); - $violation = new SniffViolation($level, 'Message', $file, 1); + $violation = new Violation($level, 'Message', $file, 1); $report->addViolation($violation); $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); @@ -192,9 +192,9 @@ public function testDisplayBlock(string $expected, int $level): void */ public static function displayBlockDataProvider(): iterable { - yield ['[OK] Files linted: 1, notices: 1, warnings: 0, errors: 0', SniffViolation::LEVEL_NOTICE]; - yield ['[WARNING] Files linted: 1, notices: 0, warnings: 1, errors: 0', SniffViolation::LEVEL_WARNING]; - yield ['[ERROR] Files linted: 1, notices: 0, warnings: 0, errors: 1', SniffViolation::LEVEL_ERROR]; - yield ['[ERROR] Files linted: 1, notices: 0, warnings: 0, errors: 1', SniffViolation::LEVEL_FATAL]; + yield ['[OK] Files linted: 1, notices: 1, warnings: 0, errors: 0', Violation::LEVEL_NOTICE]; + yield ['[WARNING] Files linted: 1, notices: 0, warnings: 1, errors: 0', Violation::LEVEL_WARNING]; + yield ['[ERROR] Files linted: 1, notices: 0, warnings: 0, errors: 1', Violation::LEVEL_ERROR]; + yield ['[ERROR] Files linted: 1, notices: 0, warnings: 0, errors: 1', Violation::LEVEL_FATAL]; } } diff --git a/tests/Report/SniffViolationTest.php b/tests/Report/SniffViolationTest.php index 52d81d35..25a7563f 100644 --- a/tests/Report/SniffViolationTest.php +++ b/tests/Report/SniffViolationTest.php @@ -5,19 +5,19 @@ namespace TwigCsFixer\Tests\Report; use PHPUnit\Framework\TestCase; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; final class SniffViolationTest extends TestCase { public function testGetters(): void { - $sniffViolation = new SniffViolation(SniffViolation::LEVEL_WARNING, 'message', 'filename', 42, 33, 'name'); - static::assertSame(SniffViolation::LEVEL_WARNING, $sniffViolation->getLevel()); - static::assertSame('message', $sniffViolation->getMessage()); - static::assertSame('filename', $sniffViolation->getFilename()); - static::assertSame(42, $sniffViolation->getLine()); - static::assertSame(33, $sniffViolation->getLinePosition()); - static::assertSame('name', $sniffViolation->getSniffName()); + $violation = new Violation(Violation::LEVEL_WARNING, 'message', 'filename', 42, 33, 'name'); + static::assertSame(Violation::LEVEL_WARNING, $violation->getLevel()); + static::assertSame('message', $violation->getMessage()); + static::assertSame('filename', $violation->getFilename()); + static::assertSame(42, $violation->getLine()); + static::assertSame(33, $violation->getLinePosition()); + static::assertSame('name', $violation->getRuleName()); } /** @@ -25,7 +25,7 @@ public function testGetters(): void */ public function testGetLevelAsString(string $expected, int $level): void { - static::assertSame($expected, SniffViolation::getLevelAsString($level)); + static::assertSame($expected, Violation::getLevelAsString($level)); } /** @@ -42,7 +42,7 @@ public static function getLevelAsStringDataProvider(): iterable public function testGetLevelAsStringException(): void { $this->expectExceptionMessage('Level "4" is not supported.'); - SniffViolation::getLevelAsString(4); + Violation::getLevelAsString(4); } /** @@ -50,7 +50,7 @@ public function testGetLevelAsStringException(): void */ public function testGetLevelAsInt(int $expected, string $level): void { - static::assertSame($expected, SniffViolation::getLevelAsInt($level)); + static::assertSame($expected, Violation::getLevelAsInt($level)); } /** @@ -69,6 +69,6 @@ public static function getLevelAsIntDataProvider(): iterable public function testGetLevelAsIntException(): void { $this->expectExceptionMessage('Level "Yolo" is not supported.'); - SniffViolation::getLevelAsInt('Yolo'); + Violation::getLevelAsInt('Yolo'); } } diff --git a/tests/Sniff/AbstractSniffTestCase.php b/tests/Rules/AbstractRuleTestCase.php similarity index 86% rename from tests/Sniff/AbstractSniffTestCase.php rename to tests/Rules/AbstractRuleTestCase.php index 7843b0bf..fc492844 100644 --- a/tests/Sniff/AbstractSniffTestCase.php +++ b/tests/Rules/AbstractRuleTestCase.php @@ -2,27 +2,27 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Sniff; +namespace TwigCsFixer\Tests\Rules; use PHPUnit\Framework\TestCase; use ReflectionClass; use SplFileInfo; use TwigCsFixer\Environment\StubbedEnvironment; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; +use TwigCsFixer\Rules\RuleInterface; use TwigCsFixer\Ruleset\Ruleset; use TwigCsFixer\Runner\Fixer; use TwigCsFixer\Runner\Linter; -use TwigCsFixer\Sniff\SniffInterface; use TwigCsFixer\Tests\TestHelper; use TwigCsFixer\Token\Tokenizer; -abstract class AbstractSniffTestCase extends TestCase +abstract class AbstractRuleTestCase extends TestCase { /** * @param array> $expects */ - protected function checkSniff( - SniffInterface $sniff, + protected function checkRule( + RuleInterface $rule, array $expects, ?string $filePath = null, ?string $fixedFilePath = null @@ -34,7 +34,7 @@ protected function checkSniff( $filePath ??= $this->generateFilePath(); - $ruleset->addSniff($sniff); + $ruleset->addRule($rule); $report = $linter->run([new SplFileInfo($filePath)], $ruleset); $fixedFilePath ??= substr($filePath, 0, -5).'.fixed.twig'; @@ -54,7 +54,7 @@ protected function checkSniff( /** @var array> $messagePositions */ $messagePositions = []; foreach ($messages as $message) { - if (SniffViolation::LEVEL_FATAL === $message->getLevel()) { + if (Violation::LEVEL_FATAL === $message->getLevel()) { $errorMessage = $message->getMessage(); $line = $message->getLine(); diff --git a/tests/Sniff/BlankEOF/BlankEOFTest.empty.twig b/tests/Rules/BlankEOF/BlankEOFTest.empty.twig similarity index 100% rename from tests/Sniff/BlankEOF/BlankEOFTest.empty.twig rename to tests/Rules/BlankEOF/BlankEOFTest.empty.twig diff --git a/tests/Sniff/BlankEOF/BlankEOFTest.empty2.fixed.twig b/tests/Rules/BlankEOF/BlankEOFTest.empty2.fixed.twig similarity index 100% rename from tests/Sniff/BlankEOF/BlankEOFTest.empty2.fixed.twig rename to tests/Rules/BlankEOF/BlankEOFTest.empty2.fixed.twig diff --git a/tests/Sniff/BlankEOF/BlankEOFTest.empty2.twig b/tests/Rules/BlankEOF/BlankEOFTest.empty2.twig similarity index 100% rename from tests/Sniff/BlankEOF/BlankEOFTest.empty2.twig rename to tests/Rules/BlankEOF/BlankEOFTest.empty2.twig diff --git a/tests/Sniff/BlankEOF/BlankEOFTest.fixed.twig b/tests/Rules/BlankEOF/BlankEOFTest.fixed.twig similarity index 100% rename from tests/Sniff/BlankEOF/BlankEOFTest.fixed.twig rename to tests/Rules/BlankEOF/BlankEOFTest.fixed.twig diff --git a/tests/Rules/BlankEOF/BlankEOFTest.php b/tests/Rules/BlankEOF/BlankEOFTest.php new file mode 100644 index 00000000..eb52888c --- /dev/null +++ b/tests/Rules/BlankEOF/BlankEOFTest.php @@ -0,0 +1,31 @@ +checkRule(new BlankEOFRule(), [ + [4 => 1], + ]); + + $this->checkRule(new BlankEOFRule(), [ + [2 => 7], + ], __DIR__.'/BlankEOFTest2.twig'); + } + + public function testRuleForEmptyFile(): void + { + $this->checkRule(new BlankEOFRule(), [], __DIR__.'/BlankEOFTest.empty.twig'); + + $this->checkRule(new BlankEOFRule(), [ + [3 => 1], + ], __DIR__.'/BlankEOFTest.empty2.twig'); + } +} diff --git a/tests/Sniff/BlankEOF/BlankEOFTest.twig b/tests/Rules/BlankEOF/BlankEOFTest.twig similarity index 100% rename from tests/Sniff/BlankEOF/BlankEOFTest.twig rename to tests/Rules/BlankEOF/BlankEOFTest.twig diff --git a/tests/Sniff/BlankEOF/BlankEOFTest2.fixed.twig b/tests/Rules/BlankEOF/BlankEOFTest2.fixed.twig similarity index 100% rename from tests/Sniff/BlankEOF/BlankEOFTest2.fixed.twig rename to tests/Rules/BlankEOF/BlankEOFTest2.fixed.twig diff --git a/tests/Sniff/BlankEOF/BlankEOFTest2.twig b/tests/Rules/BlankEOF/BlankEOFTest2.twig similarity index 100% rename from tests/Sniff/BlankEOF/BlankEOFTest2.twig rename to tests/Rules/BlankEOF/BlankEOFTest2.twig diff --git a/tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.fixed.twig b/tests/Rules/BlockNameSpacing/BlockNameSpacingTest.fixed.twig similarity index 100% rename from tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.fixed.twig rename to tests/Rules/BlockNameSpacing/BlockNameSpacingTest.fixed.twig diff --git a/tests/Rules/BlockNameSpacing/BlockNameSpacingTest.php b/tests/Rules/BlockNameSpacing/BlockNameSpacingTest.php new file mode 100644 index 00000000..9aebbae7 --- /dev/null +++ b/tests/Rules/BlockNameSpacing/BlockNameSpacingTest.php @@ -0,0 +1,21 @@ +checkRule(new BlockNameSpacingRule(), [ + [1 => 5], + [1 => 5], + [3 => 3], + [3 => 3], + ]); + } +} diff --git a/tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.twig b/tests/Rules/BlockNameSpacing/BlockNameSpacingTest.twig similarity index 100% rename from tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.twig rename to tests/Rules/BlockNameSpacing/BlockNameSpacingTest.twig diff --git a/tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.fixed.twig b/tests/Rules/DelimiterSpacing/DelimiterSpacingTest.fixed.twig similarity index 100% rename from tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.fixed.twig rename to tests/Rules/DelimiterSpacing/DelimiterSpacingTest.fixed.twig diff --git a/tests/Rules/DelimiterSpacing/DelimiterSpacingTest.php b/tests/Rules/DelimiterSpacing/DelimiterSpacingTest.php new file mode 100644 index 00000000..042a480a --- /dev/null +++ b/tests/Rules/DelimiterSpacing/DelimiterSpacingTest.php @@ -0,0 +1,21 @@ +checkRule(new DelimiterSpacingRule(), [ + [15 => 1], + [15 => 12], + [15 => 15], + [15 => 25], + ]); + } +} diff --git a/tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.twig b/tests/Rules/DelimiterSpacing/DelimiterSpacingTest.twig similarity index 100% rename from tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.twig rename to tests/Rules/DelimiterSpacing/DelimiterSpacingTest.twig diff --git a/tests/Sniff/EmptyLines/EmptyLinesTest.fixed.twig b/tests/Rules/EmptyLines/EmptyLinesTest.fixed.twig similarity index 100% rename from tests/Sniff/EmptyLines/EmptyLinesTest.fixed.twig rename to tests/Rules/EmptyLines/EmptyLinesTest.fixed.twig diff --git a/tests/Rules/EmptyLines/EmptyLinesTest.php b/tests/Rules/EmptyLines/EmptyLinesTest.php new file mode 100644 index 00000000..9e0962fe --- /dev/null +++ b/tests/Rules/EmptyLines/EmptyLinesTest.php @@ -0,0 +1,20 @@ +checkRule(new EmptyLinesRule(), [ + [2 => 1], + [5 => 1], + [10 => 1], + ]); + } +} diff --git a/tests/Sniff/EmptyLines/EmptyLinesTest.twig b/tests/Rules/EmptyLines/EmptyLinesTest.twig similarity index 100% rename from tests/Sniff/EmptyLines/EmptyLinesTest.twig rename to tests/Rules/EmptyLines/EmptyLinesTest.twig diff --git a/tests/Sniff/Fixtures/FakeSniff.php b/tests/Rules/Fixtures/FakeRule.php similarity index 50% rename from tests/Sniff/Fixtures/FakeSniff.php rename to tests/Rules/Fixtures/FakeRule.php index 80d2f009..e5238b77 100644 --- a/tests/Sniff/Fixtures/FakeSniff.php +++ b/tests/Rules/Fixtures/FakeRule.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Sniff\Fixtures; +namespace TwigCsFixer\Tests\Rules\Fixtures; -use TwigCsFixer\Sniff\AbstractSniff; +use TwigCsFixer\Rules\AbstractRule; -class FakeSniff extends AbstractSniff +class FakeRule extends AbstractRule { public function process(int $tokenPosition, array $tokens): void { diff --git a/tests/Sniff/Indent/IndentTest.fixed.twig b/tests/Rules/Indent/IndentTest.fixed.twig similarity index 100% rename from tests/Sniff/Indent/IndentTest.fixed.twig rename to tests/Rules/Indent/IndentTest.fixed.twig diff --git a/tests/Sniff/Indent/IndentTest.fixed2.twig b/tests/Rules/Indent/IndentTest.fixed2.twig similarity index 100% rename from tests/Sniff/Indent/IndentTest.fixed2.twig rename to tests/Rules/Indent/IndentTest.fixed2.twig diff --git a/tests/Rules/Indent/IndentTest.php b/tests/Rules/Indent/IndentTest.php new file mode 100644 index 00000000..35c3f56b --- /dev/null +++ b/tests/Rules/Indent/IndentTest.php @@ -0,0 +1,38 @@ + 4], (new IndentRule())->getConfiguration()); + static::assertSame(['space_ratio' => 2], (new IndentRule(2))->getConfiguration()); + } + + public function testRule(): void + { + $this->checkRule(new IndentRule(), [ + [2 => 1], + [4 => 1], + ]); + } + + public function testRuleWithSpaceRatio(): void + { + $this->checkRule( + new IndentRule(2), + [ + [2 => 1], + [4 => 1], + ], + __DIR__.'/IndentTest.twig', + __DIR__.'/IndentTest.fixed2.twig', + ); + } +} diff --git a/tests/Sniff/Indent/IndentTest.twig b/tests/Rules/Indent/IndentTest.twig similarity index 100% rename from tests/Sniff/Indent/IndentTest.twig rename to tests/Rules/Indent/IndentTest.twig diff --git a/tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.fixed.twig b/tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.fixed.twig similarity index 100% rename from tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.fixed.twig rename to tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.fixed.twig diff --git a/tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.php b/tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.php new file mode 100644 index 00000000..6ba0c7b6 --- /dev/null +++ b/tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.php @@ -0,0 +1,20 @@ +checkRule(new OperatorNameSpacingRule(), [ + [2 => 13], + [3 => 13], + [4 => 10], + ]); + } +} diff --git a/tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.twig b/tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.twig similarity index 100% rename from tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.twig rename to tests/Rules/OperatorNameSpacing/OperatorNameSpacingTest.twig diff --git a/tests/Sniff/OperatorSpacing/OperatorSpacingTest.fixed.twig b/tests/Rules/OperatorSpacing/OperatorSpacingTest.fixed.twig similarity index 100% rename from tests/Sniff/OperatorSpacing/OperatorSpacingTest.fixed.twig rename to tests/Rules/OperatorSpacing/OperatorSpacingTest.fixed.twig diff --git a/tests/Sniff/OperatorSpacing/OperatorSpacingTest.php b/tests/Rules/OperatorSpacing/OperatorSpacingTest.php similarity index 74% rename from tests/Sniff/OperatorSpacing/OperatorSpacingTest.php rename to tests/Rules/OperatorSpacing/OperatorSpacingTest.php index 56bdf161..43c4440c 100644 --- a/tests/Sniff/OperatorSpacing/OperatorSpacingTest.php +++ b/tests/Rules/OperatorSpacing/OperatorSpacingTest.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Sniff\OperatorSpacing; +namespace TwigCsFixer\Tests\Rules\OperatorSpacing; -use TwigCsFixer\Sniff\OperatorSpacingSniff; -use TwigCsFixer\Tests\Sniff\AbstractSniffTestCase; +use TwigCsFixer\Rules\OperatorSpacingRule; +use TwigCsFixer\Tests\Rules\AbstractRuleTestCase; -final class OperatorSpacingTest extends AbstractSniffTestCase +final class OperatorSpacingTest extends AbstractRuleTestCase { - public function testSniff(): void + public function testRule(): void { - $this->checkSniff(new OperatorSpacingSniff(), [ + $this->checkRule(new OperatorSpacingRule(), [ [1 => 5], [1 => 5], [2 => 5], @@ -59,10 +59,10 @@ public function testSniff(): void ]); } - public function testSniffWithTab(): void + public function testRuleWithTab(): void { - $this->checkSniff( - new OperatorSpacingSniff(), + $this->checkRule( + new OperatorSpacingRule(), [], __DIR__.'/OperatorSpacingTest.tab.twig' ); diff --git a/tests/Sniff/OperatorSpacing/OperatorSpacingTest.tab.fixed.twig b/tests/Rules/OperatorSpacing/OperatorSpacingTest.tab.fixed.twig similarity index 100% rename from tests/Sniff/OperatorSpacing/OperatorSpacingTest.tab.fixed.twig rename to tests/Rules/OperatorSpacing/OperatorSpacingTest.tab.fixed.twig diff --git a/tests/Sniff/OperatorSpacing/OperatorSpacingTest.tab.twig b/tests/Rules/OperatorSpacing/OperatorSpacingTest.tab.twig similarity index 100% rename from tests/Sniff/OperatorSpacing/OperatorSpacingTest.tab.twig rename to tests/Rules/OperatorSpacing/OperatorSpacingTest.tab.twig diff --git a/tests/Sniff/OperatorSpacing/OperatorSpacingTest.twig b/tests/Rules/OperatorSpacing/OperatorSpacingTest.twig similarity index 100% rename from tests/Sniff/OperatorSpacing/OperatorSpacingTest.twig rename to tests/Rules/OperatorSpacing/OperatorSpacingTest.twig diff --git a/tests/Sniff/PunctuationSpacing/PunctuationSpacingTest.fixed.twig b/tests/Rules/PunctuationSpacing/PunctuationSpacingTest.fixed.twig similarity index 100% rename from tests/Sniff/PunctuationSpacing/PunctuationSpacingTest.fixed.twig rename to tests/Rules/PunctuationSpacing/PunctuationSpacingTest.fixed.twig diff --git a/tests/Sniff/PunctuationSpacing/PunctuationSpacingTest.php b/tests/Rules/PunctuationSpacing/PunctuationSpacingTest.php similarity index 56% rename from tests/Sniff/PunctuationSpacing/PunctuationSpacingTest.php rename to tests/Rules/PunctuationSpacing/PunctuationSpacingTest.php index e56b1ec4..986d8c04 100644 --- a/tests/Sniff/PunctuationSpacing/PunctuationSpacingTest.php +++ b/tests/Rules/PunctuationSpacing/PunctuationSpacingTest.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Sniff\PunctuationSpacing; +namespace TwigCsFixer\Tests\Rules\PunctuationSpacing; -use TwigCsFixer\Sniff\PunctuationSpacingSniff; -use TwigCsFixer\Tests\Sniff\AbstractSniffTestCase; +use TwigCsFixer\Rules\PunctuationSpacingRule; +use TwigCsFixer\Tests\Rules\AbstractRuleTestCase; -final class PunctuationSpacingTest extends AbstractSniffTestCase +final class PunctuationSpacingTest extends AbstractRuleTestCase { - public function testSniff(): void + public function testRule(): void { - $this->checkSniff(new PunctuationSpacingSniff(), [ + $this->checkRule(new PunctuationSpacingRule(), [ [3 => 4], [3 => 10], [4 => 4], diff --git a/tests/Sniff/PunctuationSpacing/PunctuationSpacingTest.twig b/tests/Rules/PunctuationSpacing/PunctuationSpacingTest.twig similarity index 100% rename from tests/Sniff/PunctuationSpacing/PunctuationSpacingTest.twig rename to tests/Rules/PunctuationSpacing/PunctuationSpacingTest.twig diff --git a/tests/Sniff/SniffTest.php b/tests/Rules/RuleTest.php similarity index 85% rename from tests/Sniff/SniffTest.php rename to tests/Rules/RuleTest.php index 8448f67d..e48abb7c 100644 --- a/tests/Sniff/SniffTest.php +++ b/tests/Rules/RuleTest.php @@ -2,22 +2,22 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Sniff; +namespace TwigCsFixer\Tests\Rules; use PHPUnit\Framework\TestCase; use SplFileInfo; use TwigCsFixer\Report\Report; -use TwigCsFixer\Sniff\AbstractSniff; -use TwigCsFixer\Tests\Sniff\Fixtures\FakeSniff; +use TwigCsFixer\Rules\AbstractRule; +use TwigCsFixer\Tests\Rules\Fixtures\FakeRule; use TwigCsFixer\Token\Token; -final class SniffTest extends TestCase +final class RuleTest extends TestCase { - public function testSniffWithReport(): void + public function testRuleWithReport(): void { $report = new Report([new SplFileInfo('fakeFile.html.twig')]); - $sniff = new class () extends AbstractSniff { + $rule = new class () extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { $token = $tokens[$tokenPosition]; @@ -31,23 +31,23 @@ protected function process(int $tokenPosition, array $tokens): void } }; - $sniff->lintFile([new Token(Token::EOF_TYPE, 0, 0, 'fakeFile.html.twig')], $report); + $rule->lintFile([new Token(Token::EOF_TYPE, 0, 0, 'fakeFile.html.twig')], $report); static::assertSame(2, $report->getTotalWarnings()); static::assertSame(2, $report->getTotalErrors()); } - public function testSniffName(): void + public function testRuleName(): void { - $sniff = new FakeSniff(); - static::assertSame(FakeSniff::class, $sniff->getName()); + $rule = new FakeRule(); + static::assertSame(FakeRule::class, $rule->getName()); } - public function testSniffWithReport2(): void + public function testRuleWithReport2(): void { $report = new Report([new SplFileInfo('fakeFile.html.twig')]); - $sniff = new class () extends AbstractSniff { + $rule = new class () extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { $token = $tokens[$tokenPosition]; @@ -93,7 +93,7 @@ protected function process(int $tokenPosition, array $tokens): void } } }; - $sniff->lintFile([ + $rule->lintFile([ new Token(Token::TEXT_TYPE, 0, 0, 'fakeFile.html.twig'), new Token(Token::EOL_TYPE, 1, 0, 'fakeFile.html.twig'), new Token(Token::EOL_TYPE, 2, 0, 'fakeFile.html.twig'), diff --git a/tests/Sniff/SpacingSniffTest.php b/tests/Rules/SpacingRuleTest.php similarity index 86% rename from tests/Sniff/SpacingSniffTest.php rename to tests/Rules/SpacingRuleTest.php index e41e5762..8601dc2f 100644 --- a/tests/Sniff/SpacingSniffTest.php +++ b/tests/Rules/SpacingRuleTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace TwigCsFixer\Tests\Sniff; +namespace TwigCsFixer\Tests\Rules; use PHPUnit\Framework\TestCase; +use TwigCsFixer\Rules\AbstractSpacingRule; use TwigCsFixer\Runner\FixerInterface; -use TwigCsFixer\Sniff\AbstractSpacingSniff; use TwigCsFixer\Token\Token; -final class SpacingSniffTest extends TestCase +final class SpacingRuleTest extends TestCase { - public function testSpacingSniff(): void + public function testSpacingRule(): void { - $sniff = new class () extends AbstractSpacingSniff { + $rule = new class () extends AbstractSpacingRule { protected function getSpaceBefore(int $tokenPosition, array $tokens): ?int { $token = $tokens[$tokenPosition]; @@ -49,7 +49,7 @@ protected function getSpaceAfter(int $tokenPosition, array $tokens): ?int $fixer->expects(static::once())->method('addContent')->with(0, ' '); $fixer->expects(static::once())->method('addContentBefore')->with(5, ' '); - $sniff->fixFile([ + $rule->fixFile([ new Token(Token::TEXT_TYPE, 0, 0, 'fakeFile.html.twig'), new Token(Token::TEXT_TYPE, 1, 0, 'fakeFile.html.twig'), new Token(Token::TEXT_TYPE, 2, 0, 'fakeFile.html.twig'), diff --git a/tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.fixed.twig b/tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.fixed.twig similarity index 100% rename from tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.fixed.twig rename to tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.fixed.twig diff --git a/tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php b/tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php new file mode 100644 index 00000000..aec65582 --- /dev/null +++ b/tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php @@ -0,0 +1,20 @@ +checkRule(new TrailingCommaSingleLineRule(), [ + [2 => 9], + [4 => 13], + [6 => 12], + ]); + } +} diff --git a/tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.twig b/tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.twig similarity index 100% rename from tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.twig rename to tests/Rules/TrailingCommaSingleLine/TrailingCommaSingleLineTest.twig diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.empty.twig b/tests/Rules/TrailingSpace/TrailingSpaceTest.empty.twig similarity index 100% rename from tests/Sniff/TrailingSpace/TrailingSpaceTest.empty.twig rename to tests/Rules/TrailingSpace/TrailingSpaceTest.empty.twig diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.empty2.fixed.twig b/tests/Rules/TrailingSpace/TrailingSpaceTest.empty2.fixed.twig similarity index 100% rename from tests/Sniff/TrailingSpace/TrailingSpaceTest.empty2.fixed.twig rename to tests/Rules/TrailingSpace/TrailingSpaceTest.empty2.fixed.twig diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.empty2.twig b/tests/Rules/TrailingSpace/TrailingSpaceTest.empty2.twig similarity index 100% rename from tests/Sniff/TrailingSpace/TrailingSpaceTest.empty2.twig rename to tests/Rules/TrailingSpace/TrailingSpaceTest.empty2.twig diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.fixed.twig b/tests/Rules/TrailingSpace/TrailingSpaceTest.fixed.twig similarity index 100% rename from tests/Sniff/TrailingSpace/TrailingSpaceTest.fixed.twig rename to tests/Rules/TrailingSpace/TrailingSpaceTest.fixed.twig diff --git a/tests/Rules/TrailingSpace/TrailingSpaceTest.php b/tests/Rules/TrailingSpace/TrailingSpaceTest.php new file mode 100644 index 00000000..73fd7813 --- /dev/null +++ b/tests/Rules/TrailingSpace/TrailingSpaceTest.php @@ -0,0 +1,40 @@ +checkRule(new TrailingSpaceRule(), [ + [2 => 33], + [4 => 23], + ]); + } + + public function testRuleWithTab(): void + { + $this->checkRule(new TrailingSpaceRule(), [ + [2 => 32], + [4 => 21], + ], __DIR__.'/TrailingSpaceTest.tab.twig'); + } + + public function testRuleWithEmptyFile(): void + { + $this->checkRule( + new TrailingSpaceRule(), + [], + __DIR__.'/TrailingSpaceTest.empty.twig' + ); + + $this->checkRule(new TrailingSpaceRule(), [ + [1 => 2], + ], __DIR__.'/TrailingSpaceTest.empty2.twig'); + } +} diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.tab.fixed.twig b/tests/Rules/TrailingSpace/TrailingSpaceTest.tab.fixed.twig similarity index 100% rename from tests/Sniff/TrailingSpace/TrailingSpaceTest.tab.fixed.twig rename to tests/Rules/TrailingSpace/TrailingSpaceTest.tab.fixed.twig diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.tab.twig b/tests/Rules/TrailingSpace/TrailingSpaceTest.tab.twig similarity index 100% rename from tests/Sniff/TrailingSpace/TrailingSpaceTest.tab.twig rename to tests/Rules/TrailingSpace/TrailingSpaceTest.tab.twig diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.twig b/tests/Rules/TrailingSpace/TrailingSpaceTest.twig similarity index 100% rename from tests/Sniff/TrailingSpace/TrailingSpaceTest.twig rename to tests/Rules/TrailingSpace/TrailingSpaceTest.twig diff --git a/tests/Ruleset/RulesetTest.php b/tests/Ruleset/RulesetTest.php index 2b9fa6fe..5821d8c1 100644 --- a/tests/Ruleset/RulesetTest.php +++ b/tests/Ruleset/RulesetTest.php @@ -5,43 +5,43 @@ namespace TwigCsFixer\Tests\Ruleset; use PHPUnit\Framework\TestCase; +use TwigCsFixer\Rules\BlankEOFRule; +use TwigCsFixer\Rules\RuleInterface; +use TwigCsFixer\Rules\TrailingSpaceRule; use TwigCsFixer\Ruleset\Ruleset; -use TwigCsFixer\Sniff\BlankEOFSniff; -use TwigCsFixer\Sniff\SniffInterface; -use TwigCsFixer\Sniff\TrailingSpaceSniff; use TwigCsFixer\Standard\StandardInterface; final class RulesetTest extends TestCase { - public function testStartWithNoSniff(): void + public function testStartWithNoRule(): void { $ruleset = new Ruleset(); - static::assertSame([], $ruleset->getSniffs()); + static::assertSame([], $ruleset->getRules()); } - public function testAddAndRemoveSniff(): void + public function testAddAndRemoveRule(): void { $ruleset = new Ruleset(); - $sniff = self::createStub(SniffInterface::class); + $rule = self::createStub(RuleInterface::class); - $ruleset->addSniff($sniff); - static::assertCount(1, $ruleset->getSniffs()); + $ruleset->addRule($rule); + static::assertCount(1, $ruleset->getRules()); - $ruleset->removeSniff($sniff::class); - static::assertCount(0, $ruleset->getSniffs()); + $ruleset->removeRule($rule::class); + static::assertCount(0, $ruleset->getRules()); } public function testAddStandard(): void { $ruleset = new Ruleset(); - // Using real sniff to have different class name - $sniff1 = new BlankEOFSniff(); - $sniff2 = new TrailingSpaceSniff(); + // Using real rule to have different class name + $rule1 = new BlankEOFRule(); + $rule2 = new TrailingSpaceRule(); $standard = self::createStub(StandardInterface::class); - $standard->method('getSniffs')->willReturn([$sniff1, $sniff2]); + $standard->method('getRules')->willReturn([$rule1, $rule2]); $ruleset->addStandard($standard); - static::assertCount(2, $ruleset->getSniffs()); + static::assertCount(2, $ruleset->getRules()); } } diff --git a/tests/Runner/FixerTest.php b/tests/Runner/FixerTest.php index e413e67b..c44f053f 100644 --- a/tests/Runner/FixerTest.php +++ b/tests/Runner/FixerTest.php @@ -9,9 +9,9 @@ use TwigCsFixer\Environment\StubbedEnvironment; use TwigCsFixer\Exception\CannotFixFileException; use TwigCsFixer\Exception\CannotTokenizeException; +use TwigCsFixer\Rules\AbstractRule; use TwigCsFixer\Ruleset\Ruleset; use TwigCsFixer\Runner\Fixer; -use TwigCsFixer\Sniff\AbstractSniff; use TwigCsFixer\Token\Token; use TwigCsFixer\Token\Tokenizer; use TwigCsFixer\Token\TokenizerInterface; @@ -48,7 +48,7 @@ public function testReplaceToken(): void { $tokenizer = new Tokenizer(new StubbedEnvironment()); - $sniff = new class () extends AbstractSniff { + $rule = new class () extends AbstractRule { private bool $isAlreadyExecuted = false; protected function process(int $tokenPosition, array $tokens): void @@ -83,7 +83,7 @@ protected function process(int $tokenPosition, array $tokens): void }; $ruleset = new Ruleset(); - $ruleset->addSniff($sniff); + $ruleset->addRule($rule); $fixer = new Fixer($tokenizer); @@ -94,7 +94,7 @@ public function testReplaceTokenIsDesignedAgainstInfiniteLoop(): void { $tokenizer = new Tokenizer(new StubbedEnvironment()); - $sniff = new class () extends AbstractSniff { + $rule = new class () extends AbstractRule { protected function process(int $tokenPosition, array $tokens): void { $fixer = $this->addFixableError('Error', $tokens[$tokenPosition]); @@ -107,7 +107,7 @@ protected function process(int $tokenPosition, array $tokens): void }; $ruleset = new Ruleset(); - $ruleset->addSniff($sniff); + $ruleset->addRule($rule); $fixer = new Fixer($tokenizer); @@ -119,7 +119,7 @@ public function testReplaceTokenIsDesignedAgainstConflict(): void { $tokenizer = new Tokenizer(new StubbedEnvironment()); - $sniff1 = new class () extends AbstractSniff { + $rule1 = new class () extends AbstractRule { private bool $isAlreadyExecuted = false; protected function process(int $tokenPosition, array $tokens): void @@ -134,10 +134,10 @@ protected function process(int $tokenPosition, array $tokens): void return; } - $fixer->replaceToken($tokenPosition, 'sniff'); + $fixer->replaceToken($tokenPosition, 'rule'); } }; - $sniff2 = new class () extends AbstractSniff { + $rule2 = new class () extends AbstractRule { private int $error = 0; protected function process(int $tokenPosition, array $tokens): void @@ -169,12 +169,12 @@ protected function process(int $tokenPosition, array $tokens): void $fixer->endChangeSet(); } }; - $sniff3 = new class () extends AbstractSniff { + $rule3 = new class () extends AbstractRule { private bool $isAlreadyExecuted = false; protected function process(int $tokenPosition, array $tokens): void { - if ($this->isAlreadyExecuted || 'sniff' !== $tokens[$tokenPosition]->getValue()) { + if ($this->isAlreadyExecuted || 'rule' !== $tokens[$tokenPosition]->getValue()) { return; } $this->isAlreadyExecuted = true; @@ -184,7 +184,7 @@ protected function process(int $tokenPosition, array $tokens): void return; } - // On the first execution, a conflict is created by sniff 1 and 2 + // On the first execution, a conflict is created by rule 1 and 2 // So the fixer won't try to fix anything else TestCase::assertFalse($fixer->replaceToken($tokenPosition, 'b')); $fixer->beginChangeSet(); @@ -194,9 +194,9 @@ protected function process(int $tokenPosition, array $tokens): void }; $ruleset = new Ruleset(); - $ruleset->addSniff($sniff1); - $ruleset->addSniff($sniff2); - $ruleset->addSniff($sniff3); + $ruleset->addRule($rule1); + $ruleset->addRule($rule2); + $ruleset->addRule($rule3); $fixer = new Fixer($tokenizer); @@ -210,7 +210,7 @@ public function testAddContentMethods(string $content, string $expected): void { $tokenizer = new Tokenizer(new StubbedEnvironment()); - $sniff = new class () extends AbstractSniff { + $rule = new class () extends AbstractRule { private bool $isAlreadyExecuted = false; protected function process(int $tokenPosition, array $tokens): void @@ -235,7 +235,7 @@ protected function process(int $tokenPosition, array $tokens): void }; $ruleset = new Ruleset(); - $ruleset->addSniff($sniff); + $ruleset->addRule($rule); $fixer = new Fixer($tokenizer); diff --git a/tests/Runner/LinterTest.php b/tests/Runner/LinterTest.php index 2846b254..4766b8b6 100644 --- a/tests/Runner/LinterTest.php +++ b/tests/Runner/LinterTest.php @@ -11,7 +11,7 @@ use TwigCsFixer\Environment\StubbedEnvironment; use TwigCsFixer\Exception\CannotFixFileException; use TwigCsFixer\Exception\CannotTokenizeException; -use TwigCsFixer\Report\SniffViolation; +use TwigCsFixer\Report\Violation; use TwigCsFixer\Ruleset\Ruleset; use TwigCsFixer\Runner\FixerInterface; use TwigCsFixer\Runner\Linter; @@ -51,7 +51,7 @@ public function testUnreadableFilesAreReported(): void $message = $messages[0]; static::assertSame('Unable to read file.', $message->getMessage()); - static::assertSame(SniffViolation::LEVEL_FATAL, $message->getLevel()); + static::assertSame(Violation::LEVEL_FATAL, $message->getLevel()); static::assertSame($fileNotReadablePath, $message->getFilename()); static::assertCount(0, $report->getFileViolations($filePath)); @@ -75,7 +75,7 @@ public function testInvalidFilesAreReported(): void $message = $messages[0]; static::assertSame('File is invalid: Error.', $message->getMessage()); - static::assertSame(SniffViolation::LEVEL_FATAL, $message->getLevel()); + static::assertSame(Violation::LEVEL_FATAL, $message->getLevel()); static::assertSame($filePath, $message->getFilename()); // We still validate other files @@ -120,7 +120,7 @@ static function () use (&$call): array { $message = $messages[0]; static::assertSame('Unable to tokenize file: The template is invalid.', $message->getMessage()); - static::assertSame(SniffViolation::LEVEL_FATAL, $message->getLevel()); + static::assertSame(Violation::LEVEL_FATAL, $message->getLevel()); static::assertSame($filePath, $message->getFilename()); } @@ -159,7 +159,7 @@ public function testUserDeprecationAreReported(): void $message = $messages[0]; static::assertSame('User Deprecation', $message->getMessage()); - static::assertSame(SniffViolation::LEVEL_NOTICE, $message->getLevel()); + static::assertSame(Violation::LEVEL_NOTICE, $message->getLevel()); static::assertSame($filePath, $message->getFilename()); } @@ -224,7 +224,7 @@ static function () use (&$call, $exception): string { $message = $messages[0]; static::assertStringContainsString($expectedMessage, $message->getMessage()); - static::assertSame(SniffViolation::LEVEL_FATAL, $message->getLevel()); + static::assertSame(Violation::LEVEL_FATAL, $message->getLevel()); static::assertSame($filePath, $message->getFilename()); } diff --git a/tests/Sniff/BlankEOF/BlankEOFTest.php b/tests/Sniff/BlankEOF/BlankEOFTest.php deleted file mode 100644 index 1a1ff1fd..00000000 --- a/tests/Sniff/BlankEOF/BlankEOFTest.php +++ /dev/null @@ -1,31 +0,0 @@ -checkSniff(new BlankEOFSniff(), [ - [4 => 1], - ]); - - $this->checkSniff(new BlankEOFSniff(), [ - [2 => 7], - ], __DIR__.'/BlankEOFTest2.twig'); - } - - public function testSniffForEmptyFile(): void - { - $this->checkSniff(new BlankEOFSniff(), [], __DIR__.'/BlankEOFTest.empty.twig'); - - $this->checkSniff(new BlankEOFSniff(), [ - [3 => 1], - ], __DIR__.'/BlankEOFTest.empty2.twig'); - } -} diff --git a/tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.php b/tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.php deleted file mode 100644 index 689abf59..00000000 --- a/tests/Sniff/BlockNameSpacing/BlockNameSpacingTest.php +++ /dev/null @@ -1,21 +0,0 @@ -checkSniff(new BlockNameSpacingSniff(), [ - [1 => 5], - [1 => 5], - [3 => 3], - [3 => 3], - ]); - } -} diff --git a/tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.php b/tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.php deleted file mode 100644 index ad9d3db5..00000000 --- a/tests/Sniff/DelimiterSpacing/DelimiterSpacingTest.php +++ /dev/null @@ -1,21 +0,0 @@ -checkSniff(new DelimiterSpacingSniff(), [ - [15 => 1], - [15 => 12], - [15 => 15], - [15 => 25], - ]); - } -} diff --git a/tests/Sniff/EmptyLines/EmptyLinesTest.php b/tests/Sniff/EmptyLines/EmptyLinesTest.php deleted file mode 100644 index 7e3bfee5..00000000 --- a/tests/Sniff/EmptyLines/EmptyLinesTest.php +++ /dev/null @@ -1,20 +0,0 @@ -checkSniff(new EmptyLinesSniff(), [ - [2 => 1], - [5 => 1], - [10 => 1], - ]); - } -} diff --git a/tests/Sniff/Indent/IndentTest.php b/tests/Sniff/Indent/IndentTest.php deleted file mode 100644 index a5dfafea..00000000 --- a/tests/Sniff/Indent/IndentTest.php +++ /dev/null @@ -1,38 +0,0 @@ - 4], (new IndentSniff())->getConfiguration()); - static::assertSame(['space_ratio' => 2], (new IndentSniff(2))->getConfiguration()); - } - - public function testSniff(): void - { - $this->checkSniff(new IndentSniff(), [ - [2 => 1], - [4 => 1], - ]); - } - - public function testSniffWithSpaceRatio(): void - { - $this->checkSniff( - new IndentSniff(2), - [ - [2 => 1], - [4 => 1], - ], - __DIR__.'/IndentTest.twig', - __DIR__.'/IndentTest.fixed2.twig', - ); - } -} diff --git a/tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.php b/tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.php deleted file mode 100644 index c175d420..00000000 --- a/tests/Sniff/OperatorNameSpacing/OperatorNameSpacingTest.php +++ /dev/null @@ -1,20 +0,0 @@ -checkSniff(new OperatorNameSpacingSniff(), [ - [2 => 13], - [3 => 13], - [4 => 10], - ]); - } -} diff --git a/tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php b/tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php deleted file mode 100644 index cde2976b..00000000 --- a/tests/Sniff/TrailingCommaSingleLine/TrailingCommaSingleLineTest.php +++ /dev/null @@ -1,20 +0,0 @@ -checkSniff(new TrailingCommaSingleLineSniff(), [ - [2 => 9], - [4 => 13], - [6 => 12], - ]); - } -} diff --git a/tests/Sniff/TrailingSpace/TrailingSpaceTest.php b/tests/Sniff/TrailingSpace/TrailingSpaceTest.php deleted file mode 100644 index 199a60bf..00000000 --- a/tests/Sniff/TrailingSpace/TrailingSpaceTest.php +++ /dev/null @@ -1,40 +0,0 @@ -checkSniff(new TrailingSpaceSniff(), [ - [2 => 33], - [4 => 23], - ]); - } - - public function testSniffWithTab(): void - { - $this->checkSniff(new TrailingSpaceSniff(), [ - [2 => 32], - [4 => 21], - ], __DIR__.'/TrailingSpaceTest.tab.twig'); - } - - public function testSniffWithEmptyFile(): void - { - $this->checkSniff( - new TrailingSpaceSniff(), - [], - __DIR__.'/TrailingSpaceTest.empty.twig' - ); - - $this->checkSniff(new TrailingSpaceSniff(), [ - [1 => 2], - ], __DIR__.'/TrailingSpaceTest.empty2.twig'); - } -} diff --git a/tests/Standard/GenericTest.php b/tests/Standard/GenericTest.php index 339494f1..0dae447e 100644 --- a/tests/Standard/GenericTest.php +++ b/tests/Standard/GenericTest.php @@ -5,35 +5,35 @@ namespace TwigCsFixer\Tests\Standard; use PHPUnit\Framework\TestCase; -use TwigCsFixer\Sniff\BlankEOFSniff; -use TwigCsFixer\Sniff\BlockNameSpacingSniff; -use TwigCsFixer\Sniff\DelimiterSpacingSniff; -use TwigCsFixer\Sniff\EmptyLinesSniff; -use TwigCsFixer\Sniff\IndentSniff; -use TwigCsFixer\Sniff\OperatorNameSpacingSniff; -use TwigCsFixer\Sniff\OperatorSpacingSniff; -use TwigCsFixer\Sniff\PunctuationSpacingSniff; -use TwigCsFixer\Sniff\TrailingCommaSingleLineSniff; -use TwigCsFixer\Sniff\TrailingSpaceSniff; +use TwigCsFixer\Rules\BlankEOFRule; +use TwigCsFixer\Rules\BlockNameSpacingRule; +use TwigCsFixer\Rules\DelimiterSpacingRule; +use TwigCsFixer\Rules\EmptyLinesRule; +use TwigCsFixer\Rules\IndentRule; +use TwigCsFixer\Rules\OperatorNameSpacingRule; +use TwigCsFixer\Rules\OperatorSpacingRule; +use TwigCsFixer\Rules\PunctuationSpacingRule; +use TwigCsFixer\Rules\TrailingCommaSingleLineRule; +use TwigCsFixer\Rules\TrailingSpaceRule; use TwigCsFixer\Standard\Generic; final class GenericTest extends TestCase { - public function testGetSniffs(): void + public function testGetRules(): void { $standard = new Generic(); static::assertEquals([ - new DelimiterSpacingSniff(), - new OperatorNameSpacingSniff(), - new OperatorSpacingSniff(), - new PunctuationSpacingSniff(), - new BlankEOFSniff(), - new BlockNameSpacingSniff(), - new EmptyLinesSniff(), - new IndentSniff(), - new TrailingCommaSingleLineSniff(), - new TrailingSpaceSniff(), - ], $standard->getSniffs()); + new DelimiterSpacingRule(), + new OperatorNameSpacingRule(), + new OperatorSpacingRule(), + new PunctuationSpacingRule(), + new BlankEOFRule(), + new BlockNameSpacingRule(), + new EmptyLinesRule(), + new IndentRule(), + new TrailingCommaSingleLineRule(), + new TrailingSpaceRule(), + ], $standard->getRules()); } } diff --git a/tests/Standard/TwigTest.php b/tests/Standard/TwigTest.php index 567c6c64..d3d831db 100644 --- a/tests/Standard/TwigTest.php +++ b/tests/Standard/TwigTest.php @@ -5,23 +5,23 @@ namespace TwigCsFixer\Tests\Standard; use PHPUnit\Framework\TestCase; -use TwigCsFixer\Sniff\DelimiterSpacingSniff; -use TwigCsFixer\Sniff\OperatorNameSpacingSniff; -use TwigCsFixer\Sniff\OperatorSpacingSniff; -use TwigCsFixer\Sniff\PunctuationSpacingSniff; +use TwigCsFixer\Rules\DelimiterSpacingRule; +use TwigCsFixer\Rules\OperatorNameSpacingRule; +use TwigCsFixer\Rules\OperatorSpacingRule; +use TwigCsFixer\Rules\PunctuationSpacingRule; use TwigCsFixer\Standard\Twig; final class TwigTest extends TestCase { - public function testGetSniffs(): void + public function testGetRules(): void { $standard = new Twig(); static::assertEquals([ - new DelimiterSpacingSniff(), - new OperatorNameSpacingSniff(), - new OperatorSpacingSniff(), - new PunctuationSpacingSniff(), - ], $standard->getSniffs()); + new DelimiterSpacingRule(), + new OperatorNameSpacingRule(), + new OperatorSpacingRule(), + new PunctuationSpacingRule(), + ], $standard->getRules()); } }