From aa7648fedf7156b988b5459b74f8259035304cfe Mon Sep 17 00:00:00 2001 From: szatom Date: Thu, 8 Jun 2023 16:08:16 +0200 Subject: [PATCH] Fixed line/column number in violations. Better NoQuotationMark detection. --- .../src/Rule/NoQuotationMarkAttributeRule.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/brainsum_twigcs/src/Rule/NoQuotationMarkAttributeRule.php b/brainsum_twigcs/src/Rule/NoQuotationMarkAttributeRule.php index d772164..78db1a0 100644 --- a/brainsum_twigcs/src/Rule/NoQuotationMarkAttributeRule.php +++ b/brainsum_twigcs/src/Rule/NoQuotationMarkAttributeRule.php @@ -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(); }