Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rector to autofix code smell #4045

Merged
merged 89 commits into from Sep 2, 2023
Merged

Use Rector to autofix code smell #4045

merged 89 commits into from Sep 2, 2023

Conversation

splitbrain
Copy link
Collaborator

@splitbrain splitbrain commented Aug 29, 2023

This adds a configuration for rector and a new github workflow to automatically apply it when new code is pushed to master. The code is then also autofixed by php codesniffer. The result is auto submitted as pull request.

This PR also applies the changes suggested by rector in batches (see commits). I looked at all the changes made to ensure they seem valid, removed offending rules where it didn't and also manually reformatted some of the output. The latter is needed because rector isn't very good with white spaces and array formatting.

Ideally this is merged quickly to avoid merge conflicts but also to get the changed code into other people's hands to see if anything broke that was not found by tests.

The ultimate goal is to provide this mechanism to plugin authors to automatically update their plugins to new DokuWiki and PHP standards.

  • change branch in github action
  • improve PR message in github action
  • apply all rector changes in batches and fine tune rector config
    • for inc/
    • for lib/
  • add custom rector config for renaming deprecated function calls/class names
  • maybe drop a couple more exceptions from our codesniffer setup and apply them as well
  • get rid of the remaining codesniffer rule excludes and apply them all - no sense in waiting

Post merge:

  • see if which deprecated stuff we can drop (form.php?)
  • investigate in a pre commit hook for running code sniffer on changed files

A workflow should automatically suggest a new pull request with the
changes.

Initial fixes will not be applied from the auto generated PR but will be
added as piece by piece commits with rule updates to this branch.
when using bootstrapping, these defines seem not to be auto detected
anymore. We probably have to add a few more once we start running on
plugins.
Seems rector was too aggressive here in removing a variable.
This broke tests. Ideally an Interface should be defined that both the
real APICore and the TestPlugin implement.
prevent rector from rewriting this into an auto-assignment.
inc/Cache/CacheParser.php Outdated Show resolved Hide resolved
@splitbrain
Copy link
Collaborator Author

Good news: all the code sniffer rules are now applied as well.

@Klap-in
Copy link
Collaborator

Klap-in commented Aug 31, 2023

Please double check my usage of $auth instanceof AuthPlugin that I did not swap the logic.

Copy link
Collaborator

@fiwswe fiwswe left a comment

Choose a reason for hiding this comment

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

Next batch of reviews…

I'll do lib/ next.

inc/parser/renderer.php Outdated Show resolved Hide resolved
inc/parser/xhtml.php Show resolved Hide resolved
inc/parser/xhtml.php Show resolved Hide resolved
inc/parser/xhtml.php Outdated Show resolved Hide resolved
inc/parser/xhtml.php Show resolved Hide resolved
inc/parser/xhtmlsummary.php Outdated Show resolved Hide resolved
inc/search.php Outdated Show resolved Hide resolved
inc/toolbar.php Show resolved Hide resolved
inc/toolbar.php Show resolved Hide resolved
install.php Show resolved Hide resolved
@splitbrain
Copy link
Collaborator Author

Okay, I think I'm through and addressed all comments. @Klap-in your auth instance changes look correct to me.

Unless someone objects, I would merge this later today. We can (and should) always do small improvements later.

@splitbrain splitbrain merged commit 5ff5424 into master Sep 2, 2023
11 of 12 checks passed
@splitbrain splitbrain deleted the autofix branch September 2, 2023 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants