Skip to content

Commit fb10a62

Browse files
committed
Fixed line/column number in violations.
Better NoQuotationMark detection.
1 parent d094c6e commit fb10a62

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

brainsum_twigcs/src/Rule/NoQuotationMarkAttributeRule.php

+11-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ public function check(TokenStream $tokens)
2323
Token::VAR_START_TYPE === $tokens->look(Lexer::NEXT_TOKEN)->getType() &&
2424
Token::WHITESPACE_TYPE === $tokens->look(2)->getType() &&
2525
Token::NAME_TYPE === $tokens->look(3)->getType()) {
26-
27-
$violations[] = $this->createViolation(
28-
$tokens->getSourceContext()->getPath(),
29-
$token->getLine(),
30-
$token->getColumn() + strlen($token->getValue()) + 1,
31-
'Unsafe attribute value without quotation mark.'
32-
);
33-
}
26+
$quots = substr_count(strstr($token->getValue(), '<'), '"');
27+
28+
if (!($quots % 2)) {
29+
$violations[] = $this->createViolation(
30+
$tokens->getSourceContext()->getPath(),
31+
$tokens->look(Lexer::NEXT_TOKEN)->getLine(),
32+
$tokens->look(Lexer::NEXT_TOKEN)->getColumn() + strlen($tokens->look(Lexer::NEXT_TOKEN)->getValue()) - 1,
33+
'Unsafe attribute value without quotation mark.'
34+
);
35+
}
36+
}
3437

3538
$tokens->next();
3639
}

0 commit comments

Comments
 (0)