Skip to content

[BUGFIX] Remove trailing semicolon with compact format #1345

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

Merged
merged 3 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Please also have a look at our

### Fixed

- Remove trailing semicolon from declaration blocks with 'compact'
`OutputFormat` (#1345)
- Parse selector functions (like `:not`) with comma-separated arguments (#1292)
- Parse quoted attribute selector value containing comma (#1323)
- Allow comma in selectors (e.g. `:not(html, body)`) (#1293)
Expand Down
1 change: 1 addition & 0 deletions src/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ public static function createCompact(): self
->setSpaceAfterRuleName('')
->setSpaceBeforeOpeningBrace('')
->setSpaceAfterSelectorSeparator('')
->setSemicolonAfterLastRule(false)
->setRenderComments(false);

return $format;
Expand Down
8 changes: 4 additions & 4 deletions tests/Comment/CommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function keepCommentsInOutput(): void
. ' * Comments' . "\n"
. ' *//* Hell */@import url("some/url.css") screen;'
. '/* Number 4 *//* Number 5 */.foo,#bar{'
. '/* Number 6 */background-color:#000;}@media screen{'
. '/** Number 10 **/#foo.bar{/** Number 10b **/position:absolute;}}',
. '/* Number 6 */background-color:#000}@media screen{'
. '/** Number 10 **/#foo.bar{/** Number 10b **/position:absolute}}',
$cssDocument->render(OutputFormat::createCompact()->setRenderComments(true))
);
}
Expand All @@ -76,8 +76,8 @@ public function stripCommentsFromOutput(): void
', $css->render(OutputFormat::createPretty()->setRenderComments(false)));
self::assertSame(
'@import url("some/url.css") screen;'
. '.foo,#bar{background-color:#000;}'
. '@media screen{#foo.bar{position:absolute;}}',
. '.foo,#bar{background-color:#000}'
. '@media screen{#foo.bar{position:absolute}}',
$css->render(OutputFormat::createCompact())
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/RuleSet/RuleSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function renderReturnsCssForRulesSet(array $propertyNamesAndValuesToSet,
/**
* @test
*/
public function renderWithCompactOutputFormatReturnsCssWithoutWhitespace(): void
public function renderWithCompactOutputFormatReturnsCssWithoutWhitespaceOrTrailingSemicolon(): void
{
$this->setRulesFromPropertyNamesAndValues([
['name' => 'color', 'value' => 'green'],
Expand All @@ -80,7 +80,7 @@ public function renderWithCompactOutputFormatReturnsCssWithoutWhitespace(): void

$result = $this->subject->render(OutputFormat::createCompact());

self::assertSame('color:green;display:block;', $result);
self::assertSame('color:green;display:block', $result);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/OutputFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function plain(): void
public function compact(): void
{
self::assertSame(
'.main,.test{font:italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background:white;}'
. '@media screen{.main{background-size:100% 100%;font-size:1.3em;background-color:#fff;}}',
'.main,.test{font:italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background:white}'
. '@media screen{.main{background-size:100% 100%;font-size:1.3em;background-color:#fff}}',
$this->document->render(OutputFormat::createCompact())
);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/OutputFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,16 @@ public function createCompactReturnsInstanceWithSpaceAfterListArgumentSeparators
self::assertSame([], $newInstance->getSpaceAfterListArgumentSeparators());
}

/**
* @test
*/
public function createCompactReturnsInstanceWithRenderSemicolonAfterLastRuleDisabled(): void
{
$newInstance = OutputFormat::createCompact();

self::assertFalse($newInstance->shouldRenderSemicolonAfterLastRule());
}

/**
* @test
*/
Expand Down