diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index 913b854..72cae65 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -209,6 +209,28 @@ Using ``runtime-set``: --runtime-set removedTypoScriptConfigFiles "/Some/Absolute/Path/*.yaml" +.. _configuration-removedTypoScriptConstantConfigFiles: + +removedTypoScriptConstantsConfigFiles +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Configure where to look for configuration files defining the removed TypoScript constants. +Default is ``Configuration/Removed/TypoScriptConstants/*.yaml`` inside the standard itself. +We already try to deliver as much as possible. Globing is used, so placeholders like ``*`` are +possible, see https://secure.php.net/manual/en/function.glob.php + +Using :file:`ruleset.xml`: + +.. code:: xml + + + +Using ``runtime-set``: + +.. code:: bash + + --runtime-set removedTypoScriptConstantConfigFiles "/Some/Absolute/Path/*.yaml" + .. _configuration-features: features diff --git a/Documentation/source/features.rst b/Documentation/source/features.rst index c7bc589..7576335 100644 --- a/Documentation/source/features.rst +++ b/Documentation/source/features.rst @@ -114,6 +114,10 @@ This will check whether you are using already removed TypoScript parts, supporte - Paths like ``styles.insertContent`` +Check for usage of *removed TypoScript constants*. The TypoScript constants are configured in same +way as removed functions. For configuration options see +:ref:`configuration-removedTypoScriptConstantConfigFiles`. + For a complete list, take a look at the corresponding YAML-Files. Further checks diff --git a/src/Standards/Typo3Update/Configuration/Removed/TypoScriptConstant/7.0.yaml b/src/Standards/Typo3Update/Configuration/Removed/TypoScriptConstant/7.0.yaml new file mode 100644 index 0000000..80d7e28 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/TypoScriptConstant/7.0.yaml @@ -0,0 +1,20 @@ +# Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Index.html#breaking-changes +'7.0': + _clear: + replacement: 'Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html' + _blackBorderWrap: + replacement: 'Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html' + _tableWrap: + replacement: 'Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html' + _tableWrap_DEBUG: + replacement: 'Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html' + _stdFrameParams: + replacement: 'Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html' + _stdFramesetParams: + replacement: 'Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html' diff --git a/src/Standards/Typo3Update/Options.php b/src/Standards/Typo3Update/Options.php index 62b8a78..f5a4777 100644 --- a/src/Standards/Typo3Update/Options.php +++ b/src/Standards/Typo3Update/Options.php @@ -95,6 +95,19 @@ class Options ); } + /** + * Returns an array of absolute file names containing removed typoscript constants. + * + * @return array + */ + public static function getRemovedTypoScriptConstantConfigFiles() + { + return static::getOptionFileNames( + 'removedTypoScriptConstant', + __DIR__ . '/Configuration/Removed/TypoScriptConstant/*.yaml' + ); + } + /** * Returns an array of absolute file names containing removed class configurations. * diff --git a/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff.php new file mode 100644 index 0000000..c396d32 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff.php @@ -0,0 +1,86 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Helmich\TypoScriptParser\Tokenizer\TokenInterface; +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Options; +use Typo3Update\Sniffs\Removed\AbstractGenericUsage; + +class Typo3Update_Sniffs_Removed_TypoScriptConstantSniff extends AbstractGenericUsage +{ + /** + * Register sniff only for TypoScript. + * @var array + */ + public $supportedTokenizers = [ + 'TYPOSCRIPT', + ]; + + public function register() + { + return [ + TokenInterface::TYPE_RIGHTVALUE_MULTILINE, + TokenInterface::TYPE_RIGHTVALUE, + ]; + } + + protected function prepareStructure(array $typo3Versions) + { + $newStructure = []; + + foreach ($typo3Versions as $typo3Version => $removals) { + foreach ($removals as $removed => $config) { + $config['name'] = $removed; + $config['identifier'] = $removed; + $config['oldUsage'] = $removed; + $config['versionRemoved'] = $typo3Version; + $newStructure[$removed] = $config; + } + } + + return $newStructure; + } + + protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + $removed = []; + $tokens = $phpcsFile->getTokens(); + $token = $tokens[$stackPtr]; + $matches = []; + preg_match_all('/\{\$.*\}/', $token['content'], $matches); + + foreach ($matches as $constants) { + foreach ($constants as $constant) { + $constant = substr($constant, 2, -1); + if ($this->configured->isRemoved($constant)) { + $removed[] = $this->configured->getRemoved($constant); + } + } + } + + return $removed; + } + + protected function getRemovedConfigFiles() + { + return Options::getRemovedTypoScriptConstantConfigFiles(); + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff/Expected.json new file mode 100644 index 0000000..e353a62 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff/Expected.json @@ -0,0 +1,42 @@ +{ + "files": { + "InputFileForIssues.ts": { + "errors": 0, + "messages": [ + { + "column": 13, + "fixable": false, + "line": 3, + "message": "Calls to removed code are not allowed; found _clear. Removed in 7.0. Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html", + "severity": 5, + "source": "Typo3Update.Removed.TypoScriptConstant._clear", + "type": "WARNING" + }, + { + "column": 11, + "fixable": false, + "line": 4, + "message": "Calls to removed code are not allowed; found _tableWrap_DEBUG. Removed in 7.0. Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html", + "severity": 5, + "source": "Typo3Update.Removed.TypoScriptConstant._tableWrap_DEBUG", + "type": "WARNING" + }, + { + "column": 11, + "fixable": false, + "line": 4, + "message": "Calls to removed code are not allowed; found _tableWrap. Removed in 7.0. Either remove usage of constant or add a snippet at an early point in TypoScript for backwards compatibility. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-60561-DefaultTypoScriptConstantsRemoved.html", + "severity": 5, + "source": "Typo3Update.Removed.TypoScriptConstant._tableWrap", + "type": "WARNING" + } + ], + "warnings": 3 + } + }, + "totals": { + "errors": 0, + "fixable": 0, + "warnings": 3 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff/InputFileForIssues.ts b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff/InputFileForIssues.ts new file mode 100644 index 0000000..e8cc475 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff/InputFileForIssues.ts @@ -0,0 +1,8 @@ +test = TEXT +test { + value = Some stuff {$_clear} and some more. + value ( + Some values {$_tableWrap_DEBUG} + {$_tableWrap} + ) +}