-
Notifications
You must be signed in to change notification settings - Fork 7
[FEATURE] Add a virtual CodeFormatRule to stop silently swallowing formatting-only changes #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
030c792
97cd071
919f2eb
e3dca0a
b177c5f
f01474e
86071bd
2a1a4c4
ea69980
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,8 @@ | |
| - | ||
| options: | ||
| recipients: | ||
| - bar@domain.com: 'Bar' | ||
| + foo@domain.com: Bar | ||
| + bar@domain.com: Bar | ||
| bar@domain.com: Bar | ||
| subject: 'Kontaktanfrage von Website' | ||
| - recipientAddress: foo@domain.com | ||
| - recipientName: Bar | ||
|
|
@@ -32,9 +31,8 @@ | |
| - | ||
| options: | ||
| recipients: | ||
| - bar@domain.com: 'Bar' | ||
| + foo@domain.com: Bar | ||
| + bar@domain.com: Bar | ||
| bar@domain.com: Bar | ||
| subject: 'Kontaktanfrage von Website' | ||
| - recipientAddress: foo@domain.com | ||
| - recipientName: Bar | ||
|
|
@@ -70,8 +68,9 @@ | |
| ----------- end diff ----------- | ||
|
|
||
| Applied rules: | ||
| * CodeFormatRule | ||
| * EmailFinisherYamlFractor | ||
|
|
||
|
|
||
| [OK] 1 file has been changed by Fractor | ||
| [OK] 1 file has been changed by Fractor | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering about the extra whitespace at the end here where it comes from and why it is not trimmed as before
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are coming from the symfony output and are technically always present in the console. I can only assume that the whitespaces had been trimmed by ones IDE in the past and therefore were formerly missing. They don't really matter and are only of cosmetic nature. We can savely remove them if you like to. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace a9f\FractorComposerJson\Tests\ComposerJsonProcessResult; | ||
|
|
||
| use a9f\Fractor\Application\ValueObject\AppliedRule; | ||
| use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; | ||
| use a9f\FractorComposerJson\RemovePackageComposerJsonFractor; | ||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
|
|
||
| /** | ||
| * The composer.json processor re-prints files it touches, so a formatting-only | ||
| * change (indentation) must be attributed to the virtual CodeFormatRule — so a | ||
| * re-indentation is reported rather than applied silently — while a real | ||
| * transformation stays attributed to its own rule. | ||
| */ | ||
| final class ComposerJsonProcessResultTest extends AbstractFractorTestCase | ||
| { | ||
| /** | ||
| * @param list<string> $expectedAppliedRules | ||
| */ | ||
| #[DataProvider('provideData')] | ||
| public function test(string $fixture, array $expectedAppliedRules): void | ||
| { | ||
| $fractorTestResult = $this->doTestFile(__DIR__ . '/Fixtures/' . $fixture); | ||
|
|
||
| self::assertSame($expectedAppliedRules, $fractorTestResult->getAppliedFractorRules()); | ||
| } | ||
|
|
||
| /** | ||
| * @return \Iterator<string, array{string, list<string>}> | ||
| */ | ||
| public static function provideData(): \Iterator | ||
| { | ||
| yield 'rule change is attributed to the real rule' => [ | ||
| 'rule-change/composer.json.fixture', | ||
| [RemovePackageComposerJsonFractor::class], | ||
| ]; | ||
| yield 'pure reformat is attributed to the virtual code-format rule' => [ | ||
| 'reformatting/composer.json.fixture', | ||
| [AppliedRule::CODE_FORMAT_RULE], | ||
| ]; | ||
| yield 'already formatted file reports no change' => ['already-formatted/composer.json.fixture', []]; | ||
| } | ||
|
|
||
| public function provideConfigFilePath(): string | ||
| { | ||
| return __DIR__ . '/config/fractor.php'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "acme/demo", | ||
| "require": { | ||
| "vendor1/keep": "^2.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "name": "acme/demo", | ||
| "require": { | ||
| "vendor1/keep": "^2.0" | ||
| } | ||
| } | ||
| ----- | ||
| { | ||
| "name": "acme/demo", | ||
| "require": { | ||
| "vendor1/keep": "^2.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "require": { | ||
| "vendor1/legacy": "^1.0", | ||
| "vendor1/keep": "^2.0" | ||
| } | ||
| } | ||
| ----- | ||
| { | ||
| "require": { | ||
| "vendor1/keep": "^2.0" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use a9f\Fractor\Configuration\FractorConfiguration; | ||
| use a9f\FractorComposerJson\RemovePackageComposerJsonFractor; | ||
|
|
||
| return FractorConfiguration::configure() | ||
| ->import(__DIR__ . '/../../../config/application.php') | ||
| ->withConfiguredRule(RemovePackageComposerJsonFractor::class, ['vendor1/legacy']); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| page = PAGE | ||
| page.10 = TEXT | ||
| page.10.value = Hello |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| page = PAGE | ||
| page.10 = TEXT | ||
| page.10.value = Hello | ||
| ----- | ||
| page = PAGE | ||
| page.10 = TEXT | ||
| page.10.value = Hello |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| page = PAGE | ||
| config.spamProtectEmailAddresses = ascii | ||
| ----- | ||
| page = PAGE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace a9f\FractorTypoScript\Tests\TypoScriptProcessResult; | ||
|
|
||
| use a9f\Fractor\Application\ValueObject\AppliedRule; | ||
| use a9f\Fractor\Testing\PHPUnit\AbstractFractorTestCase; | ||
| use a9f\FractorTypoScript\Tests\Fixtures\DummyTypoScriptFractorRule; | ||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
|
|
||
| /** | ||
| * The TypoScript pretty-printer re-formats files it touches, so a formatting-only | ||
| * reformat must be attributed to the virtual CodeFormatRule (and count toward the | ||
| * exit code), while a real transformation stays attributed to its own rule. | ||
| */ | ||
| final class TypoScriptProcessResultTest extends AbstractFractorTestCase | ||
| { | ||
| /** | ||
| * @param list<string> $expectedAppliedRules | ||
| */ | ||
| #[DataProvider('provideData')] | ||
| public function test(string $fixture, array $expectedAppliedRules): void | ||
| { | ||
| $fractorTestResult = $this->doTestFile(__DIR__ . '/Fixtures/' . $fixture); | ||
|
|
||
| self::assertSame($expectedAppliedRules, $fractorTestResult->getAppliedFractorRules()); | ||
| } | ||
|
|
||
| /** | ||
| * @return \Iterator<string, array{string, list<string>}> | ||
| */ | ||
| public static function provideData(): \Iterator | ||
| { | ||
| yield 'rule change is attributed to the real rule' => [ | ||
| 'rule-change.typoscript.fixture', | ||
| [DummyTypoScriptFractorRule::class], | ||
| ]; | ||
| yield 'pure reformat is attributed to the virtual code-format rule' => [ | ||
| 'reformatting.typoscript.fixture', | ||
| [AppliedRule::CODE_FORMAT_RULE], | ||
| ]; | ||
| yield 'already formatted file reports no change' => ['already-formatted.typoscript.fixture', []]; | ||
| } | ||
|
|
||
| public function provideConfigFilePath(): string | ||
| { | ||
| return __DIR__ . '/config/fractor.php'; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use a9f\Fractor\Configuration\FractorConfiguration; | ||
| use a9f\FractorTypoScript\Configuration\TypoScriptProcessorOption; | ||
| use a9f\FractorTypoScript\Tests\Fixtures\DummyTypoScriptFractorRule; | ||
| use Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConditionTermination; | ||
| use Helmich\TypoScriptParser\Parser\Printer\PrettyPrinterConfiguration; | ||
|
|
||
| return FractorConfiguration::configure() | ||
| ->withOptions([ | ||
| TypoScriptProcessorOption::INDENT_SIZE => 4, | ||
| TypoScriptProcessorOption::INDENT_CHARACTER => PrettyPrinterConfiguration::INDENTATION_STYLE_SPACES, | ||
| TypoScriptProcessorOption::ADD_CLOSING_GLOBAL => false, | ||
| TypoScriptProcessorOption::INCLUDE_EMPTY_LINE_BREAKS => true, | ||
| TypoScriptProcessorOption::INDENT_CONDITIONS => true, | ||
| TypoScriptProcessorOption::CONDITION_TERMINATION => PrettyPrinterConditionTermination::Keep, | ||
| ]) | ||
| ->withRules([DummyTypoScriptFractorRule::class]); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff | ||
| xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
| <file source-language="en" datatype="plaintext" original="messages"> | ||
| <body> | ||
| <trans-unit id="key1" xml:space="preserve"> | ||
| <source>Goodbye</source> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
| <file source-language="en" datatype="plaintext" original="messages"> | ||
| <body> | ||
| <trans-unit id="key1" xml:space="preserve"> | ||
| <source>Goodbye</source> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> | ||
| ----- | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff | ||
| xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
| <file source-language="en" datatype="plaintext" original="messages"> | ||
| <body> | ||
| <trans-unit id="key1" xml:space="preserve"> | ||
| <source>Goodbye</source> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
| <file source-language="en" datatype="plaintext" original="messages"> | ||
| <body> | ||
| <trans-unit id="key1" xml:space="preserve"> | ||
| <source>Hello</source> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> | ||
| ----- | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff | ||
| xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
| <file source-language="en" datatype="plaintext" original="messages"> | ||
| <body> | ||
| <trans-unit id="key1" xml:space="preserve"> | ||
| <source>Hello World</source> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff | ||
| xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
| <file source-language="en" datatype="plaintext" original="messages"> | ||
| <body> | ||
| <trans-unit id="key1" xml:space="preserve"> | ||
| <source>Hello</source> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> | ||
| ----- | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <xliff | ||
| xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> | ||
| <file source-language="en" datatype="plaintext" original="messages"> | ||
| <body> | ||
| <trans-unit id="key1" xml:space="preserve"> | ||
| <source>Hello World</source> | ||
| </trans-unit> | ||
| </body> | ||
| </file> | ||
| </xliff> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is there a diff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The YAML processor now diffs against a normalized baseline (the re-dumped original) instead of the raw source. Previously the diff was raw:
'Bar'against'Bar'. After our change we diff againstBarwithout quotes. That's why theexpected-output.txthad to change.