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

Improve validation error listing with more context and links to file editors #3505

Merged
merged 27 commits into from
Oct 18, 2019

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Oct 15, 2019

Summary

Part of #2316, redesigning the compatibility tool.

  • Include callback file name and line 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 (via amp_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 a amp_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. ✨
  • Include hook 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.
  • Add an information section to provide context for JS, CSS, and HTML error types.
  • Eliminate use of pretty-printed JSON for displaying the sources, in favor of tables.
  • Add special case for widgets so subclassed WP_Widget::widget method is used as opposed to WP_Widget::display_callback.
  • Improve styling, including zebra striping for new validation error rows (two shades of red).
  • Swap order of Error Type and Status columns.
  • Rename “Details” column to “Context”.
  • Disambiguates “handle” to indicate whether a handle is for a script or a style.
  • Incorporate actual plugin and theme names in source information, in addition to slugs. Also include icons.
  • Use translatable strings for labels in sources, rather than just keys.

Before

validated-url-screen-before

After

wordpressdev lndo site_core-dev_src_wp-admin_post php_post=3782 action=edit (6)

Informational Messages

JavaScript Error Type

image

CSS Error Type

image

HTML Error Type

image

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@googlebot googlebot added the cla: yes Signed the Google CLA label Oct 15, 2019
@westonruter westonruter added this to the v1.3.1 milestone Oct 17, 2019
@westonruter westonruter marked this pull request as ready for review October 17, 2019 05:22
@westonruter westonruter changed the title Improve validation sourcing with more context and links to file editors Improve validation error listing with more context and links to file editors Oct 17, 2019
@swissspidy swissspidy self-requested a review October 17, 2019 10:18
@swissspidy swissspidy modified the milestones: v1.3.1, v1.4 Oct 17, 2019
@kmyram kmyram added the P0 High priority label Oct 17, 2019
Copy link
Contributor

@pierlon pierlon left a 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.

assets/css/src/amp-validation-error-taxonomy.css Outdated Show resolved Hide resolved
…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)
  ...
@westonruter
Copy link
Member Author

The presentation of the sources is much improved yet further with actual labels and theme/plugin names:

image

image

@westonruter
Copy link
Member Author

Also, now the handle indicates whether it is a Script handle or a Style handle. Previously it was just “handle”, leaving you to figure out from context.

image

Copy link
Collaborator

@schlessera schlessera left a 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' ),
Copy link
Collaborator

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

Copy link
Member Author

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?

Copy link
Collaborator

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' ),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Markup in translation.

Copy link
Member Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

😨

Copy link
Member Author

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.

Copy link
Member

@amedina amedina left a 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.

@westonruter
Copy link
Member Author

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.

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! 😉)

@westonruter westonruter merged commit a50ed15 into develop Oct 18, 2019
@westonruter westonruter deleted the improve/validation-sourcing branch October 18, 2019 22:17
westonruter added a commit that referenced this pull request Nov 10, 2019
westonruter added a commit that referenced this pull request Nov 10, 2019
westonruter added a commit to GoogleChromeLabs/wp-origination that referenced this pull request Nov 10, 2019
westonruter added a commit that referenced this pull request Nov 11, 2019
)

* Remove dead code after #3505

* Fix matching file paths for child themes
westonruter added a commit that referenced this pull request Nov 11, 2019
)

* Remove dead code after #3505

* Fix matching file paths for child themes
brennensmith75 added a commit to brennensmith75/WP-Origination that referenced this pull request Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA P0 High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants