From e1e34016386d397583cf04dfc43b470f819cd5a3 Mon Sep 17 00:00:00 2001 From: Elmar Hinz <t3elmar@gmail.com> Date: Mon, 9 May 2016 21:59:37 +0200 Subject: [PATCH] [TASK] Deprecate single slash comments in TypoScript 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> --- .../TypoScript/Parser/TypoScriptParser.php | 3 + ...ed-Single-Slash-Comments-In-TypoScript.rst | 27 +++++++++ .../Parser/TypoScriptParserTest.php | 56 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-76104-Deprecated-Single-Slash-Comments-In-TypoScript.rst diff --git a/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php b/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php index 1596b846ad49..06db119aa5c3 100644 --- a/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php +++ b/typo3/sysext/core/Classes/TypoScript/Parser/TypoScriptParser.php @@ -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 index 000000000000..ddae1e021b1c --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-76104-Deprecated-Single-Slash-Comments-In-TypoScript.rst @@ -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. diff --git a/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php b/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php index 96bd068665da..be1912cd13ca 100644 --- a/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php +++ b/typo3/sysext/core/Tests/Unit/TypoScript/Parser/TypoScriptParserTest.php @@ -262,6 +262,62 @@ class TypoScriptParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $this->typoScriptParser->_call('executeValueModifier', $modifierName, $modifierArgument, $currentValue); } + /** + * @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 -- GitLab