[TikiWiki-commits] [Git][tikiwiki/tiki][master] 3 commits: [REF] Rector: Modernize the rector.php file
Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <693b427c4a78f_2a17f25083573@gitlab-sidekiq-low-urgency-cpu-bound-v2-797576f54b-s7mkq.mail> |
Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
a2925366 by Benoit Grégoire at 2025-12-11T15:41:28-05:00
[REF] Rector: Modernize the rector.php file
- - - - -
691613a7 by Benoit Grégoire at 2025-12-11T16:25:16-05:00
[REF] Rector: Update rules to apply CompleteDynamicPropertiesRector globally
- - - - -
ecf290bb by Benoit Grégoire at 2025-12-11T16:34:56-05:00
[ENH] Add rector to the CI pipeline. Pipeline will fail if rector would have modified any file
- - - - -
3 changed files:
- .gitlab-ci.yml
- lib/core/Tiki/Relation/SystemTrackerCreator.php
- rector.php
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -1,6 +1,6 @@
stages:
- build
- - lint
+ - code-quality
- tiki-check
- unit-tests
- package-tiki
@@ -113,12 +113,14 @@ node_build:
#
.cache-vendor_bundled: &cache-vendor_bundled
+ #I'm actually not sure this speeds up anything - benoitg - 2025-12-11
key:
prefix: "vendor_bundled"
files:
- vendor_bundled/composer.lock
paths:
- - vendor_bundled/vendor
+ - vendor_bundled/vendor/
+ - bin/
policy: pull
.cache-composercache: &cache-composercache
@@ -151,6 +153,7 @@ composer:
artifacts:
paths:
- vendor_bundled/vendor/
+ - bin/
expire_in: 2 days
composer-dbdiff:
@@ -180,11 +183,11 @@ composer-dbdiff:
#
-# Lint
+# Code quality: linting, coding standards, etc.
#
phpcs:
- stage: lint
+ stage: code-quality
needs:
- composer
image: ${DEPENDENCY_PROXY_PREFIX}${BASE_QA_IMAGE}
@@ -201,7 +204,7 @@ phpcs:
policy: pull-push
phplint:
- stage: lint
+ stage: code-quality
image: ${DEPENDENCY_PROXY_PREFIX}tikiwiki/tikiwiki-ci:${PHP_VERSION}-qa
needs:
- composer
@@ -216,7 +219,7 @@ phplint:
- PHP_VERSION: ['8.1', '8.2', '8.3', '8.4', '8.5']
smarty-lint:
- stage: lint
+ stage: code-quality
needs:
- composer
image: ${DEPENDENCY_PROXY_PREFIX}${BASE_QA_IMAGE}
@@ -224,7 +227,7 @@ smarty-lint:
- php vendor_bundled/vendor/umakantp/smartylint/smartyl -p --files=lib/test,templates,themes --rules=doc/devtools/smartyl.rules.xml
eslint:
- stage: lint
+ stage: code-quality
needs:
- node_modules
image:
@@ -234,7 +237,7 @@ eslint:
- npx eslint .
shlint:
- stage: lint
+ stage: code-quality
needs: []
image: koalaman/shellcheck-alpine:latest
script:
@@ -242,19 +245,43 @@ shlint:
- shellcheck ./doc/devtools/*.sh
check-bom-encoding:
- stage: lint
+ stage: code-quality
needs: []
image: ${DEPENDENCY_PROXY_PREFIX}${BASE_QA_IMAGE}
script:
- php doc/devtools/check_bom_encoding.php
unix-ending-line:
- stage: lint
+ stage: code-quality
needs: []
image: ${DEPENDENCY_PROXY_PREFIX}${BASE_QA_IMAGE}
script:
- php doc/devtools/check_unix_ending_line.php
+translation-standards:
+ stage: code-quality
+ needs:
+ - composer
+ image: ${DEPENDENCY_PROXY_PREFIX}${BASE_QA_IMAGE}
+ script:
+ - php doc/devtools/check_template_translation_standards.php --all
+
+rector:
+ stage: code-quality
+ needs:
+ - composer
+ image: ${DEPENDENCY_PROXY_PREFIX}${BASE_QA_IMAGE}
+ script:
+ # If rector would have changed any files, it will return a non-zero code
+ - php bin/rector process --dry-run
+ cache:
+ - key:
+ prefix: "rector"
+ files:
+ - rector.php
+ paths:
+ - temp/dev/rector_cache
+ policy: pull-push
#
# Check Tikiwiki development specific check (related also with release)
#
@@ -296,14 +323,6 @@ translation:
- git log --first-parent --pretty="format:%h" -1 --skip=1 | xargs -I gitHash php -d display_errors=On console.php translation:englishupdate --audit
allow_failure: true
-translation-standards:
- stage: tiki-check
- needs:
- - composer
- image: ${DEPENDENCY_PROXY_PREFIX}${BASE_QA_IMAGE}
- script:
- - php doc/devtools/check_template_translation_standards.php --all
-
#satis-validates:
# stage: tiki-check
# needs: []
=====================================
lib/core/Tiki/Relation/SystemTrackerCreator.php
=====================================
@@ -20,6 +20,7 @@ class SystemTrackerCreator
{
protected $trackerId;
protected $fieldIds;
+ private $trklib;
public function __construct()
{
=====================================
rector.php
=====================================
@@ -10,7 +10,7 @@ if (PHP_SAPI !== 'cli') {
To run rector (https://getrector.com/documentation) on a file or directory, run:
-php vendor_bundled/vendor/rector/rector/bin/rector process --memory-limit=4G --dry-run
+php bin/rector process --memory-limit=4G --dry-run
Obviously, always run --dry-run first.
@@ -25,11 +25,11 @@ If you apply something with rector, you commits should be something like:
For global commits (in this case the changes to rector.php would be commited):
-[REF] Rector: Update rules to apply SymfonyLevelSetList::UP_TO_SYMFONY_54 globally
+[REF] Rector: Update rules to apply SymfonyLevelSetList::UP_TO_SYMFONY_54 globally
One shot, or partial application (in which case your changes in rector.php should not be commited, or commited commented-out):
-[REF] Rector: Apply ReturnTypeFromStrictNativeCallRector::class to path lib/core
+[REF] Rector: Apply ReturnTypeFromStrictNativeCallRector::class to path lib/core
Articles to read:
@@ -37,16 +37,29 @@ Articles to read:
* https://symfonycasts.com/screencast/symfony6-upgrade/rector (about upgrading symfony)
*/
-use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
-use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
+
use Rector\Config\RectorConfig;
+use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Set\ValueObject\SetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Symfony\Set\SymfonySetList;
+use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector;
+use Rector\CodeQuality\Rector\ClassMethod\ReturnTypeFromStrictScalarReturnExprRector;
-return static function (RectorConfig $rectorConfig): void {
- //TO debug these paths, add --debug to your rector commands, and you will see every file processed.
- $rectorConfig->paths([
+return RectorConfig::configure()
+ ->withCache(
+ // ensure file system caching is used instead of in-memory
+ cacheClass: FileCacheStorage::class,
+ // specify a path that works locally as well as on CI job runners
+ cacheDirectory: __DIR__ . '/temp/dev/rector_cache'
+ )
+ //Because tiki uses vendor_bundled as it's main composer instead of the root, we have to do this manually. - benoitg - 2025-12-11
+ ->withBootstrapFiles([
+ __DIR__ . '/vendor_bundled/vendor/autoload.php',
+ ])
+
+ ->withPaths([
+ //TO debug these paths, add --debug to your rector commands, and you will see every file processed.
__DIR__ . '/' . ADMIN_PATH,
__DIR__ . '/' . TIKI_CONFIG_PATH,
__DIR__ . '/' . DEPRECATED_DEVTOOLS_PATH,
@@ -59,43 +72,60 @@ return static function (RectorConfig $rectorConfig): void {
__DIR__ . '/' . PERMISSIONCHECK_PATH,
__DIR__ . '/' . PROFILES_PATH,
__DIR__ . '/' . BASE_THEMES_SRC_PATH,
- ]);
- $rectorConfig->skip([
+
+ ])->withSkip([
// __DIR__ . '/src/SingleFile.php',
// __DIR__ . '/src/WholeDirectory',
// or use fnmatch
__DIR__ . '*/vendor/*',
- ]);
-
+ ])
/* Register sets of rules.
They are not documented in a single place in rector doc unfortunately.
Some can be found in
https://github.com/rectorphp/rector/blob/main/packages/Set/ValueObject/SetList.php
*/
- $rectorConfig->sets([
+ ->withSets([
+ //PHP version sets.
+
+ //Do NOT set higher than our lowest supported php version. This is only necessary because we dont use the standard composer.json at the root. Otherwise an withPhpSets() would take care of this for us.
+ //SetList::PHP_81
+
//Code quality sets we want to reach
- //SetList::TYPE_DECLARATION,
- //PHP version sets. do NOT set higher than our lowest supported php version
- //LevelSetList::UP_TO_PHP_81,
+ //SetList::TYPE_DECLARATION,
//PHPUnitSetList::PHPUNIT_100,
+
//Symfony upgrades
//Documentation: https://github.com/rectorphp/rector-symfony
//https://github.com/rectorphp/rector-symfony/tree/main/config/sets/symfony
//Applied globally SYMFONY_60 to SYMFONY_64 on 2023-05-05
//SymfonySetList::SYMFONY_64
- ]);
+ ])
/* Register individial rules.
Available rules for rector are found and documented here: https://getrector.com/documentation/rules-overview
*/
- $rectorConfig->rules([
- //Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector::class,
- //Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector::class,
- //ReturnTypeFromStrictNativeCallRector::class,
- //ReturnTypeFromStrictScalarReturnExprRector::class,
- ]);
-};
+
+ ->withRules(
+ [
+ // These rules had been completely applied in the past. They should be re-fixed and left uncommented - benoitg - 2025-12-11
+
+ //Please keep references to the rules you add in this file, use https://getrector.com/find-rule
+
+ //https://getrector.com/rule-detail/complete-dynamic-properties-rector
+ Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector::class,
+ //Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector::class,
+ //ReturnTypeFromStrictNativeCallRector::class,
+ //ReturnTypeFromStrictScalarReturnExprRector::class,
+ ]
+ )
+ ->withSkip(
+ [
+ //This is a spectacularly bad idea. There is a reason the PHP people made this a warning, hard casting will just cause additional bugs, and give the false impression someone actually thought about the implications - benoitg - 2025-12-11
+ Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector::class
+ ]
+ )
+;
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/compare/a7feef665d0bdc720c91be5cf1a9b4df12f00cbc...ecf290bb687e38110af3a5643f3bf3ffcae48c77
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/compare/a7feef665d0bdc720c91be5cf1a9b4df12f00cbc...ecf290bb687e38110af3a5643f3bf3ffcae48c77
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs