Page MenuHomePhabricator

Encourage void for non-abortable MW hook functions
Open, Needs TriagePublic


Follow-up from

This is fairly common pattern. While it's hard to statically detect this scenario with absolute certainty, perhaps we can develop something simple with no realistic false positive and yet still catch more of the problem.

The objective being that we flag any definitions hook functions that are known to be non-abortable and disallow use of @return bool or @return true in their doc comment, and disallow return true; in their function bodies.

In terms of heuristics, I'm not sure what the best approach will me. Maybe something as basic as static on* functions in *Hooks class, where the function name is compared against a list of known non-abortable hooks (the same way we do for discouraged/deprecated functions etc.).

Or perhaps instead of a stateless heuristic, we could read extension.json which get us wider range of possible ways to define hooks in favour of something a little less neat code-wise?

Event Timeline

Maybe phan can do the work better (In my opinion phan can do things with many files involved or dependenies between files, codesniffer is better when only check one file)

It can read the hooks from Hooks::runWithoutAbort calls in core and extensions while parsing the files.
Than reading extension.json of the extension working on and try to find the hook handlers there.