Skip to content

Commit

Permalink
fix: Support numeric values without leading zero in `numeric_literal_…
Browse files Browse the repository at this point in the history
…separator` (#7735)
  • Loading branch information
muuvmuuv committed Jan 15, 2024
1 parent 04e3513 commit b03d0c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/Basic/NumericLiteralSeparatorFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function formatValue(string $value): string
/** If its a negative value we need an offset */
$negativeOffset = static fn ($v) => str_contains($v, '-') ? 1 : 0;

Preg::matchAll('/([0-9-_]+)((\.)([0-9_]+))?((e)([0-9-_]+))?/i', $value, $result);
Preg::matchAll('/([0-9-_]+)?((\.)([0-9_]+))?((e)([0-9-_]+))?/i', $value, $result);

$integer = $result[1][0];
$joinedValue = $this->insertEveryRight($integer, 3, $negativeOffset($integer));
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixer/Basic/NumericLiteralSeparatorFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ public static function provideFixCases(): iterable
'0b110001000' => '0b1_10001000',
],
'float' => [
'.1001' => '.100_1',
'1234.5' => '1_234.5',
'1.2345' => '1.234_5',
'1234e5' => '1_234e5',
'1234E5' => '1_234E5',
'1e2345' => '1e2_345',
'1234.5678e1234' => '1_234.567_8e1_234',
'.5678e1234' => '.567_8e1_234',
'1.1e-1234' => '1.1e-1_234',
'1.1e-12345' => '1.1e-12_345',
'1.1e-123456' => '1.1e-123_456',
'.1e-12345' => '.1e-12_345',
],
'hexadecimal' => [
'0x42726F776E' => '0x42_72_6F_77_6E',
Expand Down

0 comments on commit b03d0c4

Please sign in to comment.