-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Implement a lint rule that ensures that functions/classes with no "gutenberg_" prefix are properly guarded #44151
Comments
I'm working on implementing this rule. |
I'm looking for feedback before implementing the solution for this issue. Let me briefly summarize it: Does writing a new phpcs sniff that checks whether the functions/classes are properly guarded seem valid to you? @adamziel, I know you've worked on a script that checks prefixes in Gutenberg functions. |
@anton-vlasenko thanks for the ping!
The linter rule is a great idea which would save everyone a ton of headache! It also makes me think – can we find 3 or 4 last instances of this problem to learn if any other measures would help here? For example, do we need any other linter rules other than one checking for the
That ended up being just an idea, I've never gotten around to building a script :-( I only built some automations for releasing new WordPress versions, which now makes me think – wouldn't it be great if the release leads knew away about the naming conflicts the moment they're introduced? I'm thinking about some kind of smoke automated test to install the latest Gutenberg plugin and visit a few most important pages, perhaps even in the CI for PRs somehow marked as core merge. Also cc @gziolo |
I haven't forgotten about this issue. But I apologise it took me so long to reply, @adamziel.
I believe that the e2e tests should have failed in that situation. The problem is that such issues can remain unnoticed for a long time, which could cause many websites to go down. This can happen because a function or class with a conflicting name might be backported to Core unbeknownst to the Gutenberg CI jobs. Consequently, Gutenberg CI jobs will not provide advance warnings to developers. So, in my opinion, this should be prevented in advance with the help of a PHPCS sniff that would enforce
Thank you! |
A separate repo would do it! The price to pay would be a new chore to update it periodically. I like the namespace suggestion in the discussion under your PR, though, maybe that’s all we need? Is there a sniff to require using a namespace in all files? |
Thank you for the reply, @adamziel. I agree with that.
Namespaces might work. I've submitted a PR that adds such a sniff (and added you as a reviewer). |
FWIW, there's a Trac ticket for this in Core: https://core.trac.wordpress.org/ticket/56794 😊 |
BTW to name one specific scenario: Dynamic block code (in Since the dynamic block code is actually copied over to Core from the Here's an example of the above scenario: #51989 |
What problem does this address?
Currently, it's possible to define a PHP function (class) with any prefix.
This repeatedly resulted in fatal errors due to duplicate function names between Core and Gutenberg.
What is your proposed solution?
A new lint rule should be implemented.
It should check that PHP functions/classes with no
(G|g)utenberg_
prefix are properly guarded withfunction_exists()
orclass_exists()
.The text was updated successfully, but these errors were encountered: