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

Review: Add validator spec via code generation #100 #221

Merged
merged 19 commits into from
Jun 10, 2021

Conversation

westonruter
Copy link
Member

Follow-up on #100.

@schlessera schlessera added Tech Debt Deprecations, inefficiencies, code health Validator labels Jun 6, 2021
@schlessera
Copy link
Collaborator

Regarding the TODOs for "class/method not found", these are caused by the lack of support for class maps in PhpStorm. The Nette PHP Generator package uses a class map as an autoloader, and PhpStorm doesn't include that in its index.

This would be solvable by either generating a complex '.phpstorm.meta.php' file or by generating a stubs file to add to the autoloader, but I'm not sure it is worth the effort.

As the TODOs caused PHPCS failures due to their length, I've removed those for now.

@schlessera
Copy link
Collaborator

As a side-effect of solving one of the code insight TODOs, this PR has now added magic getters for all types of entries, and all of them now include a class doc-block with all relevant properties.

@schlessera
Copy link
Collaborator

@westonruter I adapted to code and resolved all of your TODOs except for the three that relate to the handling of latest extension versions. I have created a new issue for these, so that we can merge this PR now: #232

@schlessera schlessera marked this pull request as ready for review June 6, 2021 17:06
@@ -126,7 +126,7 @@ interface Tag
const NEXTID = 'nextid';
const NOBR = 'nobr';
const NOSCRIPT = 'noscript';
const O_P = 'o:p';
const O_P = 'o:p'; // @todo Will this be usable at present given PHP DOM?
Copy link
Member Author

Choose a reason for hiding this comment

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

Thoughts on this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd leave this TODO in for now. I haven't tested this yet, and I'm also not sure we'll even encounter that in the WP plugin anywhere.

Comment on lines -30 to +42
SpecRule::MANDATORY_ONEOF => '[\'amp-nested-submenu-close\', \'amp-nested-submenu-open\']',
SpecRule::MANDATORY_ONEOF => [
Attribute::AMP_NESTED_SUBMENU_CLOSE,
Attribute::AMP_NESTED_SUBMENU_OPEN,
],
Copy link
Member Author

Choose a reason for hiding this comment

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

😍

SpecRule::NAME => Attribute::HREF,
Attribute::ASYNC => [],
Attribute::CROSSORIGIN => [],
Attribute::HREF => [
SpecRule::MANDATORY => true,
SpecRule::VALUE_REGEX => 'https://cdn\.materialdesignicons\.com/([0-9]+\.?)+/css/materialdesignicons\.min\.css|https://cloud\.typography\.com/[0-9]*/[0-9]*/css/fonts\.css|https://fast\.fonts\.net/.*|https://fonts\.googleapis\.com/css2?\?.*|https://fonts\.googleapis\.com/icon\?.*|https://fonts\.googleapis\.com/earlyaccess/.*\.css|https://maxcdn\.bootstrapcdn\.com/font-awesome/([0-9]+\.?)+/css/font-awesome\.min\.css(\?.*)?|https://(use|pro|kit)\.fontawesome\.com/releases/v([0-9]+\.?)+/css/[0-9a-zA-Z-]+\.css|https://(use|pro|kit)\.fontawesome\.com/[0-9a-zA-Z-]+\.css|https://use\.typekit\.net/[\w\p{L}\p{N}_]+\.css',
Copy link
Member Author

Choose a reason for hiding this comment

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

Since this regex will be sent to preg_match(), we should escape the '/' delimiter. See ampproject/amp-wp@afd1172

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't escape this against a random delimiter.
I would suggest using the chr(0) delimiter in the plugin if you want to avoid preg_quote().

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm merging this now to get rid of another huge PR, but we can discuss this particular issue separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. I wasn't aware you could use a NUL as a delimiter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems you can't:

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I've opened this as #238.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, sorry, I've remembered incorrectly, it was chr(1) that we have been using in WP-CLI, not chr(0). The chr(1) character is the "start of header" (SOH) character, intended to control the flow of streams, and shouldn't be in use or cause conflicts in HTML.

This delimiter has been used as the default delimiter in the WP-CLI search-replace command when you provide a regex via the CLI, and as far as I know, it has never caused any issues.

=> https://3v4l.org/piT1j
Online PHP editor _ output for piT1j - Google Chrome 2021-06-14 at 7 51 44 AM

Copy link
Member Author

Choose a reason for hiding this comment

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

Excellent. Sounds good to me.

Co-authored-by: Weston Ruter <westonruter@google.com>
Co-authored-by: Weston Ruter <westonruter@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tech Debt Deprecations, inefficiencies, code health Validator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants