Merge branch 'feature/54-add-checks-for-typoscript' into 'develop'

Feature/54 add checks for typoscript

Closes #54

See merge request !74
This commit is contained in:
Daniel Hürtgen 2017-04-27 10:45:13 +02:00
commit 01af1eaf4b
13 changed files with 565 additions and 26 deletions

View file

@ -1,3 +1,4 @@
.. _highlight: yaml
.. _configuration: .. _configuration:
Configuration Configuration
@ -7,6 +8,13 @@ Configuration is done through PHPCS Standards, e.g. provide a custom :file:`rule
project using a :file:`phpcs.xml.dist`. As this is just a PHPCS-Standard, the official documentation project using a :file:`phpcs.xml.dist`. As this is just a PHPCS-Standard, the official documentation
applies. applies.
Also some configuration is done through yaml files, see :ref:`configuration-yaml-files`.
.. _configuration-options:
Options
-------
All options available in :file:`ruleset.xml` are also available in your :file:`phpcs.xml` files, as All options available in :file:`ruleset.xml` are also available in your :file:`phpcs.xml` files, as
already documented by phpcs itself. Therefore this documentation will just mention already documented by phpcs itself. Therefore this documentation will just mention
:file:`ruleset.xml`. :file:`ruleset.xml`.
@ -22,7 +30,7 @@ The following configuration options are available:
.. _configuration-legacyExtensions: .. _configuration-legacyExtensions:
legacyExtensions legacyExtensions
---------------- ^^^^^^^^^^^^^^^^
Configures which extension names are legacy. Used to provide further checks and warnings about Configures which extension names are legacy. Used to provide further checks and warnings about
possible legacy code. All class usages starting with ``Tx_<ExtensionName>`` where ExtensionName is possible legacy code. All class usages starting with ``Tx_<ExtensionName>`` where ExtensionName is
@ -44,7 +52,7 @@ Example:
.. _configuration-allowedTags: .. _configuration-allowedTags:
allowedTags allowedTags
----------- ^^^^^^^^^^^
Only used inside Sniff ``Typo3Update.Classname.PhpDocComment``. Only used inside Sniff ``Typo3Update.Classname.PhpDocComment``.
@ -66,7 +74,7 @@ Example:
.. _configuration-mappingFile: .. _configuration-mappingFile:
mappingFile mappingFile
----------- ^^^^^^^^^^^
For auto migrating usages of old class names, a PHP file with a mapping is required. The file has to For auto migrating usages of old class names, a PHP file with a mapping is required. The file has to
be in the composer structure :file:`autoload_classaliasmap.php`. be in the composer structure :file:`autoload_classaliasmap.php`.
@ -91,7 +99,7 @@ Using ``runtime-set``:
.. _configuration-vendor: .. _configuration-vendor:
vendor vendor
------ ^^^^^^
Used while adding namespaces to legacy class definitions and updating plugin and module Used while adding namespaces to legacy class definitions and updating plugin and module
registrations. Default is ``YourCompany`` to enable you to search and replace afterwards. registrations. Default is ``YourCompany`` to enable you to search and replace afterwards.
@ -106,7 +114,7 @@ Using :file:`ruleset.xml`:
<config name="vendor" value="YourVendor"/> <config name="vendor" value="YourVendor"/>
Example: Using ``runtime-set``:
.. code:: bash .. code:: bash
@ -115,7 +123,7 @@ Example:
.. _configuration-removedFunctionConfigFiles: .. _configuration-removedFunctionConfigFiles:
removedFunctionConfigFiles removedFunctionConfigFiles
-------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^
Configure where to look for configuration files defining the removed functions and methods. Default Configure where to look for configuration files defining the removed functions and methods. Default
is ``Configuration/Removed/Functions/*.yaml`` inside the standard itself. We already try to deliver is ``Configuration/Removed/Functions/*.yaml`` inside the standard itself. We already try to deliver
@ -129,7 +137,7 @@ Using :file:`ruleset.xml`:
<config name="removedFunctionConfigFiles" value="/Some/Absolute/Path/*.yaml"/> <config name="removedFunctionConfigFiles" value="/Some/Absolute/Path/*.yaml"/>
Example: Using ``runtime-set``:
.. code:: bash .. code:: bash
@ -138,7 +146,7 @@ Example:
.. _configuration-removedConstantConfigFiles: .. _configuration-removedConstantConfigFiles:
removedConstantConfigFiles removedConstantConfigFiles
-------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^
Configure where to look for configuration files defining the removed constants. Default is Configure where to look for configuration files defining the removed constants. Default is
``Configuration/Removed/Functions/*.yaml`` inside the standard itself. We already try to deliver as ``Configuration/Removed/Functions/*.yaml`` inside the standard itself. We already try to deliver as
@ -151,16 +159,38 @@ Using :file:`ruleset.xml`:
<config name="removedConstantConfigFiles" value="/Some/Absolute/Path/*.yaml"/> <config name="removedConstantConfigFiles" value="/Some/Absolute/Path/*.yaml"/>
Example: Using ``runtime-set``:
.. code:: bash .. code:: bash
--runtime-set removedConstantConfigFiles "/Some/Absolute/Path/*.yaml" --runtime-set removedConstantConfigFiles "/Some/Absolute/Path/*.yaml"
.. _configuration-removedTypoScriptConfigFiles:
removedTypoScriptConfigFiles
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Configure where to look for configuration files defining the removed TypoScript object identifiers.
Default is ``Configuration/Removed/TypoScript/*.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
<config name="removedTypoScriptConfigFiles" value="/Some/Absolute/Path/*.yaml"/>
Using ``runtime-set``:
.. code:: bash
--runtime-set removedTypoScriptConfigFiles "/Some/Absolute/Path/*.yaml"
.. _configuration-features: .. _configuration-features:
features features
-------- ^^^^^^^^
Configure where to look for configuration files defining the feature mappings. Default is Configure where to look for configuration files defining the feature mappings. Default is
``Configuration/Features/*.yaml`` inside the standard itself. Globing is used, so placeholders like ``Configuration/Features/*.yaml`` inside the standard itself. Globing is used, so placeholders like
@ -172,8 +202,89 @@ Using :file:`ruleset.xml`:
<config name="features" value="/Some/Absolute/Path/*.yaml"/> <config name="features" value="/Some/Absolute/Path/*.yaml"/>
Example: Using ``runtime-set``:
.. code:: bash .. code:: bash
--runtime-set features "/Some/Absolute/Path/*.yaml" --runtime-set features "/Some/Absolute/Path/*.yaml"
.. _configuration-yaml-files:
YAML Files
----------
YAML files are used to configure removed constants, function / methods and TypoScript. We decided to
go with yaml files here, to ease adding stuff in the future. It's a simple format and everyone can
contribute.
You can configure the paths to look up the files through the specific options, documented above.
This section will cover the structure of the various yaml files.
General structure
^^^^^^^^^^^^^^^^^
The basic structure is the same for all parts. Inside a file you have to provide an array for each
TYPO3 version::
'7.0':
styles.insertContent:
replacement: 'Either remove usage of styles.insertContent or a...'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0...'
'7.1':
\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->includeTCA:
replacement: 'Full TCA is always loaded during bootstrap in ...'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7...'
In above example the TypoScript ``styles.insertContent`` was removed in TYPO3 version *7.0*.
Below a TYPO3 version each entry is a removed function or TypoScript part of TYPO3. The key is used
to lookup matchings in the source code. Specific parsing is documented below.
All entries consists of a ``replacement`` and ``docsUrl`` entry.
The ``replacement`` can either be ``null`` or a string. If it's null we will show that this part is
removed without any replacement.
If you provide a string, this will be displayed to help during migrations.
The ``docsUrl`` is displayed in addition, so everyone can take a deeper look at the change, the
effects and how to migrate.
Also the TYPO3 core team references the forge issues in each change, where you can find the pull
requests.
Constants and Functions
^^^^^^^^^^^^^^^^^^^^^^^
Special parsing is done for the keys identifying removed constants and functions.
Always provide the fully qualified class namespace. Seperate the constant or method by ``::`` if
it's possible to access it static, otherwise use ``->`` to indicate it's an instance method.
This is used to check only matching calls.
Two examples::
'7.0':
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA:
replacement: null
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Ch...'
\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->includeTCA:
replacement: 'Full TCA is always loaded during bootstrap in FE, th...'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Change...'
TypoScript
^^^^^^^^^^
Use ``new`` in front of, to declare the entry as OBJECT, e.g. a cObject.
Only matching types will be checked in source code.
Two examples::
'7.0':
styles.insertContent:
replacement: 'Either remove usage of styles.insertContent or add a sni...'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog...'
'7.1':
new HRULER:
replacement: 'Any installation should migrate to alternatives such as F...'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog...'

View file

@ -31,6 +31,17 @@ You might want to add ``-p --colors`` to see that something is happening.
Also make sure to ignore certain files like libraries or js and css files while running the update. Also make sure to ignore certain files like libraries or js and css files while running the update.
Check out the official docs for how to do so. Check out the official docs for how to do so.
Lint TypoScript
---------------
To lint TypoScript, include the files in your linting and add the following arguments per file
extension::
--extensions=txt/TypoScript,ts/TypoScript
Make sure to ignore files with same file extension but different meaning, like documentatons, readme
or changelogs.
FAQ FAQ
--- ---

View file

@ -0,0 +1,26 @@
# 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'
mod.web_list.alternateBgColors:
replacement: 'Removed without substitution'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-53658-RemoveAlternateBgColorsOption.html'
acronym:
replacement: 'User TSconfig must be modified to refer to "abbreviation" instead of "acronym"'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-54409-RteAcronymButtonRenamedAbbreviation.html'
features.rewrittenPropertyMapper:
replacement: 'it is no longer possible to deactivate the feature. If configured with 1, just remove, otherwise adjust your code.'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-57396-ExtbaseDeprecatedPropertyMapperRemoved.html'
config.notification_email_charset:
replacement: ~
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62793-RemoveConfigNotification.html'
config.notification_email_encoding:
replacement: ~
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62793-RemoveConfigNotification.html'
config.notification_email_urlmode:
replacement: ~
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62793-RemoveConfigNotification.html'
config.uniqueLinkVars:
replacement: 'The setting config.uniqueLinkVars has been removed as the behaviour is now always used'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62888-RemoveUniqueLinkVars.html'

View file

@ -0,0 +1,35 @@
# Breaking changes in 7.1: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Index.html#breaking-changes
'7.1':
lib.parseFunc_RTE.externalBlocks.blockquote.callRecursive.tagStdWrap.HTMLparser:
replacement: 'It is recommended to fix the margins inside your website CSS. Alternatively, you can re-add the above TypoScript lines to your website TypoScript template (not recommended)'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-44879-CSSStyledContentTypoScriptBlockQuoteInlineStylesRemoved.html'
lib.parseFunc_RTE.externalBlocks.blockquote.callRecursive.tagStdWrap.HTMLparser.tags.blockquote.overrideAttribs:
replacement: 'It is recommended to fix the margins inside your website CSS. Alternatively, you can re-add the above TypoScript lines to your website TypoScript template (not recommended)'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-44879-CSSStyledContentTypoScriptBlockQuoteInlineStylesRemoved.html'
config.meaningfulTempFilePrefix:
replacement: 'All files will always have their original filename fully prepended when stored in the folder typo3temp/GB/. Just remove the setting'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-62886-RemoveMeaningfulTempFilePrefix.html'
new CLEARGIF:
replacement: 'Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html'
new COLUMNS:
replacement: 'Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html'
new CTABLE:
replacement: 'Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html'
new OTABLE:
replacement: 'Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html'
new HRULER:
replacement: 'Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html'
new FORM:
replacement: 'For TYPO3 CMS 7, installing EXT:compatibility6 brings back the existing functionality. For the long term the affected installations should migrate to a different, better suited solution for sending mails and building forms'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64668-MailformMovedToLegacyExtension.html'
new IMGTEXT:
replacement: 'Any installation should migrate to alternatives such as CSS Styled Content without a table-based rendering for text w/ image elements to customize the output of content'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64671-ContentObjectImgTextMovedToLegacyExtension.html'
new SEARCHRESULTS:
replacement: 'For TYPO3 CMS 7, installing EXT:compatibility6 brings back the existing functionality. For the long term the affected installations should be migrate to a better suited solution for searching'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64696-MoveSearchCTypeToLegacyExtension.html'

View file

@ -0,0 +1,23 @@
# Breaking changes in 7.2: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Index.html#breaking-changes
'7.2':
mod.web_info.menu.function.tx_cms_webinfo_page:
replacement: 'Renamed to mod.web_info.menu.function.TYPO3\CMS\Frontend\Controller\PageInformationController'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-66286-PageTSconfigOptionsToHideWebInfoModulesRenamed.html'
mod.web_info.menu.function.tx_cms_webinfo_lang:
replacement: 'Renamed to mod.web_info.menu.function.TYPO3\CMS\Frontend\Controller\TranslationStatusController'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-66286-PageTSconfigOptionsToHideWebInfoModulesRenamed.html'
mod.web_info.menu.function.tx_belog_webinfo:
replacement: 'Renamed to mod.web_info.menu.function.TYPO3\CMS\Belog\Module\BackendLogModuleBootstrap'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-66286-PageTSconfigOptionsToHideWebInfoModulesRenamed.html'
mod.web_info.menu.function.tx_infopagetsconfig_webinfo:
replacement: 'Renamed to mod.web_info.menu.function.TYPO3\CMS\InfoPagetsconfig\Controller\InfoPageTyposcriptConfigController'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-66286-PageTSconfigOptionsToHideWebInfoModulesRenamed.html'
mod.web_info.menu.function.tx_linkvalidator_ModFuncReport:
replacement: 'Renamed to mod.web_info.menu.function.TYPO3\CMS\Linkvalidator\Report\LinkValidatorReport'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-66286-PageTSconfigOptionsToHideWebInfoModulesRenamed.html'
mod.web_info.menu.function.tx_indexedsearch_modfunc1:
replacement: 'removed, indexed_search has its own module'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-66286-PageTSconfigOptionsToHideWebInfoModulesRenamed.html'
mod.web_info.menu.function.tx_indexedsearch_modfunc2:
replacement: 'removed, indexed_search has its own module'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-66286-PageTSconfigOptionsToHideWebInfoModulesRenamed.html'

View file

@ -0,0 +1,14 @@
# Breaking changes in 7.4: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Index.html#breaking-changes
'7.4':
page.javascriptLibs.Prototype:
replacement: ~
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Breaking-39721-PrototypejsAndScriptaculousRemoved.html'
page.javascriptLibs.Scriptaculous:
replacement: ~
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Breaking-39721-PrototypejsAndScriptaculousRemoved.html'
page.javascriptLibs.Scriptaculous.modules:
replacement: ~
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Breaking-39721-PrototypejsAndScriptaculousRemoved.html'
RTE.userLinks:
replacement: 'Use the newly added Tabbing API to add your custom link selection tab'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Breaking-68116-DropRTEuserLinksFunctionality.html'

View file

@ -0,0 +1,5 @@
# Breaking changes in 7.6: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.6/Index.html#breaking-changes
'7.6':
plugin.tx_indexedsearch.settings.showRules:
replacement: 'Use to plugin.tx_indexedsearch.settings.displayRules = 0 instead'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.6/Breaking-51099-StreamlineSettingsConditions.html'

View file

@ -82,6 +82,19 @@ class Options
); );
} }
/**
* Returns an array of absolute file names containing removed typoscript.
*
* @return array<string>
*/
public static function getRemovedTypoScriptConfigFiles()
{
return static::getOptionFileNames(
'removedTypoScript',
__DIR__ . '/Configuration/Removed/TypoScript/*.yaml'
);
}
/** /**
* Get the option by optionName, if not defined, use default. * Get the option by optionName, if not defined, use default.
* *

View file

@ -45,7 +45,7 @@ abstract class AbstractGenericUsage implements PhpCsSniff
protected $configured = []; protected $configured = [];
/** /**
* Constant for the current sniff instance. * Entries removed in current sniff.
* @var array * @var array
*/ */
protected $removed = []; protected $removed = [];
@ -101,7 +101,7 @@ abstract class AbstractGenericUsage implements PhpCsSniff
)[0]; )[0];
$newStructure[$removed]['name'] = $split[1]; $newStructure[$removed]['name'] = $split[1];
} }
}; }
} }
return $newStructure; return $newStructure;
@ -203,16 +203,16 @@ abstract class AbstractGenericUsage implements PhpCsSniff
*/ */
protected function addMessage(PhpCsFile $phpcsFile, $tokenPosition) protected function addMessage(PhpCsFile $phpcsFile, $tokenPosition)
{ {
foreach ($this->removed as $constant) { foreach ($this->removed as $removed) {
$phpcsFile->addWarning( $phpcsFile->addWarning(
'Legacy calls are not allowed; found %s. Removed in %s. %s. See: %s', 'Legacy calls are not allowed; found %s. Removed in %s. %s. See: %s',
$tokenPosition, $tokenPosition,
$this->getIdentifier($constant), $this->getIdentifier($removed),
[ [
$this->getOldUsage($constant), $this->getOldUsage($removed),
$this->getRemovedVersion($constant), $this->getRemovedVersion($removed),
$this->getReplacement($constant), $this->getReplacement($removed),
$this->getDocsUrl($constant), $this->getDocsUrl($removed),
] ]
); );
} }
@ -283,7 +283,7 @@ abstract class AbstractGenericUsage implements PhpCsSniff
/** /**
* Allow user to lookup the official docs related to this deprecation / breaking change. * Allow user to lookup the official docs related to this deprecation / breaking change.
* *
* @param array $config The converted structure for a single constant. * @param array $config
* *
* @return string * @return string
*/ */

View file

@ -0,0 +1,142 @@
<?php
/*
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
*
* 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;
/**
* Check usage of removed or breaking changed TypoScript.
*/
class Typo3Update_Sniffs_Removed_TypoScriptSniff extends AbstractGenericUsage
{
/**
* Register sniff only for TypoScript.
* @var array<string>
*/
public $supportedTokenizers = [
'TYPOSCRIPT',
];
/**
* Returns the token types that this sniff is interested in.
*
* @return array<int>
*/
public function register()
{
return [
TokenInterface::TYPE_OBJECT_CONSTRUCTOR,
TokenInterface::TYPE_OBJECT_IDENTIFIER,
];
}
/**
* Prepares structure from config for later usage.
*
* @param array $typo3Versions
* @return array
*/
protected function prepareStructure(array $typo3Versions)
{
$newStructure = [];
foreach ($typo3Versions as $typo3Version => $removals) {
foreach ($removals as $removed => $config) {
$config['type'] = TokenInterface::TYPE_OBJECT_IDENTIFIER;
// If starting with new, it's a constructor, meaning content object or other Object.
if (strtolower(substr($removed, 0, 4)) === 'new ') {
$config['type'] = TokenInterface::TYPE_OBJECT_CONSTRUCTOR;
$removed = substr($removed, 4);
}
$config['name'] = $removed;
$config['version_removed'] = $typo3Version;
$newStructure[$removed] = $config;
}
}
return $newStructure;
}
/**
* 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]) && $token['type'] === $this->configured[$objectIdentifier]['type']) {
$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<string>
*/
protected function getRemovedConfigFiles()
{
return Options::getRemovedTypoScriptConfigFiles();
}
}

View file

@ -0,0 +1,96 @@
{
"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.TypoScript.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.TypoScript.styles-insertContent",
"type": "WARNING"
},
{
"column": 1,
"fixable": false,
"line": 6,
"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.TypoScript.styles-insertContent",
"type": "WARNING"
},
{
"column": 1,
"fixable": false,
"line": 13,
"message": "Legacy calls are not allowed; found mod.web_list.alternateBgColors. Removed in 7.0. Removed without substitution. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-53658-RemoveAlternateBgColorsOption.html",
"severity": 5,
"source": "Typo3Update.Removed.TypoScript.mod-web_list-alternateBgColors",
"type": "WARNING"
},
{
"column": 10,
"fixable": false,
"line": 26,
"message": "Legacy calls are not allowed; found CLEARGIF. Removed in 7.1. Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html",
"severity": 5,
"source": "Typo3Update.Removed.TypoScript.CLEARGIF",
"type": "WARNING"
},
{
"column": 10,
"fixable": false,
"line": 27,
"message": "Legacy calls are not allowed; found COLUMNS. Removed in 7.1. Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html",
"severity": 5,
"source": "Typo3Update.Removed.TypoScript.COLUMNS",
"type": "WARNING"
},
{
"column": 10,
"fixable": false,
"line": 28,
"message": "Legacy calls are not allowed; found CTABLE. Removed in 7.1. Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html",
"severity": 5,
"source": "Typo3Update.Removed.TypoScript.CTABLE",
"type": "WARNING"
},
{
"column": 10,
"fixable": false,
"line": 29,
"message": "Legacy calls are not allowed; found OTABLE. Removed in 7.1. Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html",
"severity": 5,
"source": "Typo3Update.Removed.TypoScript.OTABLE",
"type": "WARNING"
},
{
"column": 10,
"fixable": false,
"line": 30,
"message": "Legacy calls are not allowed; found HRULER. Removed in 7.1. Any installation should migrate to alternatives such as FLUIDTEMPLATE to customize the output of the content. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.1/Breaking-64639-RemovedContentObjects.html",
"severity": 5,
"source": "Typo3Update.Removed.TypoScript.HRULER",
"type": "WARNING"
}
],
"warnings": 9
}
},
"totals": {
"errors": 0,
"fixable": 0,
"warnings": 9
}
}

View file

@ -0,0 +1,31 @@
page {
10 < styles.insertContent
10 =< styles.insertContent
}
styles.insertContent {
select {
where = colPos=1
}
}
# already covered
mod.web_list.alternateBgColors = 1
# Not covered yet
mod {
web_list {
alternateBgColors = 1
}
}
page {
CLEARGIF {
value = test
}
10 = CLEARGIF
11 = COLUMNS
12 = CTABLE
13 = OTABLE
14 = HRULER
}

View file

@ -114,6 +114,12 @@ class SniffsTest extends TestCase
*/ */
protected function executeSniff(\SplFileInfo $folder, array $arguments = []) protected function executeSniff(\SplFileInfo $folder, array $arguments = [])
{ {
$fileName = '';
if (isset($arguments['inputFileName'])) {
$fileName = $arguments['inputFileName'];
unset($arguments['inputFileName']);
}
$internalArguments = array_merge_recursive([ $internalArguments = array_merge_recursive([
'standard' => 'Typo3Update', 'standard' => 'Typo3Update',
'runtime-set' => [ 'runtime-set' => [
@ -123,14 +129,11 @@ class SniffsTest extends TestCase
], ],
'report' => 'json', 'report' => 'json',
'sniffs' => $this->getSniffByFolder($folder), 'sniffs' => $this->getSniffByFolder($folder),
'inputFile' => $folder->getRealPath() . DIRECTORY_SEPARATOR . 'InputFileForIssues.php', 'inputFile' => $this->getInputFile($folder, $fileName),
], $arguments); ], $arguments);
if (isset($internalArguments['inputFileName'])) { if (strpos($internalArguments['inputFile'], '.ts') !== false) {
$internalArguments['inputFile'] = $folder->getRealPath() $internalArguments['extensions'] = 'ts/TypoScript';
. DIRECTORY_SEPARATOR
. $internalArguments['inputFileName'];
unset($internalArguments['inputFileName']);
} }
$this->assertEquals( $this->assertEquals(
@ -227,6 +230,35 @@ class SniffsTest extends TestCase
return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Arguments.php'; return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Arguments.php';
} }
/**
* Get absolute file path to file to use for testing.
*
* @param \SplFileInfo $folder
* @param string $fileName
* @return string
*/
protected function getInputFile(\SplFileInfo $folder, $fileName = '')
{
$folderPath = $folder->getRealPath() . DIRECTORY_SEPARATOR;
$file = $folderPath . $fileName;
if (!is_file($file)) {
$file = $folderPath . $fileName;
}
if (!is_file($file)) {
$file = $folderPath . 'InputFileForIssues.php';
}
if (!is_file($file)) {
$file = $folderPath . 'InputFileForIssues.ts';
}
if (!is_file($file)) {
throw new \Exception('message', 1492083289);
}
return $file;
}
/** /**
* Build cli call for phpcs. * Build cli call for phpcs.
* *