Skip to content
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

feat: allow arbitrary space indentation #7818

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/WhitespacesFixerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ final class WhitespacesFixerConfig

public function __construct(string $indent = ' ', string $lineEnding = "\n")
{
if (!\in_array($indent, [' ', ' ', "\t"], true)) {
throw new \InvalidArgumentException('Invalid "indent" param, expected tab or two or four spaces.');
if (!Preg::match('/^(?: +|\t)$/', $indent)) {
Copy link
Member

@keradus keradus Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF we would go forward direction to approve the PR, we need a new tests to prove it works:

  • each fixer that uses WhitespacesFixerConfig should receive a new test with new whitespace variant(s)
  • dedicated integration tests for new whitespace variant(s) (at least mimic tests/Fixtures/Integration/set/@PSR12_whitespaces.test*.php)

(i suggest to not invest into it till aligned into direction)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll convert this to a draft while I familiarize myself more with the codebase.

throw new \InvalidArgumentException('Invalid "indent" param, expected tab or spaces.');
}

if (!\in_array($lineEnding, ["\n", "\r\n"], true)) {
Expand Down
4 changes: 3 additions & 1 deletion tests/WhitespacesFixerConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ public static function provideFixCases(): iterable

yield ["\t", "\n"];

yield [str_repeat(' ', 12), "\n"];

yield [' ', "\r\n"];

yield ["\t", "\r\n"];

yield [' ', 'asd', 'Invalid "lineEnding" param, expected "\n" or "\r\n".'];

yield ['std', "\n", 'Invalid "indent" param, expected tab or two or four spaces.'];
yield ['std', "\n", 'Invalid "indent" param, expected tab or spaces.'];
}
}