File tree Expand file tree Collapse file tree 3 files changed +38
-4
lines changed
Expand file tree Collapse file tree 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -207,7 +207,7 @@ protected function lintChar(string $sChar): ?bool
207207
208208 if (is_bool ($ bLintNestedSelectorChar = $ this ->lintNestedSelectorChar ($ sChar ))) {
209209 $ this ->setPreviousChar ($ sChar );
210- return $ bLintPropertyContentChar ;
210+ return $ bLintNestedSelectorChar ;
211211 }
212212
213213 $ this ->addError ('Unexpected char ' . json_encode ($ sChar ));
@@ -251,9 +251,11 @@ protected function lintSelectorChar(string $sChar): ?bool
251251 {
252252 // Selector must start by #.a-zA-Z
253253 if ($ this ->assertContext (null )) {
254- if ($ sChar === ' ' ) {
254+
255+ if ($ this ->getCssLintProperties ()->isAllowedIndentationChar ($ sChar )) {
255256 return true ;
256257 }
258+
257259 if (preg_match ('/[@#.a-zA-Z\[\*-:]+/ ' , $ sChar )) {
258260 $ this ->setContext (self ::CONTEXT_SELECTOR );
259261 $ this ->addContextContent ($ sChar );
@@ -347,9 +349,14 @@ protected function lintSelectorContentChar(string $sChar): ?bool
347349 if (!$ this ->assertContext (self ::CONTEXT_SELECTOR_CONTENT )) {
348350 return null ;
349351 }
350- if ($ sChar === ' ' ) {
352+
353+ $ sContextContent = $ this ->getContextContent ();
354+ if ((!$ sContextContent || $ sContextContent === '{ ' ) &&
355+ $ this ->getCssLintProperties ()->isAllowedIndentationChar ($ sChar )
356+ ) {
351357 return true ;
352358 }
359+
353360 if ($ sChar === '} ' ) {
354361 if ($ this ->isNestedSelector ()) {
355362 $ this ->resetContext ();
Original file line number Diff line number Diff line change @@ -460,6 +460,8 @@ class Properties
460460 'text-size-adjust ' => '' ,
461461 ];
462462
463+ protected static $ allowedIndentationChars = [' ' ];
464+
463465 /**
464466 * @param string $sProperty
465467 * @return boolean
@@ -486,4 +488,19 @@ public static function propertyExists(string $sProperty): bool
486488 }
487489 return false ;
488490 }
491+
492+ public static function getAllowedIndentationChars (): array
493+ {
494+ return static ::$ allowedIndentationChars ;
495+ }
496+
497+ public static function setAllowedIndentationChars (array $ aAllowedIndentationChars )
498+ {
499+ static ::$ allowedIndentationChars = $ aAllowedIndentationChars ;
500+ }
501+
502+ public static function isAllowedIndentationChar ($ sChar ): bool
503+ {
504+ return in_array ($ sChar , static ::$ allowedIndentationChars , true );
505+ }
489506}
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public function testLintValidString()
4141 .button.arrow-only::after {
4242 top: -0.1em;
4343 float: none;
44- margin-left: 0; } ' ));
44+ margin-left: 0; } ' ), print_r ( $ this -> linter -> getErrors (), true ) );
4545 }
4646
4747 public function testLintNotValidString ()
@@ -57,6 +57,16 @@ public function testLintNotValidString()
5757 ], $ this ->linter ->getErrors ());
5858 }
5959
60+ public function testLintValidStringContainingTabs ()
61+ {
62+ $ this ->linter ->getCssLintProperties ()->setAllowedIndentationChars (["\t" ]);
63+ $ this ->assertTrue ($ this ->linter ->lintString ("\t\t" . '.button.dropdown::after {
64+ ' . "\t\t" . 'display: block;
65+ ' . "\t\t" . '} ' ), print_r ($ this ->linter ->getErrors (), true ));
66+
67+ $ this ->linter ->getCssLintProperties ()->setAllowedIndentationChars ([' ' ]);
68+ }
69+
6070 public function testLintStringWithUnterminatedContext ()
6171 {
6272 $ this ->assertFalse ($ this ->linter ->lintString ('* { ' ));
You can’t perform that action at this time.
0 commit comments