Skip to content

Commit

Permalink
Ignore empty lines when checking indentation (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-helmich authored May 2, 2021
1 parent 7fba670 commit 822a6ea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Linter/Sniff/IndentationSniff.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Helmich\TypoScriptLint\Linter\Sniff;

use Helmich\TypoScriptLint\Linter\LinterConfiguration;
Expand Down Expand Up @@ -72,7 +75,7 @@ public function sniff(array $tokens, File $file, LinterConfiguration $configurat
$expectedIndentationCharacterCount
);

$tokensInLine = array_values(array_filter($tokensInLine, function(TokenInterface $token): bool {
$tokensInLine = array_values(array_filter($tokensInLine, function (TokenInterface $token): bool {
return $token->getType() !== TokenInterface::TYPE_RIGHTVALUE_MULTILINE;
}));

Expand Down Expand Up @@ -105,6 +108,14 @@ public function sniff(array $tokens, File $file, LinterConfiguration $configurat
*/
private function isEmptyLine(array $tokensInLine): bool
{
$tokensInLine = array_values(array_filter($tokensInLine, function (TokenInterface $t): bool {
return $t->getType() !== TokenInterface::TYPE_EMPTY_LINE;
}));

if (count($tokensInLine) === 0) {
return true;
}

if (count($tokensInLine) > 1) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
foo {
bar = 2

baz = 5
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3;2;Expected indent of 4 spaces.;warning;Helmich\TypoScriptLint\Linter\Sniff\IndentationSniff
4;2;Expected indent of 4 spaces.;warning;Helmich\TypoScriptLint\Linter\Sniff\IndentationSniff

0 comments on commit 822a6ea

Please sign in to comment.