Repository: martin-helmich/typo3-typoscript-lint (php)

Issue:
No warning for not indented lines in conditions
Given the TypoScript
```typoscript
[globalString = GP:foo = 1]
foo.bar = 3
[global]
```
and the configuration
```yaml
sniffs:
  - class: Indentation
    parameters:
      indentConditions: true
```
the linter completes without warnings. Although line 2 should be indented with 4 spaces.

Pull request description:
Fix no warnings for not indented lines in conditions
Fixes #101

Patch:
diff --git a/src/Linter/Sniff/IndentationSniff.php b/src/Linter/Sniff/IndentationSniff.php
index 0234088..60fe84d 100644
--- a/src/Linter/Sniff/IndentationSniff.php
+++ b/src/Linter/Sniff/IndentationSniff.php
@@ -77,7 +77,7 @@ class IndentationSniff implements TokenStreamSniffInterface
             }));
 
             // Skip empty lines and conditions inside conditions.
-            if ($this->isEmptyLine($tokensInLine) || $this->insideCondition && $tokensInLine[0] !== TokenInterface::TYPE_CONDITION && !self::isWhitespace($tokensInLine[0])) {
+            if ($this->isEmptyLine($tokensInLine) || ($this->insideCondition && self::isCondition($tokensInLine[0]))) {
                 continue;
             }
 
diff --git a/src/Linter/Sniff/Inspection/TokenInspections.php b/src/Linter/Sniff/Inspection/TokenInspections.php
index 42fe535..8ad69b1 100644
--- a/src/Linter/Sniff/Inspection/TokenInspections.php
+++ b/src/Linter/Sniff/Inspection/TokenInspections.php
@@ -71,4 +71,15 @@ trait TokenInspections
     {
         return static::isWhitespace($token) && strlen(trim($token->getValue(), "\n")) == $length;
     }
-}
\ No newline at end of file
+
+    /**
+     * Tests whether a token is a condition
+     *
+     * @param TokenInterface $token
+     * @return bool
+     */
+    private static function isCondition(TokenInterface $token): bool
+    {
+        return $token->getType() === TokenInterface::TYPE_CONDITION || $token->getType() === TokenInterface::TYPE_CONDITION_ELSE;
+    }
+}


Test patch:
diff --git a/tests/unit/Helmich/TypoScriptLint/Linter/Sniff/IndentationSniffTest.php b/tests/unit/Helmich/TypoScriptLint/Linter/Sniff/IndentationSniffTest.php
index a2ce61d..470fa34 100644
--- a/tests/unit/Helmich/TypoScriptLint/Linter/Sniff/IndentationSniffTest.php
+++ b/tests/unit/Helmich/TypoScriptLint/Linter/Sniff/IndentationSniffTest.php
@@ -88,7 +88,7 @@ plugin.tx_solr {
 [end]
 EOF;
 
-        $sniff = new IndentationSniff(["indentConditions" => true]);
+        $sniff = new IndentationSniff([]);
         $tokens = (new Tokenizer())->tokenizeString($code);
         $file = new File("file");
 
@@ -97,4 +97,28 @@ EOF;
         $warnings = $file->getIssues();
         assertThat($warnings, equalTo([]));
     }
+
+    /**
+     * @see https://github.com/martin-helmich/typo3-typoscript-lint/issues/101
+     */
+    public function testWarningIsGeneratedForNotIndentedLinesInConditions()
+    {
+        $code = <<<EOF
+[globalString = GP:foo = 1]
+foo.bar = 3
+[global]
+EOF;
+
+        $sniff = new IndentationSniff(["indentConditions" => true]);
+        $tokens = (new Tokenizer())->tokenizeString($code);
+        $file = new File("file");
+
+        $sniff->sniff($tokens, $file, new LinterConfiguration());
+
+        $warnings = $file->getIssues();
+
+        $this->assertCount(1, $warnings);
+        $this->assertEquals('Expected indent of 4 spaces.', $warnings[0]->getMessage());
+        $this->assertEquals(2, $warnings[0]->getLine());
+    }
 }