mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-22 00:16:12 +01:00

[FEATURE] Add Rector (#1031)

This part of #851.

In later parts, we'll add a Rector wrapper to `runTests.sh` and a CI job, and apply possible changes suggested by Rector.

Part of #851
Closes #125
This commit is contained in:
Eike Starkmann 2024-05-07 16:49:48 +02:00 committed by GitHub
parent 4ee0848039
commit ff4f7e3d0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 108 additions and 1 deletions

3
.gitattributes vendored
View file

@ -1,7 +1,6 @@
/.Build/ export-ignore /.Build/ export-ignore
/.editorconfig export-ignore /.editorconfig export-ignore
/.eslintignore export-ignore /.eslintignore export-ignore
/eslint.config.json export-ignore
/.gitattributes export-ignore /.gitattributes export-ignore
/.github/ export-ignore /.github/ export-ignore
/.gitignore export-ignore /.gitignore export-ignore
@ -13,10 +12,12 @@
/Configuration/FunctionalTests.xml export-ignore /Configuration/FunctionalTests.xml export-ignore
/Configuration/UnitTests.xml export-ignore /Configuration/UnitTests.xml export-ignore
/Tests/ export-ignore /Tests/ export-ignore
/eslint.config.json export-ignore
/package.json export-ignore /package.json export-ignore
/phive.xml export-ignore /phive.xml export-ignore
/phpcs.xml export-ignore /phpcs.xml export-ignore
/phpstan-baseline.neon export-ignore /phpstan-baseline.neon export-ignore
/phpstan.neon export-ignore /phpstan.neon export-ignore
/rector.php export-ignore
/stylelint.config.js export-ignore /stylelint.config.js export-ignore
/tools/ export-ignore binary /tools/ export-ignore binary

View file

@ -60,6 +60,8 @@
"seld/jsonlint": "^1.10.2", "seld/jsonlint": "^1.10.2",
"spaze/phpstan-disallowed-calls": "^3.3", "spaze/phpstan-disallowed-calls": "^3.3",
"squizlabs/php_codesniffer": "^3.9.2", "squizlabs/php_codesniffer": "^3.9.2",
"ssch/typo3-rector": "^2.5.0",
"ssch/typo3-rector-testing-framework": "^2.0.1",
"symfony/console": "^5.4 || ^6.4 || ^7.0", "symfony/console": "^5.4 || ^6.4 || ^7.0",
"symfony/translation": "^5.4 || ^6.4 || ^7.0", "symfony/translation": "^5.4 || ^6.4 || ^7.0",
"symfony/yaml": "^5.4 || ^6.4 || ^7.0", "symfony/yaml": "^5.4 || ^6.4 || ^7.0",
@ -195,6 +197,7 @@
"rm phpcs.xml", "rm phpcs.xml",
"rm phpstan-baseline.neon", "rm phpstan-baseline.neon",
"rm phpstan.neon", "rm phpstan.neon",
"rm rector.php",
"rm stylelint.config.js" "rm stylelint.config.js"
] ]
}, },

103
rector.php Normal file
View file

@ -0,0 +1,103 @@
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector;
use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Rector\ValueObject\PhpVersion;
use Ssch\TYPO3Rector\CodeQuality\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Ssch\TYPO3Rector\CodeQuality\General\ExtEmConfRector;
use Ssch\TYPO3Rector\Configuration\Typo3Option;
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;
use Ssch\TYPO3Rector\Set\Typo3SetList;
use Ssch\Typo3RectorTestingFramework\Set\TYPO3TestingFrameworkSetList;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/Classes/',
__DIR__ . '/Configuration/',
__DIR__ . '/Tests/',
__DIR__ . '/ext_emconf.php',
__DIR__ . '/ext_localconf.php',
])
->withPhpVersion(PhpVersion::PHP_74)
->withPhpSets(
true
)
// Note: We're only enabling a single set by default to improve performance. (Rector needs at least a single set to
// run.)
//
// You can temporarily enable more sets as needed.
->withSets([
// Rector sets
// LevelSetList::UP_TO_PHP_53,
// LevelSetList::UP_TO_PHP_54,
// LevelSetList::UP_TO_PHP_55,
// LevelSetList::UP_TO_PHP_56,
// LevelSetList::UP_TO_PHP_70,
// LevelSetList::UP_TO_PHP_71,
// LevelSetList::UP_TO_PHP_72,
// LevelSetList::UP_TO_PHP_73,
// LevelSetList::UP_TO_PHP_74,
// LevelSetList::UP_TO_PHP_80,
// LevelSetList::UP_TO_PHP_81,
// LevelSetList::UP_TO_PHP_82,
// LevelSetList::UP_TO_PHP_83,
// SetList::CODE_QUALITY,
// SetList::CODING_STYLE,
// SetList::DEAD_CODE,
// SetList::EARLY_RETURN,
// SetList::INSTANCEOF,
// SetList::NAMING,
// SetList::PRIVATIZATION,
// SetList::STRICT_BOOLEANS,
// SetList::TYPE_DECLARATION,
// PHPUnit sets
// PHPUnitSetList::PHPUNIT80_DMS,
// PHPUnitSetList::PHPUNIT_40,
// PHPUnitSetList::PHPUNIT_50,
// PHPUnitSetList::PHPUNIT_60,
// PHPUnitSetList::PHPUNIT_70,
// PHPUnitSetList::PHPUNIT_80,
// PHPUnitSetList::PHPUNIT_90,
// PHPUnitSetList::PHPUNIT_100,
// PHPUnitSetList::PHPUNIT_CODE_QUALITY,
// TYPO3 Sets
// https://github.com/sabbelasichon/typo3-rector/blob/main/src/Set/Typo3LevelSetList.php
// https://github.com/sabbelasichon/typo3-rector/blob/main/src/Set/Typo3SetList.php
Typo3SetList::CODE_QUALITY,
Typo3SetList::GENERAL,
Typo3LevelSetList::UP_TO_TYPO3_11,
// Typo3LevelSetList::UP_TO_TYPO3_12,
// TYPO3TestingFrameworkSetList::TYPO3_TESTING_FRAMEWORK_7,
])
// To have a better analysis from PHPStan, we teach it here some more things
->withPHPStanConfigs([
Typo3Option::PHPSTAN_FOR_RECTOR_PATH,
])
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
ConvertImplicitVariablesToExplicitGlobalsRector::class,
])
->withImportNames(true, true, false)
->withConfiguredRule(ExtEmConfRector::class, [
ExtEmConfRector::PHP_VERSION_CONSTRAINT => '7.4.0-8.3.99',
ExtEmConfRector::TYPO3_VERSION_CONSTRAINT => '11.5.4-12.4.99',
ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => [],
])
->withSkip([
]);