Skip to content

Commit 9c0cdf6

Browse files
authored
SONARHTML-332 S6819 Skip non-standard html components (#491)
1 parent 5dc657c commit 9c0cdf6

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ jobs:
108108
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
109109
run: |
110110
mvn -f its/ruling/pom.xml verify -Pqa -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V
111+
- name: Show ruling differences
112+
if: failure()
113+
run: ./tools/ruling-debug-script.sh
111114

112115
promote:
113116
needs: [build, build-windows, qa, ruling]

its/ruling/src/test/resources/expected/Web-S6819.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
59,
2121
127
2222
],
23-
"project:voten/resources/views/auth/register.blade.php": [
24-
56
25-
],
2623
"project:voten/resources/views/passport/index.blade.php": [
2724
26,
2825
27

sonar-html-plugin/src/main/java/org/sonar/plugins/html/checks/accessibility/PreferTagOverRoleCheck.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
import org.sonar.plugins.html.checks.AbstractPageCheck;
2626
import org.sonar.plugins.html.node.TagNode;
2727

28+
import static org.sonar.plugins.html.api.HtmlConstants.hasKnownHTMLTag;
29+
2830
@Rule(key = "S6819")
2931
public class PreferTagOverRoleCheck extends AbstractPageCheck {
3032
@Override
3133
public void startElement(TagNode element) {
3234
var roleAttr = element.getPropertyValue("role");
33-
if (roleAttr == null) {
35+
if (roleAttr == null || !hasKnownHTMLTag(element)) {
3436
return;
3537
}
3638

sonar-html-plugin/src/test/java/org/sonar/plugins/html/checks/accessibility/PreferTagOverRoleCheckTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ void html() {
3434
HtmlSourceCode sourceCode = TestHelper.scan(
3535
new File("src/test/resources/checks/PreferTagOverRoleCheck.html"),
3636
new PreferTagOverRoleCheck());
37-
var issues = sourceCode.getIssues();
38-
assertThat(issues).hasSize(8);
3937
checkMessagesVerifier.verify(sourceCode.getIssues())
4038
.next().atLine(1).withMessage("Use <input> instead of the checkbox role to ensure accessibility across all devices.")
4139
.next().atLine(2).withMessage("Use <button> or <input> instead of the button role to ensure accessibility across all devices.")
4240
.next().atLine(3).withMessage("Use <h1> or <h2> or <h3> or <h4> or <h5> or <h6> instead of the heading role to ensure accessibility across all devices.")
4341
.next().atLine(4).withMessage("Use <a> or <area> instead of the link role to ensure accessibility across all devices.")
4442
.next().atLine(5).withMessage("Use <tbody> or <tfoot> or <thead> instead of the rowgroup role to ensure accessibility across all devices.")
4543
.next().atLine(6).withMessage("Use <input> instead of the checkbox role to ensure accessibility across all devices.")
46-
.next().atLine(7).withMessage("Use <input> instead of the checkbox role to ensure accessibility across all devices.")
47-
.next().atLine(8).withMessage("Use <header> instead of the banner role to ensure accessibility across all devices.")
44+
.next().atLine(7).withMessage("Use <header> instead of the banner role to ensure accessibility across all devices.")
4845
.consume();
4946
}
5047
}

sonar-html-plugin/src/test/resources/checks/PreferTagOverRoleCheck.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
<div role="link" /> <!-- Noncompliant -->
55
<div role="rowgroup" /> <!-- Noncompliant -->
66
<span role="checkbox" /> <!-- Noncompliant -->
7-
<other role="checkbox" /> <!-- Noncompliant -->
87
<div role="banner" /> <!-- Noncompliant -->
98

109
<div />
1110
<div role="unknown" />
1211
<div role="also unknown" />
1312
<other />
1413
<img role="img" />
15-
<input role="checkbox" />
14+
<input role="checkbox" />
15+
<other role="checkbox" /> <!-- Compliant as using non-standard html tag -->
16+
<mat-card role="region" aria-labelledby="reportsHeading" appearance="outlined" /> <!-- Compliant as using non-standard html tag -->

tools/ruling-debug-script.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
default_actual_dir="its/ruling/target/actual"
4+
5+
expected_dir="its/ruling/src/test/resources/expected"
6+
actual_dir="${1:-$default_actual_dir}"
7+
8+
# Differing files
9+
diff -rq "$expected_dir" "$actual_dir" | grep "differ" | while read -r line; do
10+
file1=$(echo "$line" | awk '{print $2}')
11+
file2=$(echo "$line" | awk '{print $4}')
12+
echo "Differences in: $file1"
13+
diff -u "$file1" "$file2"
14+
echo "----------------------------------------"
15+
done
16+
17+
# Files only in one directory
18+
diff -rq "$expected_dir" "$actual_dir" | grep "Only in" | while read -r line; do
19+
dir=$(echo "$line" | awk '{print $3}' | sed 's/://')
20+
file=$(echo "$line" | awk '{print $4}')
21+
full_path="$dir/$file"
22+
if [ -f "$full_path" ]; then
23+
echo "File only in $dir: $file"
24+
cat "$full_path"
25+
echo "----------------------------------------"
26+
fi
27+
done

0 commit comments

Comments
 (0)