[TASK] Deprecate single slash comments in TypoScript 51/48051/17
authorElmar Hinz <t3elmar@gmail.com>
Mon, 9 May 2016 19:59:37 +0000 (21:59 +0200)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 27 May 2016 11:41:34 +0000 (13:41 +0200)
Double slash one-line comments are standard in many languages.
Make them standard in TypoScript, too.

Deprecated:
  / Line comment headed by single slash

Resolves: #76104
Releases: master
Change-Id: Id78391f973cdf8147bf91b269996f31d475de717
Reviewed-on: https://review.typo3.org/48051
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-76104-Deprecated-Single-Slash-Comments-In-TypoScript.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php

index 1596b84..06db119 100644 (file)
@@ -483,6 +483,9 @@ class TypoScriptParser
                             break;
                         }
                     } else {
+                        if (preg_match('|^\s*/[^/]|', $line)) {
+                            $this->error('Line ' . ($this->lineNumberOffset + $this->rawP - 1) .  ': Single slash headed one-line comments are deprecated.', 2);
+                        }
                         if ($this->syntaxHighLight) {
                             $this->regHighLight('comment', $lineP);
                         }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76104-Deprecated-Single-Slash-Comments-In-TypoScript.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76104-Deprecated-Single-Slash-Comments-In-TypoScript.rst
new file mode 100644 (file)
index 0000000..ddae1e0
--- /dev/null
@@ -0,0 +1,27 @@
+====================================================================
+Deprecation: #76104 - Deprecated single slash comments in TypoScript
+====================================================================
+
+Description
+===========
+
+Double slash one-line comments are standard in many languages.
+Make them standard for TypoScript, too.
+
+Define::
+
+   One-line comments must start with two forward slashes as
+   the first non-blank characters and should be followed by
+   a whitespace.
+
+
+Deprecated::
+
+   / Line comment headed by single slash
+
+
+Impact
+======
+
+The TypoScript devoloper receives a deprecation warning
+with line number.
index 96bd068..be1912c 100644 (file)
@@ -263,6 +263,62 @@ class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
+     * @test
+     */
+    public function invalidCharactersInObjectNamesAreReported()
+    {
+        $typoScript = '$.10 = invalid';
+        $this->typoScriptParser->parse($typoScript);
+        $expected = 'Line 0: Object Name String, "$.10" contains invalid character "$". Must be alphanumeric or one of: "_:-\."';
+        $this->assertEquals($expected, $this->typoScriptParser->errors[0][0]);
+    }
+
+    /**
+     * @return array
+     */
+    public function doubleSlashCommentsDataProvider()
+    {
+        return [
+            'valid, without spaces' => ['// valid, without spaces'],
+            'valid, with one space' => [' // valid, with one space'],
+            'valid, with multiple spaces' => ['  // valid, with multiple spaces'],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider doubleSlashCommentsDataProvider
+     */
+    public function doubleSlashCommentsAreValid($typoScript)
+    {
+        $this->typoScriptParser->parse($typoScript);
+        $this->assertEmpty($this->typoScriptParser->errors);
+    }
+
+    /**
+     * @return array
+     */
+    public function singleSlashCommentsDataProvider()
+    {
+        return [
+            'deprecated, without spaces' => ['/ deprecated, without spaces'],
+            'deprecated, with one space' => [' / deprecated, with one space'],
+            'deprecated, with multiple spaces' => ['  / deprecated, with multiple spaces'],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider singleSlashCommentsDataProvider
+     */
+    public function singleSlashHeadedCommentsAreDeprecated($typoScript)
+    {
+        $this->typoScriptParser->parse($typoScript);
+        $expected = 'Line 0: Single slash headed one-line comments are deprecated.';
+        $this->assertEquals($expected, $this->typoScriptParser->errors[0][0]);
+    }
+
+    /**
      * @param string $typoScript
      * @param array $expected
      * @dataProvider typoScriptIsParsedToArrayDataProvider