Skip to content

Commit

Permalink
Fixed line/column number in violations.
Browse files Browse the repository at this point in the history
Better NoQuotationMark detection.
  • Loading branch information
szatom committed Jun 8, 2023
1 parent d094c6e commit fb10a62
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions brainsum_twigcs/src/Rule/NoQuotationMarkAttributeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ public function check(TokenStream $tokens)
Token::VAR_START_TYPE === $tokens->look(Lexer::NEXT_TOKEN)->getType() &&
Token::WHITESPACE_TYPE === $tokens->look(2)->getType() &&
Token::NAME_TYPE === $tokens->look(3)->getType()) {

$violations[] = $this->createViolation(
$tokens->getSourceContext()->getPath(),
$token->getLine(),
$token->getColumn() + strlen($token->getValue()) + 1,
'Unsafe attribute value without quotation mark.'
);
}
$quots = substr_count(strstr($token->getValue(), '<'), '"');

if (!($quots % 2)) {
$violations[] = $this->createViolation(
$tokens->getSourceContext()->getPath(),
$tokens->look(Lexer::NEXT_TOKEN)->getLine(),
$tokens->look(Lexer::NEXT_TOKEN)->getColumn() + strlen($tokens->look(Lexer::NEXT_TOKEN)->getValue()) - 1,
'Unsafe attribute value without quotation mark.'
);
}
}

$tokens->next();
}
Expand Down

0 comments on commit fb10a62

Please sign in to comment.