Skip to content

🐛 Multiple bugFix #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions TwigCS/src/Report/TextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public function display(Report $report, string $level = null): void
}

/**
* @param string $template
* @param int $line
* @param int $context
* @param string $template
* @param int|null $line
* @param int $context
*
* @return array
*/
protected function getContext(string $template, int $line, int $context): array
protected function getContext(string $template, ?int $line, int $context): array
{
$lines = explode("\n", $template);

Expand Down
2 changes: 1 addition & 1 deletion TwigCS/src/Runner/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function fixFile(string $file): bool
try {
$twigSource = new Source($contents, 'TwigCS');
$stream = $this->tokenizer->tokenize($twigSource);
} catch (Exception $e) {
} catch (Exception $exception) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions TwigCS/src/Runner/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ protected function processTemplate(string $file, Ruleset $ruleset, Report $repor
// Tokenizer.
try {
$stream = $this->tokenizer->tokenize($twigSource);
} catch (Exception $e) {
} catch (Exception $exception) {
$sniffViolation = new SniffViolation(
Report::MESSAGE_TYPE_FATAL,
sprintf('Unable to tokenize file: %s', $e->getMessage()),
sprintf('Unable to tokenize file: %s', $exception->getMessage()),
$file
);

Expand Down
5 changes: 5 additions & 0 deletions TwigCS/src/Token/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,11 @@ protected function lexPunctuation(): void
array_pop($this->bracketsAndTernary);
$lastBracket = end($this->bracketsAndTernary);
} while ('?' === $lastBracket[0]);

// This is maybe the end of the variable, start again.
$this->lexVariable();

return;
}
}

Expand Down
4 changes: 2 additions & 2 deletions TwigCS/tests/Ruleset/AbstractSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ protected function checkSniff(SniffInterface $sniff, array $expects): void

$ruleset->addSniff($sniff);
$report = $linter->run([$file], $ruleset);
} catch (Exception $e) {
self::fail($e->getMessage());
} catch (Exception $exception) {
self::fail($exception->getMessage());

return;
}
Expand Down
12 changes: 11 additions & 1 deletion TwigCS/tests/Token/Tokenizer/TokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,17 @@ public function tokenizeDataProvider(): array
75 => Token::WHITESPACE_TYPE,
76 => Token::BLOCK_END_TYPE,
77 => Token::EOL_TYPE,
78 => Token::EOF_TYPE,
78 => Token::VAR_START_TYPE,
79 => Token::WHITESPACE_TYPE,
80 => Token::NAME_TYPE,
81 => Token::WHITESPACE_TYPE,
82 => Token::OPERATOR_TYPE,
83 => Token::WHITESPACE_TYPE,
84 => Token::STRING_TYPE,
85 => Token::WHITESPACE_TYPE,
86 => Token::VAR_END_TYPE,
87 => Token::EOL_TYPE,
88 => Token::EOF_TYPE,
],
],
[
Expand Down
1 change: 1 addition & 0 deletions TwigCS/tests/Token/Tokenizer/TokenizerTest3.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
{{ bar ? 'string' : "string#" }}
{{ baz ?: { a:[1, 2] } }}
{% set a={foo: bar ? baz ? 1, test: 1} %}
{{ a ? ',' }}