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

Enable the blinks and marquee axe-core rules to power the text_blinking_scrolling rule #637

Merged
27 changes: 18 additions & 9 deletions includes/classes/class-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ function () use ( $ns, $version ) {
);
}



/**
* REST handler that saves to the DB a list of js rule violations for a post.
*
Expand Down Expand Up @@ -194,11 +192,19 @@ public function set_post_scan_results( $request ) {

//phpcs:ignore Generic.Commenting.Todo.TaskFound
// TODO: setup a rules class for loading/filtering rules.
$rules = edac_register_rules();
$js_rule_ids = [];
$rules = edac_register_rules();
$js_rule_ids = [];
$combined_rule_ids = [];
foreach ( $rules as $rule ) {
if ( array_key_exists( 'ruleset', $rule ) && 'js' === $rule['ruleset'] ) {
$js_rule_ids[] = $rule['slug'];

// Some rules can be a grouping of other checks with different ids. This tracks those combined check IDs for later mapping.
if ( array_key_exists( 'combines', $rule ) && ! empty( $rule['combines'] ) ) {
foreach ( $rule['combines'] as $combine_rule_id ) {
$combined_rule_ids[ $combine_rule_id ] = $rule['slug'];
}
}
}
}

Expand Down Expand Up @@ -226,7 +232,10 @@ public function set_post_scan_results( $request ) {
foreach ( $violations as $violation ) {
$rule_id = $violation['ruleId'];

if ( in_array( $rule_id, $js_rule_ids, true ) ) {
// If this rule is a combined rule then map it to the actual reporting rule ID.
$actual_rule_id = array_key_exists( $rule_id, $combined_rule_ids ) ? $combined_rule_ids[ $rule_id ] : $rule_id;

if ( in_array( $actual_rule_id, $js_rule_ids, true ) ) {

// This rule is one that we've included in our js ruleset.

Expand All @@ -236,7 +245,7 @@ public function set_post_scan_results( $request ) {
//phpcs:ignore Generic.Commenting.Todo.TaskFound
// TODO: setup a rules class for loading/filtering rules.
foreach ( $rules as $rule ) {
if ( $rule['slug'] === $rule_id ) {
if ( $rule['slug'] === $actual_rule_id ) {
$impact = $rule['rule_type']; // if we are defining the rule_type in php rules config, use that instead of the js rule's impact setting.
}
}
Expand All @@ -255,9 +264,9 @@ public function set_post_scan_results( $request ) {
* @param string $rule_id The rule ID.
* @param string $type The type of validation which is always 'js' in this path.
*/
do_action( 'edac_before_rule', $post_id, $rule_id, 'js' );
do_action( 'edac_before_rule', $post_id, $actual_rule_id, 'js' );

( new Insert_Rule_Data() )->insert( $post, $rule_id, $impact, $html );
( new Insert_Rule_Data() )->insert( $post, $actual_rule_id, $impact, $html );

/**
* Fires after a rule is run against the content.
Expand All @@ -270,7 +279,7 @@ public function set_post_scan_results( $request ) {
* @param string $rule_id The rule ID.
* @param string $type The type of validation which is always 'js' in this path.
*/
do_action( 'edac_after_rule', $post_id, $rule_id, 'js' );
do_action( 'edac_after_rule', $post_id, $actual_rule_id, 'js' );

}
}
Expand Down
2 changes: 2 additions & 0 deletions includes/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@
'<code>&lt;marquee&gt;</code>',
'<code>text-decoration: blink</code>'
),
'ruleset' => 'js',
'combines' => [ 'blink', 'marquee' ],
],
[
'title' => esc_html__( 'Insufficient Color Contrast', 'accessibility-checker' ),
Expand Down
100 changes: 0 additions & 100 deletions includes/rules/text_blinking_scrolling.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/pageScanner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const scan = async (
values: [
'color_contrast_failure',
'underlined_text',
'blink',
'marquee',
],
},

Expand Down
Loading