-
Notifications
You must be signed in to change notification settings - Fork 381
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
Improve validation error listing with more context and links to file editors #3505
Conversation
Also fix VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable and keyboard typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps don't show the colon (:
) if there's no value for the attribute.
…alidation-sourcing * 'develop' of github.com:ampproject/amp-wp: (57 commits) Undo over-eager rename of auto_accept_sanitization Rename auto-accept to accept-by-default Rename filter to amp_validation_error_auto_sanitized Fix jumping blocks when changing fonts (#3529) Update dependency browserslist to v4.7.1 (#3551) Make sure that isPageBlock always returns boolean. Fix and improve e2e tests. Remove unnessary check for block. Use shift over access first element of array. Use isPageBlock for cleaner code. Fix minor grammar issues Add docblock for `amp_is_sanitization_auto_accepted` filter Align arrows Update tests to use filter to set sanitization auto acceptance Make AMP_Validation_Manage::is_sanitization_auto_accepted() filterable Remove 'auto_accept_sanitization' option Remove relevant auto-sanitization notices Remove validation handling setting field Add special-case handling for layout=fill when both dimensions are 100% Insert duplicated page as current page. Ensure smooth snap line display (#3514) ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code that renders the pages is a wild mixture of markup and logic, which could really use a refactor, as it is very hard to read through.
I understand we're under time pressure here, but we should mark this as a priority under tech debt at one point.
echo wp_kses_post( | ||
sprintf( | ||
/* translators: 1: script, 2: Documentation URL, 3: Documentation URL, 4: Documentation URL, 5: onclick, 6: Documentation URL, 7: amp-bind, 8: Documentation URL, 9: amp-script */ | ||
__( 'Arbitrary JavaScript is not allowed in AMP. You cannot use JS %1$s tags unless they are for loading <a href="%2$s">AMP components</a> (which the AMP plugin will add for you automatically). In order for a page to be served as AMP, the invalid JS code must be removed from the page, which is what happens when you <strong>accept</strong> sanitization. Learn more about <a href="%3$s">how AMP works</a>. As an alternative to using custom JS, please consider using a pre-built AMP functionality, including <a href="%4$s">actions and events</a> (as opposed to JS event handler attributes like %5$s) and the <a href="%6$s">%7$s</a> component; you may also add custom JS if encapsulated in the <a href="%8$s">%9$s</a>.', 'amp' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the translatable strings shouldn't contain markup. Here's some sample code of how I normally deal with links in translatable strings: https://gist.github.com/schlessera/18770dc8d4641dbe9c76
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swissspidy Since this is your handiwork, would you please respond next week?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with all the translatable strings in the plugin, we're following core's lead and recommendations. Wherever possible we avoid unnecessary or unusual HTML markup. <a>
and <strong>
tags are quite common in any UI copy, and translators are used to seeing those in strings. translate.wordpress.org even has special handling for them.
While https://gist.github.com/schlessera/18770dc8d4641dbe9c76 looks interesting, it is not a format translators are familiar with.
echo wp_kses_post( | ||
sprintf( | ||
/* translators: 1: Documentation URL, 2: Documentation URL. */ | ||
__( 'AMP has specific set of allowed elements and attributes that are allowed in valid AMP pages. Learn about the <a href="%1$s">AMP HTML specification</a>. If an element or attribute is not allowed in AMP, it must be removed for the page to <a href="%2$s">cached and be eligible for prerendering</a>.', 'amp' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markup in translation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Via dfd87bb. @swissspidy Please comment.
@@ -1265,6 +1265,16 @@ public static function wrap_hook_callbacks( $hook ) { | |||
continue; | |||
} | |||
|
|||
// Skip considering ourselves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only because this logic only runs exclusively during validation, so it's not relevant to validation errors being reported on the frontend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The structural and copy changes are very good. Huge improvement on UX from a dev perspective.
Agreed 100%. This refactoring of the compatibility tool's codebase needs to be done as part of the 2.0 effort. With redesigning the compatibility tool (#2316) we can have a modern JS-driven UI that doesn't intermix all of the markup and PHP logic together (we can instead intermix markp and JS logic! 😉) |
) * Remove dead code after #3505 * Fix matching file paths for child themes
) * Remove dead code after #3505 * Fix matching file paths for child themes
Summary
Part of #2316, redesigning the compatibility tool.
file
name andline
number in source information, with links to the plugin/theme editor and scrolling to the specific line where the function is defined. The URL to open the file in an editor can be filtered (viaamp_validation_error_source_file_editor_url_template
) to allow a site to request the user's IDE to edit the file, including the use of aamp_validation_error_source_file_path
filter to map the file path from a container/VM to the host machine. See example plugin for IntelliJ IDEA for a site running on Lando. ✨priority
in source information. This is important for writing child themes and extension plugins to override the behavior, as the overriding logic must run at a later priority. Having the hook name alone is not enough.WP_Widget::widget
method is used as opposed toWP_Widget::display_callback
.Before
After
Informational Messages
JavaScript Error Type
CSS Error Type
HTML Error Type
Checklist