FEATURE: Add first TypoScript sniff

* Add configuration for removed object identifiers.
* Add sniff for removed object identifiers.

Relates: #54
This commit is contained in:
Daniel Siepmann 2017-04-13 13:32:20 +02:00
parent e7dbac4d33
commit 7a999212e2
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 128 additions and 0 deletions

View file

@ -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'

View file

@ -0,0 +1,86 @@
<?php
use Helmich\TypoScriptParser\Tokenizer\TokenInterface;
use PHP_CodeSniffer_File as PhpCsFile;
use Typo3Update\Sniffs\Options;
use Typo3Update\Sniffs\Removed\AbstractGenericUsage;
class Typo3Update_Sniffs_Removed_TypoScriptObjectIdentifierSniff extends AbstractGenericUsage
{
public $supportedTokenizers = [
'TYPOSCRIPT',
];
/**
* Returns the token types that this sniff is interested in.
*
* @return array<int>
*/
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<string>
*/
protected function getRemovedConfigFiles()
{
return Options::getRemovedTypoScriptObjectIdentifierConfigFiles();
}
}

View file

@ -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
}
}

View file

@ -0,0 +1,4 @@
page {
10 < styles.insertContent
10 =< styles.insertContent
}