From 7a999212e20414e142ce27d7a31750791e0a9597 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 13 Apr 2017 13:32:20 +0200 Subject: [PATCH] FEATURE: Add first TypoScript sniff * Add configuration for removed object identifiers. * Add sniff for removed object identifiers. Relates: #54 --- .../TypoScript/ObjectIdentifier/7.0.yaml | 5 ++ .../TypoScriptObjectIdentifierSniff.php | 86 +++++++++++++++++++ .../Expected.json | 33 +++++++ .../InputFileForIssues.ts | 4 + 4 files changed, 128 insertions(+) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/TypoScript/ObjectIdentifier/7.0.yaml create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff.php create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/Expected.json create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/InputFileForIssues.ts diff --git a/src/Standards/Typo3Update/Configuration/Removed/TypoScript/ObjectIdentifier/7.0.yaml b/src/Standards/Typo3Update/Configuration/Removed/TypoScript/ObjectIdentifier/7.0.yaml new file mode 100644 index 0000000..33fa3d1 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/TypoScript/ObjectIdentifier/7.0.yaml @@ -0,0 +1,5 @@ +# Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Index.html#breaking-changes +'7.0': + styles.insertContent: + replacement: 'Either remove usage of styles.insertContent 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-42543-DefaultTypoScriptRemoved.html' diff --git a/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff.php new file mode 100644 index 0000000..d3c6db8 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff.php @@ -0,0 +1,86 @@ + + */ + public function register() + { + return [ + TokenInterface::TYPE_OBJECT_IDENTIFIER, + ]; + } + + /** + * Check whether the current token is removed. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * @return bool + */ + protected function isRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $token = $tokens[$stackPtr]; + $objectIdentifier = $token['content']; + + if (isset($this->configured[$objectIdentifier])) { + $this->removed = [ + $this->configured[$objectIdentifier] + ]; + return true; + } + + return false; + } + + /** + * Identifier for configuring this specific error / warning through PHPCS. + * + * @param array $config + * + * @return string + */ + protected function getIdentifier(array $config) + { + return str_replace('.', '-', $config['name']); + } + + /** + * The original call, to allow user to check matches. + * + * As we match the name, that can be provided by multiple classes, you + * should provide an example, so users can check that this is the legacy + * one. + * + * @param array $config + * + * @return string + */ + protected function getOldUsage(array $config) + { + return $config['name']; + } + + /** + * Return file names containing removed configurations. + * + * @return array + */ + protected function getRemovedConfigFiles() + { + return Options::getRemovedTypoScriptObjectIdentifierConfigFiles(); + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/Expected.json new file mode 100644 index 0000000..f5f9a91 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/Expected.json @@ -0,0 +1,33 @@ +{ + "files": { + "InputFileForIssues.ts": { + "errors": 0, + "messages": [ + { + "column": 10, + "fixable": false, + "line": 2, + "message": "Legacy calls are not allowed; found styles.insertContent. Removed in 7.0. Either remove usage of styles.insertContent 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-42543-DefaultTypoScriptRemoved.html", + "severity": 5, + "source": "Typo3Update.Removed.TypoScriptObjectIdentifier.styles-insertContent", + "type": "WARNING" + }, + { + "column": 11, + "fixable": false, + "line": 3, + "message": "Legacy calls are not allowed; found styles.insertContent. Removed in 7.0. Either remove usage of styles.insertContent 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-42543-DefaultTypoScriptRemoved.html", + "severity": 5, + "source": "Typo3Update.Removed.TypoScriptObjectIdentifier.styles-insertContent", + "type": "WARNING" + } + ], + "warnings": 2 + } + }, + "totals": { + "errors": 0, + "fixable": 0, + "warnings": 2 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/InputFileForIssues.ts b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/InputFileForIssues.ts new file mode 100644 index 0000000..660a53c --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/TypoScriptObjectIdentifierSniff/InputFileForIssues.ts @@ -0,0 +1,4 @@ +page { + 10 < styles.insertContent + 10 =< styles.insertContent +}