Skip to content

Commit 18a6467

Browse files
authored
[CLEANUP] Standardize escaped linefeeds and tabs in literals (#1432)
Trailing linefeeds should always be part of the previous line, and leading tabs should be part of the following line.
1 parent e58b67c commit 18a6467

File tree

2 files changed

+44
-85
lines changed

2 files changed

+44
-85
lines changed

tests/OutputFormatTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ final class OutputFormatTest extends TestCase
1919
. ".main, .test {\n"
2020
. "\tfont: italic normal bold 16px/1.2 \"Helvetica\", Verdana, sans-serif;\n"
2121
. "\tbackground: white;\n"
22-
. "}\n"
23-
. "\n"
22+
. "}\n\n"
2423
. "@media screen {\n"
2524
. "\t.main {\n"
2625
. "\t\tbackground-size: 100% 100%;\n"
@@ -84,8 +83,8 @@ public function spaceAfterListArgumentSeparator(): void
8483
{
8584
self::assertSame(
8685
'.main, .test {font: italic normal bold 16px/ 1.2 '
87-
. '"Helvetica", Verdana, sans-serif;background: white;}'
88-
. "\n@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}",
86+
. "\"Helvetica\", Verdana, sans-serif;background: white;}\n"
87+
. '@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}',
8988
$this->document->render(OutputFormat::create()->setSpaceAfterListArgumentSeparator(' '))
9089
);
9190
}

tests/ParserTest.php

Lines changed: 41 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,11 @@ public function colorParsing(): void
156156
}
157157
self::assertSame(
158158
'#mine {color: red;border-color: #0a64e6;border-color: rgba(10,100,231,.3);outline-color: #222;'
159-
. 'background-color: #232323;}'
160-
. "\n"
161-
. '#yours {background-color: hsl(220,10%,220%);background-color: hsla(220,10%,220%,.3);}'
162-
. "\n"
159+
. "background-color: #232323;}\n"
160+
. "#yours {background-color: hsl(220,10%,220%);background-color: hsla(220,10%,220%,.3);}\n"
163161
. '#variables {background-color: rgb(var(--some-rgb));background-color: rgb(var(--r),var(--g),var(--b));'
164162
. 'background-color: rgb(255,var(--g),var(--b));background-color: rgb(255,255,var(--b));'
165-
. 'background-color: rgb(255,var(--rg));background-color: hsl(var(--some-hsl));}'
166-
. "\n"
163+
. "background-color: rgb(255,var(--rg));background-color: hsl(var(--some-hsl));}\n"
167164
. '#variables-alpha {background-color: rgba(var(--some-rgb),.1);'
168165
. 'background-color: rgba(var(--some-rg),255,.1);background-color: hsla(var(--some-hsl),.1);}',
169166
$document->render()
@@ -265,35 +262,21 @@ public function manipulation(): void
265262
{
266263
$document = self::parsedStructureForFile('atrules');
267264
self::assertSame(
268-
'@charset "utf-8";'
269-
. "\n"
270-
. '@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}'
271-
. "\n"
272-
. 'html, body {font-size: -.6em;}'
273-
. "\n"
274-
. '@keyframes mymove {from {top: 0px;}'
275-
. "\n\t"
276-
. 'to {top: 200px;}}'
277-
. "\n"
278-
. '@-moz-keyframes some-move {from {top: 0px;}'
279-
. "\n\t"
280-
. 'to {top: 200px;}}'
281-
. "\n"
265+
"@charset \"utf-8\";\n"
266+
. "@font-face {font-family: \"CrassRoots\";src: url(\"../media/cr.ttf\");}\n"
267+
. "html, body {font-size: -.6em;}\n"
268+
. "@keyframes mymove {from {top: 0px;}\n"
269+
. "\tto {top: 200px;}}\n"
270+
. "@-moz-keyframes some-move {from {top: 0px;}\n"
271+
. "\tto {top: 200px;}}\n"
282272
. '@supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) or '
283-
. '(-ms-perspective: 10px) or (-o-perspective: 10px) ) {body {font-family: "Helvetica";}}'
284-
. "\n"
285-
. '@page :pseudo-class {margin: 2in;}'
286-
. "\n"
287-
. '@-moz-document url(https://www.w3.org/),'
288-
. "\n"
289-
. ' url-prefix(https://www.w3.org/Style/),'
290-
. "\n"
291-
. ' domain(mozilla.org),'
292-
. "\n"
293-
. ' regexp("https:.*") {body {color: purple;background: yellow;}}'
294-
. "\n"
295-
. '@media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}'
296-
. "\n"
273+
. "(-ms-perspective: 10px) or (-o-perspective: 10px) ) {body {font-family: \"Helvetica\";}}\n"
274+
. "@page :pseudo-class {margin: 2in;}\n"
275+
. "@-moz-document url(https://www.w3.org/),\n"
276+
. " url-prefix(https://www.w3.org/Style/),\n"
277+
. " domain(mozilla.org),\n"
278+
. " regexp(\"https:.*\") {body {color: purple;background: yellow;}}\n"
279+
. "@media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}\n"
297280
. '@region-style #intro {p {color: blue;}}',
298281
$document->render()
299282
);
@@ -304,35 +287,21 @@ public function manipulation(): void
304287
}
305288
}
306289
self::assertSame(
307-
'@charset "utf-8";'
308-
. "\n"
309-
. '@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}'
310-
. "\n"
311-
. '#my_id html, #my_id body {font-size: -.6em;}'
312-
. "\n"
313-
. '@keyframes mymove {from {top: 0px;}'
314-
. "\n\t"
315-
. 'to {top: 200px;}}'
316-
. "\n"
317-
. '@-moz-keyframes some-move {from {top: 0px;}'
318-
. "\n\t"
319-
. 'to {top: 200px;}}'
320-
. "\n"
290+
"@charset \"utf-8\";\n"
291+
. "@font-face {font-family: \"CrassRoots\";src: url(\"../media/cr.ttf\");}\n"
292+
. "#my_id html, #my_id body {font-size: -.6em;}\n"
293+
. "@keyframes mymove {from {top: 0px;}\n"
294+
. "\tto {top: 200px;}}\n"
295+
. "@-moz-keyframes some-move {from {top: 0px;}\n"
296+
. "\tto {top: 200px;}}\n"
321297
. '@supports ( (perspective: 10px) or (-moz-perspective: 10px) or (-webkit-perspective: 10px) '
322-
. 'or (-ms-perspective: 10px) or (-o-perspective: 10px) ) {#my_id body {font-family: "Helvetica";}}'
323-
. "\n"
324-
. '@page :pseudo-class {margin: 2in;}'
325-
. "\n"
326-
. '@-moz-document url(https://www.w3.org/),'
327-
. "\n"
328-
. ' url-prefix(https://www.w3.org/Style/),'
329-
. "\n"
330-
. ' domain(mozilla.org),'
331-
. "\n"
332-
. ' regexp("https:.*") {#my_id body {color: purple;background: yellow;}}'
333-
. "\n"
334-
. '@media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}'
335-
. "\n"
298+
. "or (-ms-perspective: 10px) or (-o-perspective: 10px) ) {#my_id body {font-family: \"Helvetica\";}}\n"
299+
. "@page :pseudo-class {margin: 2in;}\n"
300+
. "@-moz-document url(https://www.w3.org/),\n"
301+
. " url-prefix(https://www.w3.org/Style/),\n"
302+
. " domain(mozilla.org),\n"
303+
. " regexp(\"https:.*\") {#my_id body {color: purple;background: yellow;}}\n"
304+
. "@media screen and (orientation: landscape) {@-ms-viewport {width: 1024px;height: 768px;}}\n"
336305
. '@region-style #intro {#my_id p {color: blue;}}',
337306
$document->render(OutputFormat::create()->setRenderComments(false))
338307
);
@@ -438,18 +407,14 @@ public function slashedValues(): void
438407
public function functionSyntax(): void
439408
{
440409
$document = self::parsedStructureForFile('functions');
441-
$expected = 'div.main {background-image: linear-gradient(#000,#fff);}'
442-
. "\n"
410+
$expected = "div.main {background-image: linear-gradient(#000,#fff);}\n"
443411
. '.collapser::before, .collapser::-moz-before, .collapser::-webkit-before {content: "»";font-size: 1.2em;'
444412
. 'margin-right: .2em;-moz-transition-property: -moz-transform;-moz-transition-duration: .2s;'
445-
. '-moz-transform-origin: center 60%;}'
446-
. "\n"
413+
. "-moz-transform-origin: center 60%;}\n"
447414
. '.collapser.expanded::before, .collapser.expanded::-moz-before,'
448-
. ' .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}'
449-
. "\n"
415+
. " .collapser.expanded::-webkit-before {-moz-transform: rotate(90deg);}\n"
450416
. '.collapser + * {height: 0;overflow: hidden;-moz-transition-property: height;'
451-
. '-moz-transition-duration: .3s;}'
452-
. "\n"
417+
. "-moz-transition-duration: .3s;}\n"
453418
. '.collapser.expanded + * {height: auto;}';
454419
self::assertSame($expected, $document->render());
455420

@@ -761,10 +726,8 @@ public function identifierEscapesInFile(): void
761726
public function selectorIgnoresInFile(): void
762727
{
763728
$document = self::parsedStructureForFile('selector-ignores', Settings::create()->withMultibyteSupport(true));
764-
$expected = '.some[selectors-may=\'contain-a-{\'] {}'
765-
. "\n"
766-
. '.this-selector .valid {width: 100px;}'
767-
. "\n"
729+
$expected = ".some[selectors-may='contain-a-{'] {}\n"
730+
. ".this-selector .valid {width: 100px;}\n"
768731
. '@media only screen and (min-width: 200px) {.test {prop: val;}}';
769732
self::assertSame($expected, $document->render());
770733
}
@@ -778,11 +741,9 @@ public function keyframeSelectors(): void
778741
'keyframe-selector-validation',
779742
Settings::create()->withMultibyteSupport(true)
780743
);
781-
$expected = '@-webkit-keyframes zoom {0% {-webkit-transform: scale(1,1);}'
782-
. "\n\t"
783-
. '50% {-webkit-transform: scale(1.2,1.2);}'
784-
. "\n\t"
785-
. '100% {-webkit-transform: scale(1,1);}}';
744+
$expected = "@-webkit-keyframes zoom {0% {-webkit-transform: scale(1,1);}\n"
745+
. "\t50% {-webkit-transform: scale(1.2,1.2);}\n"
746+
. "\t100% {-webkit-transform: scale(1,1);}}";
786747
self::assertSame($expected, $document->render());
787748
}
788749

@@ -812,8 +773,7 @@ public function calcFailure(): void
812773
public function urlInFileMbOff(): void
813774
{
814775
$document = self::parsedStructureForFile('url', Settings::create()->withMultibyteSupport(false));
815-
$expected = 'body {background: #fff url("https://somesite.com/images/someimage.gif") repeat top center;}'
816-
. "\n"
776+
$expected = "body {background: #fff url(\"https://somesite.com/images/someimage.gif\") repeat top center;}\n"
817777
. 'body {background-url: url("https://somesite.com/images/someimage.gif");}';
818778
self::assertSame($expected, $document->render());
819779
}

0 commit comments

Comments
 (0)