Page MenuHomePhabricator

Auto-fix errors in pushed changesets where possible
Closed, DeclinedPublic

Description

https://integration.wikimedia.org/ci/job/wmf-quibble-vendor-mysql-hhvm-docker/2060/console

12:05:33 FILE: ...ce/src/extensions/GeoData/includes/CoordinatesParserFunction.php
12:05:33 ----------------------------------------------------------------------
12:05:33 FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
12:05:33 ----------------------------------------------------------------------
12:05:33  5 | WARNING | [x] Unused use statement
12:05:33    |         |     (MediaWiki.Classes.UnusedUseStatement.UnusedUse)
12:05:33 ----------------------------------------------------------------------
12:05:33 PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
12:05:33 ----------------------------------------------------------------------

Hey, so why don't you?! It's aggravating to have to go through the whole rigmarole of submitting a new changeset just to fix these simple things. Obviously there are many types of issues that it would be risky to fix automatically, but things like "unused use statement" seem very safe. If it's a somewhat trickier type of change, or maybe for all changes, maybe we could have a button to push that approves the diff and automatically supplies a new changeset.

Event Timeline

Legoktm subscribed.

maybe we could have a button to push that approves the diff and automatically supplies a new changeset

I like that idea. Some sniffs are pretty reliable for auto fixing, but others are still a bit buggy and need manual review.

Meanwhile, we can also improve the documentation and workflows for doing it locally. In theory, it should be as simple as composer run fix in the project directory, then stage the changes and commit it back to Gerrit.

The below would be the complete steps, including the normal steps for working with Gerrit in general (not specific to auto-fixing):

$ cd some-gerrit-project/ # eg. mediawiki-core/
$ git checkout my-branch # or git-review -d 1234, when amending someone else's change

$ composer install
$ composer run fix

$ git add -p && git commit --amend # stage and commit changes
$ git review -R # send back to Gerrit

Just composer fix :) With MediaWiki core though it takes a decent amount of time (5-6 minutes for me) to run over everything, so you should run it only on files that you've touched. Maybe we can provide a good git hook for this as well?

Cant you pass a list of files to composer fix / phpcbf ? I do that in core for composer test to greatly speed up the linting duration.

Use:
composer lint
composer fix

And pass them the list of files you are touching.