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
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
41d99af
Include hook priority in source information
westonruter Oct 15, 2019
977ecd4
Include relative file name and line number in source information
westonruter Oct 15, 2019
fb8c82c
Add special case for sourcing WP_Widget::display_callback
westonruter Oct 16, 2019
4e0993a
Refactor test_decorate_shortcode_and_filter_source
westonruter Oct 16, 2019
e317de2
Improve display of validation error details, including informational …
westonruter Oct 16, 2019
8e77f91
Remove confusing brackets from attributes; remove redundant @
westonruter Oct 16, 2019
02231bf
Remove obsolete references to removed_unused_css_rules error code; se…
westonruter Oct 16, 2019
db22e7e
Fix identifng file for single-file plugins
westonruter Oct 17, 2019
49d1dad
Improve displaying source information, including links to theme/plugi…
westonruter Oct 17, 2019
0f0ebcf
Jump to the requested line when opening the file editor
westonruter Oct 17, 2019
b99ba62
Fix CSS linting errors
westonruter Oct 17, 2019
98bba39
Ignore WordPress.Security.NonceVerification.Recommended
westonruter Oct 17, 2019
04c2f40
Skip including AMP_Validation_Manager::add_block_source_comments in s…
westonruter Oct 17, 2019
2e99772
Improve presentation of boolean attributes
westonruter Oct 17, 2019
dfd87bb
Improve translatability of strings
westonruter Oct 17, 2019
499d279
Eliminate square brackets for attributes in favor of angle brackets f…
westonruter Oct 17, 2019
1c89197
Merge branch 'develop' of github.com:ampproject/amp-wp into improve/v…
westonruter Oct 18, 2019
82a87a6
Fix phpcs linting issues
westonruter Oct 18, 2019
5b77a64
Swap status column with error type column; rename Details to Context
westonruter Oct 18, 2019
dcb00f7
Allow validation error source file edit link to be filtered
westonruter Oct 18, 2019
b4779da
Prevent status dropdown from wrapping after status icon
westonruter Oct 18, 2019
7ff9fd7
Fix phpcs complaints regarding indentation
westonruter Oct 18, 2019
e6cbc52
Introduce file editor URL template and filter for mapping to host mac…
westonruter Oct 18, 2019
413d41b
Improve display of source information with icons and translated strings
westonruter Oct 18, 2019
96590da
Keep track of whether a handle is a script or a style
westonruter Oct 18, 2019
3a6bfe6
Prepare CSS informational message for translation
westonruter Oct 18, 2019
1b1e1dc
Prevent duplicating char findiing; add parens; fix scheme check
westonruter Oct 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion assets/css/src/amp-validation-error-taxonomy.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,38 @@ details.single-error-detail[open] .single-error-detail-summary::after {

.notice .detailed details .detailed {
padding-left: 32px;
font-family: Consolas, Monaco, monospace;
}

dl.detailed dt {
font-weight: bold;
margin-bottom: 0.5em;
}

dl.detailed dd + dt {
margin-top: 1em;
}

dl.detailed .element-attributes th {
font-weight: bold;
text-align: right;
}

dl.detailed .element-attributes th.has-attr-value::after {
content: ":";
}

dl.detailed .element-attributes th,
dl.detailed .element-attributes td {
padding: 2px;
vertical-align: top;
}

dl.detailed a {
text-decoration: underline;
}

dl.detailed {
padding-bottom: 16px;
}

.details-attributes__title code,
Expand Down Expand Up @@ -222,6 +253,14 @@ body.post-type-amp_validated_url .wp-list-table .new td {
background-color: #fef7f1;
}

body.taxonomy-amp_validation_error .wp-list-table .new.odd th,
body.taxonomy-amp_validation_error .wp-list-table .new.odd td,
tr.expanded.new.odd + tr > td:first-of-type,
body.post-type-amp_validated_url .wp-list-table .new.odd th,
body.post-type-amp_validated_url .wp-list-table .new.odd td {
background-color: #f9eee5;
}

body.taxonomy-amp_validation_error .wp-list-table .new th.check-column,
tr.expanded.new + tr > td:first-of-type,
body.post-type-amp_validated_url .wp-list-table .new th.check-column {
Expand Down Expand Up @@ -296,3 +335,24 @@ body.taxonomy-amp_validation_error .wp-list-table .new th.check-column input {
cursor: pointer;
text-decoration: underline;
}

.validation-error-sources th {
font-weight: bold;
text-align: right;
}

.validation-error-sources td,
.validation-error-sources th {
vertical-align: top;
padding: 0 4px;
}

.validation-error-sources > li {
border-top: solid 1px #ddd;
margin: 0;
padding: 6px 0;
}

.validation-error-sources > li:first-child {
border-top: 0;
}
12 changes: 1 addition & 11 deletions assets/css/src/amp-validation-single-error-url.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,9 @@ table.striped > tbody > tr.even {
cursor: pointer;
}

.details ul.detailed {
padding: 0 32px;
margin-top: 0;
}

.details div.detailed {
.details dl.detailed {
padding-left: 30px;
margin-top: 10px;
font-family: Consolas, Monaco, monospace;
}

.details .detailed details {
padding-bottom: 16px;
}

.details .detailed summary code {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const handleSearching = () => {
const detailsQuery = document.querySelectorAll( 'tbody .column-details' );

/*
* Iterate through the 'Details' column of each row.
* Iterate through the 'Context' (formerly 'Details') column of each row.
* If the search query is not present, hide the row.
*/
let numberErrorsDisplaying = 0;
Expand Down
3 changes: 1 addition & 2 deletions includes/sanitizers/class-amp-core-theme-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,7 @@ public static function get_supported_themes() {
public static function get_acceptable_errors( $template ) {
if ( isset( self::$theme_features[ $template ] ) ) {
return [
'removed_unused_css_rules' => true,
'illegal_css_at_rule' => [
'illegal_css_at_rule' => [
[
'at_rule' => 'viewport',
],
Expand Down
49 changes: 21 additions & 28 deletions includes/validation/class-amp-validated-url-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,30 +934,30 @@ public static function add_single_post_columns() {
return [
'cb' => '<input type="checkbox" />',
'error' => __( 'Error', 'amp' ),
'status' => sprintf(
'error_type' => __( 'Type', 'amp' ),
'details' => sprintf(
'%s<span class="dashicons dashicons-editor-help tooltip-button" tabindex="0"></span><div class="tooltip" hidden data-content="%s"></div>',
esc_html__( 'Status', 'amp' ),
esc_html__( 'Context', 'amp' ),
esc_attr(
sprintf(
'<h3>%s</h3><p>%s</p>',
esc_html__( 'Status', 'amp' ),
esc_html__( 'An accepted validation error is one that will not block a URL from being served as AMP; the validation error will be sanitized, normally resulting in the offending markup being stripped from the response to ensure AMP validity.', 'amp' )
esc_html__( 'Context', 'amp' ),
esc_html__( 'The parent element of where the error occurred.', 'amp' )
)
)
),
'details' => sprintf(
'sources_with_invalid_output' => __( 'Sources', 'amp' ),
'status' => sprintf(
'%s<span class="dashicons dashicons-editor-help tooltip-button" tabindex="0"></span><div class="tooltip" hidden data-content="%s"></div>',
esc_html__( 'Details', 'amp' ),
esc_html__( 'Status', 'amp' ),
esc_attr(
sprintf(
'<h3>%s</h3><p>%s</p>',
esc_html__( 'Details', 'amp' ),
esc_html__( 'The parent element of where the error occurred.', 'amp' )
esc_html__( 'Status', 'amp' ),
esc_html__( 'An accepted validation error is one that will not block a URL from being served as AMP; the validation error will be sanitized, normally resulting in the offending markup being stripped from the response to ensure AMP validity.', 'amp' )
)
)
),
'sources_with_invalid_output' => __( 'Sources', 'amp' ),
'error_type' => __( 'Type', 'amp' ),
];
}

Expand Down Expand Up @@ -990,18 +990,18 @@ public static function output_custom_column( $column_name, $post_id ) {
if ( ! empty( $error_summary[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ] ) ) {
foreach ( $error_summary[ AMP_Validation_Error_Taxonomy::REMOVED_ELEMENTS ] as $name => $count ) {
if ( 1 === (int) $count ) {
$items[] = sprintf( '<code>%s</code>', esc_html( $name ) );
$items[] = sprintf( '<code>&lt;%s&gt;</code>', esc_html( $name ) );
} else {
$items[] = sprintf( '<code>%s</code> (%d)', esc_html( $name ), $count );
$items[] = sprintf( '<code>&lt;%s&gt;</code> (%d)', esc_html( $name ), $count );
}
}
}
if ( ! empty( $error_summary[ AMP_Validation_Error_Taxonomy::REMOVED_ATTRIBUTES ] ) ) {
foreach ( $error_summary[ AMP_Validation_Error_Taxonomy::REMOVED_ATTRIBUTES ] as $name => $count ) {
if ( 1 === (int) $count ) {
$items[] = sprintf( '<code>[%s]</code>', esc_html( $name ) );
$items[] = sprintf( '<code>%s</code>', esc_html( $name ) );
} else {
$items[] = sprintf( '<code>[%s]</code> (%d)', esc_html( $name ), $count );
$items[] = sprintf( '<code>%s</code> (%d)', esc_html( $name ), $count );
}
}
}
Expand Down Expand Up @@ -1029,7 +1029,7 @@ public static function render_sources_column( $error_summary, $post_id ) {
return;
}

// Show nothing if there are no valudation errors.
// Show nothing if there are no validation errors.
if ( 0 === count( array_filter( $error_summary ) ) ) {
esc_html_e( '--', 'amp' );
return;
Expand All @@ -1043,22 +1043,19 @@ public static function render_sources_column( $error_summary, $post_id ) {

$sources = $error_summary[ AMP_Validation_Error_Taxonomy::SOURCES_INVALID_OUTPUT ];
$output = [];
$plugins = get_plugins();
foreach ( wp_array_slice_assoc( $sources, [ 'plugin', 'mu-plugin' ] ) as $type => $slugs ) {
$plugin_names = [];
$plugin_slugs = array_unique( $slugs );
foreach ( $plugin_slugs as $plugin_slug ) {
if ( 'mu-plugin' === $type ) {
$plugin_names[] = $plugin_slug;
} else {
$name = $plugin_slug;
foreach ( $plugins as $plugin_file => $plugin_data ) {
if ( strtok( $plugin_file, '/' ) === $plugin_slug ) {
$name = $plugin_data['Name'];
break;
}
$plugin_name = $plugin_slug;
$plugin = AMP_Validation_Error_Taxonomy::get_plugin_from_slug( $plugin_slug );
if ( $plugin ) {
$plugin_name = $plugin['data']['Name'];
}
$plugin_names[] = $name;
$plugin_names[] = $plugin_name;
}
}
$count = count( $plugin_names );
Expand Down Expand Up @@ -1580,11 +1577,7 @@ public static function handle_validation_error_status_update() {
'amp_taxonomy_terms_updated' => $updated_count,
];

/*
* Re-check the post after the validation status change. This is particularly important for validation errors like
* 'removed_unused_css_rules' since whether it is accepted will determine whether other validation errors are triggered
* such as in this case 'excessive_css'.
*/
// Re-check the post after the validation status change.
if ( $updated_count > 0 ) {
$validation_results = self::recheck_post( $post->ID );
// @todo For WP_Error case, see <https://github.com/ampproject/amp-wp/issues/1166>.
Expand Down
Loading