Skip to content

Commit 459dd28

Browse files
authored
[BUGFIX] Remove trailing semicolon with compact format (#1345)
Fixes #1342.
1 parent aed922c commit 459dd28

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Please also have a look at our
7474

7575
### Fixed
7676

77+
- Remove trailing semicolon from declaration blocks with 'compact'
78+
`OutputFormat` (#1345)
7779
- Parse selector functions (like `:not`) with comma-separated arguments (#1292)
7880
- Parse quoted attribute selector value containing comma (#1323)
7981
- Allow comma in selectors (e.g. `:not(html, body)`) (#1293)

src/OutputFormat.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ public static function createCompact(): self
726726
->setSpaceAfterRuleName('')
727727
->setSpaceBeforeOpeningBrace('')
728728
->setSpaceAfterSelectorSeparator('')
729+
->setSemicolonAfterLastRule(false)
729730
->setRenderComments(false);
730731

731732
return $format;

tests/Comment/CommentTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public function keepCommentsInOutput(): void
4949
. ' * Comments' . "\n"
5050
. ' *//* Hell */@import url("some/url.css") screen;'
5151
. '/* Number 4 *//* Number 5 */.foo,#bar{'
52-
. '/* Number 6 */background-color:#000;}@media screen{'
53-
. '/** Number 10 **/#foo.bar{/** Number 10b **/position:absolute;}}',
52+
. '/* Number 6 */background-color:#000}@media screen{'
53+
. '/** Number 10 **/#foo.bar{/** Number 10b **/position:absolute}}',
5454
$cssDocument->render(OutputFormat::createCompact()->setRenderComments(true))
5555
);
5656
}
@@ -76,8 +76,8 @@ public function stripCommentsFromOutput(): void
7676
', $css->render(OutputFormat::createPretty()->setRenderComments(false)));
7777
self::assertSame(
7878
'@import url("some/url.css") screen;'
79-
. '.foo,#bar{background-color:#000;}'
80-
. '@media screen{#foo.bar{position:absolute;}}',
79+
. '.foo,#bar{background-color:#000}'
80+
. '@media screen{#foo.bar{position:absolute}}',
8181
$css->render(OutputFormat::createCompact())
8282
);
8383
}

tests/Functional/RuleSet/RuleSetTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function renderReturnsCssForRulesSet(array $propertyNamesAndValuesToSet,
7171
/**
7272
* @test
7373
*/
74-
public function renderWithCompactOutputFormatReturnsCssWithoutWhitespace(): void
74+
public function renderWithCompactOutputFormatReturnsCssWithoutWhitespaceOrTrailingSemicolon(): void
7575
{
7676
$this->setRulesFromPropertyNamesAndValues([
7777
['name' => 'color', 'value' => 'green'],
@@ -80,7 +80,7 @@ public function renderWithCompactOutputFormatReturnsCssWithoutWhitespace(): void
8080

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

83-
self::assertSame('color:green;display:block;', $result);
83+
self::assertSame('color:green;display:block', $result);
8484
}
8585

8686
/**

tests/OutputFormatTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function plain(): void
6969
public function compact(): void
7070
{
7171
self::assertSame(
72-
'.main,.test{font:italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background:white;}'
73-
. '@media screen{.main{background-size:100% 100%;font-size:1.3em;background-color:#fff;}}',
72+
'.main,.test{font:italic normal bold 16px/1.2 "Helvetica",Verdana,sans-serif;background:white}'
73+
. '@media screen{.main{background-size:100% 100%;font-size:1.3em;background-color:#fff}}',
7474
$this->document->render(OutputFormat::createCompact())
7575
);
7676
}

tests/Unit/OutputFormatTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,16 @@ public function createCompactReturnsInstanceWithSpaceAfterListArgumentSeparators
10341034
self::assertSame([], $newInstance->getSpaceAfterListArgumentSeparators());
10351035
}
10361036

1037+
/**
1038+
* @test
1039+
*/
1040+
public function createCompactReturnsInstanceWithRenderSemicolonAfterLastRuleDisabled(): void
1041+
{
1042+
$newInstance = OutputFormat::createCompact();
1043+
1044+
self::assertFalse($newInstance->shouldRenderSemicolonAfterLastRule());
1045+
}
1046+
10371047
/**
10381048
* @test
10391049
*/

0 commit comments

Comments
 (0)