Skip to content

Conversation

@carlos-granados
Copy link
Contributor

@carlos-granados carlos-granados commented Jun 20, 2025

Updates the Rector settings to apply the whole set of Rector code quality rules. Most of these rules do not produce changes in our code. For those rules that produce changes I have created one commit per rule to make this easier to review. Once this is fully reviewed, I will modify the last commit to include the git blame ignores for all these commits, please do not merge until this is done

@carlos-granados carlos-granados requested a review from acoulton June 20, 2025 12:00
Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlos-granados thanks for this - generally speaking all looks good with a few small comments.

IMO as this is changing actual code rather than just style / formatting, we should not ignore these changes from git blame. I am pretty sure these are safe, but I think it's a good convention that all functional code changes are blame-able.

Instead I would just squash merge this once complete (so the blame doesn't include intermediate changes where files have been modified by more than one rule).

Comment on lines 160 to 165
return array_reduce($transformations, function ($acc, $t) {
return [
$t instanceof SimpleArgumentTransformation ? array_merge($acc[0], [$t]) : $acc[0],
!$t instanceof SimpleArgumentTransformation ? array_merge($acc[1], [$t]) : $acc[1],
$t instanceof SimpleArgumentTransformation ? $acc[1] : array_merge($acc[1], [$t]),
];
}, [[], []]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This existing logic took a bit of figuring out! It would probably be easier to follow as a pair of simple array_filters (and if the array_reduce was originally a performance concern I'm not sure the repeated array_merge makes it any better).

But I agree this change is correct for the existing implementation.

])
->withRootFiles()
->withCodeQualityLevel(0)
->withPreparedSets(codeQuality: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we at risk of CI breaking unexpectedly if Rector add new rules to the pre-defined "codeQuality" set that we have not yet adopted? We are only pinned to ^2.0, so every CI build will run with whatever happens to be the latest 2.x release of Rector at the time. I'm not sure their versioning strategy for changes to the config / implementation of rules?

We should perhaps be explicit about the rules - or alternatively require an explicit Rector version in composer.json and have a job (dependabot or a custom one like we have in behat/gherkin for the gherkin dependency) to update to each new Rector version as a standalone PR so that we can deal with any issues that arise without affecting other branches?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to be explicit about the rules, because there are a lot to be listed, so instead what I have done is to pin the explicit version of Rector that we are requiring. Since this tool is only used internally for Behat development, we can keep updating the required version when we add more Rector rules

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good solution.

Probably still worth having dependabot bump it so it doesn't fall too far behind (which could theoretically start holding back other dependencies in CI) but we can tackle that separately.

@carlos-granados
Copy link
Contributor Author

@acoulton sorry I took so long to get back to this. Summer is complicated here, hoping to get back to speed in September 😄

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks @carlos-granados - and no worries, summer is busy here too 😁

@carlos-granados carlos-granados marked this pull request as ready for review August 19, 2025 18:07
@carlos-granados carlos-granados merged commit bf6553e into Behat:master Aug 19, 2025
19 checks passed
@carlos-granados carlos-granados deleted the rector-code-quality branch August 19, 2025 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants