Skip to content

Commit f70f499

Browse files
committed
[FEATURE] Provide line number in exception message
... for mismatched parentheses in selector.
1 parent ca51e51 commit f70f499

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

CHANGELOG.md

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

1111
### Added
1212

13+
- Provide line number in exception message for mismatched parentheses in
14+
selector (#1435)
1315
- Add support for CSS container queries (#1400)
1416

1517
### Changed

src/RuleSet/DeclarationBlock.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ private static function parseSelector(ParserState $parserState, array &$comments
329329
case ')':
330330
if (!\is_string($stringWrapperCharacter)) {
331331
if ($functionNestingLevel <= 0) {
332-
throw new UnexpectedTokenException('anything but', ')');
332+
throw new UnexpectedTokenException(
333+
'anything but',
334+
')',
335+
'literal',
336+
$parserState->currentLine()
337+
);
333338
}
334339
--$functionNestingLevel;
335340
}
@@ -351,7 +356,7 @@ private static function parseSelector(ParserState $parserState, array &$comments
351356
}
352357

353358
if ($functionNestingLevel !== 0) {
354-
throw new UnexpectedTokenException(')', $nextCharacter);
359+
throw new UnexpectedTokenException(')', $nextCharacter, 'literal', $parserState->currentLine());
355360
}
356361

357362
$selector = \trim(\implode('', $selectorParts));

tests/Unit/RuleSet/DeclarationBlockTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ public static function provideInvalidSelectorAndExpectedExceptionMessage(): arra
232232
{
233233
return [
234234
'no selector' => ['', 'Token “selector” (literal) not found. Got “{”. [line no: 1]'],
235-
'lone `(`' => ['(', 'Token “)” (literal) not found. Got “{”.'],
236-
'lone `)`' => [')', 'Token “anything but” (literal) not found. Got “)”.'],
235+
'lone `(`' => ['(', 'Token “)” (literal) not found. Got “{”. [line no: 1]'],
236+
'lone `)`' => [')', 'Token “anything but” (literal) not found. Got “)” [line no: 1].'],
237237
'lone `,`' => [',', 'Token “selector” (literal) not found. Got “,”. [line no: 1]'],
238-
'unclosed `(`' => [':not(#your-mug', 'Token “)” (literal) not found. Got “{”.'],
239-
'extra `)`' => [':not(#your-mug))', 'Token “anything but” (literal) not found. Got “)”.'],
238+
'unclosed `(`' => [':not(#your-mug', 'Token “)” (literal) not found. Got “{” [line no: 1].'],
239+
'extra `)`' => [':not(#your-mug))', 'Token “anything but” (literal) not found. Got “)” [line no: 1].'],
240240
'`,` missing left operand' => [', a', 'Token “selector” (literal) not found. Got “,”. [line no: 1]'],
241241
'`,` missing right operand' => ['a,', 'Token “selector” (literal) not found. Got “{”. [line no: 1]'],
242242
];

0 commit comments

Comments
 (0)