Skip to content

Commit 22f18ac

Browse files
authoredMar 14, 2025··
fix(linter): improve jsx-a11y/anchor-ambiguous-text diagnostic message (#9789)
fix #9787
1 parent ccd4d2e commit 22f18ac

File tree

3 files changed

+70
-33
lines changed

3 files changed

+70
-33
lines changed
 

‎apps/oxlint/src/snapshots/fixtures__extends_config_overrides@oxlint.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: apps/oxlint/src/tester.rs
3+
snapshot_kind: text
34
---
45
##########
56
arguments: overrides
@@ -21,13 +22,14 @@ working directory: fixtures/extends_config
2122
`----
2223
help: Use `unknown` instead, this will force you to explicitly, and safely, assert the type is correct.
2324
24-
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/anchor-ambiguous-text.html\eslint-plugin-jsx-a11y(anchor-ambiguous-text)]8;;\: Unexpected ambagious anchor link text.
25+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/anchor-ambiguous-text.html\eslint-plugin-jsx-a11y(anchor-ambiguous-text)]8;;\: Ambiguous text within anchor, screen reader users rely on link text for context.
2526
,-[overrides/test.tsx:2:10]
2627
1 | function component(): any {
2728
2 | return <a>click here</a>;
2829
: ^^^^^^^^^^^^^^^^^
2930
3 | }
3031
`----
32+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
3133
3234
Found 0 warnings and 3 errors.
3335
Finished in <variable>ms on 2 files using 1 threads.

‎crates/oxc_linter/src/rules/jsx_a11y/anchor_ambiguous_text.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ use crate::{
1818
},
1919
};
2020

21-
fn anchor_has_ambiguous_text(span: Span) -> OxcDiagnostic {
22-
OxcDiagnostic::warn("Unexpected ambagious anchor link text.").with_label(span)
21+
fn anchor_has_ambiguous_text(span: Span, text: &CompactStr) -> OxcDiagnostic {
22+
OxcDiagnostic::warn(
23+
"Ambiguous text within anchor, screen reader users rely on link text for context.",
24+
)
25+
.with_label(span)
26+
.with_help(format!("Avoid using ambiguous text like \"{text}\", replace it with more descriptive text that provides context."))
2327
}
2428

2529
#[derive(Debug, Default, Clone)]
@@ -122,8 +126,10 @@ impl Rule for AnchorAmbiguousText {
122126
return;
123127
}
124128

125-
if self.words.contains(&normalize_str(&text)) {
126-
ctx.diagnostic(anchor_has_ambiguous_text(jsx_el.span));
129+
let text = normalize_str(&text);
130+
131+
if self.words.contains(&text) {
132+
ctx.diagnostic(anchor_has_ambiguous_text(jsx_el.span, &text));
127133
}
128134
}
129135
}
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,199 @@
11
---
22
source: crates/oxc_linter/src/tester.rs
3+
snapshot_kind: text
34
---
4-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
5+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
56
╭─[anchor_ambiguous_text.tsx:1:1]
67
1 │ <a>here</a>;
78
· ───────────
89
╰────
10+
help: Avoid using ambiguous text like "here", replace it with more descriptive text that provides context.
911

10-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
12+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
1113
╭─[anchor_ambiguous_text.tsx:1:1]
1214
1 │ <a>HERE</a>;
1315
· ───────────
1416
╰────
17+
help: Avoid using ambiguous text like "here", replace it with more descriptive text that provides context.
1518

16-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
19+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
1720
╭─[anchor_ambiguous_text.tsx:1:1]
1821
1 │ <a>click here</a>;
1922
· ─────────────────
2023
╰────
24+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
2125

22-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
26+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
2327
╭─[anchor_ambiguous_text.tsx:1:1]
2428
1 │ <a>learn more</a>;
2529
· ─────────────────
2630
╰────
31+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
2732

28-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
33+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
2934
╭─[anchor_ambiguous_text.tsx:1:1]
3035
1 │ <a>learn more</a>;
3136
· ──────────────────────
3237
╰────
38+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
3339

34-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
40+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
3541
╭─[anchor_ambiguous_text.tsx:1:1]
3642
1 │ <a>learn more.</a>;
3743
· ──────────────────
3844
╰────
45+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
3946

40-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
47+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
4148
╭─[anchor_ambiguous_text.tsx:1:1]
4249
1 │ <a>learn more?</a>;
4350
· ──────────────────
4451
╰────
52+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
4553

46-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
54+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
4755
╭─[anchor_ambiguous_text.tsx:1:1]
4856
1 │ <a>learn more,</a>;
4957
· ──────────────────
5058
╰────
59+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
5160

52-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
61+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
5362
╭─[anchor_ambiguous_text.tsx:1:1]
5463
1 │ <a>learn more!</a>;
5564
· ──────────────────
5665
╰────
66+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
5767

58-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
68+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
5969
╭─[anchor_ambiguous_text.tsx:1:1]
6070
1 │ <a>learn more;</a>;
6171
· ──────────────────
6272
╰────
73+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
6374

64-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
75+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
6576
╭─[anchor_ambiguous_text.tsx:1:1]
6677
1 │ <a>learn more:</a>;
6778
· ──────────────────
6879
╰────
80+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
6981

70-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
82+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
7183
╭─[anchor_ambiguous_text.tsx:1:1]
7284
1 │ <a>link</a>;
7385
· ───────────
7486
╰────
87+
help: Avoid using ambiguous text like "link", replace it with more descriptive text that provides context.
7588

76-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
89+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
7790
╭─[anchor_ambiguous_text.tsx:1:1]
7891
1 │ <a>a link</a>;
7992
· ─────────────
8093
╰────
94+
help: Avoid using ambiguous text like "a link", replace it with more descriptive text that provides context.
8195

82-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
96+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
8397
╭─[anchor_ambiguous_text.tsx:1:1]
8498
1<a aria-label="click here">something</a>;
8599
· ────────────────────────────────────────
86100
╰────
101+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
87102

88-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
103+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
89104
╭─[anchor_ambiguous_text.tsx:1:1]
90105
1 │ <a> a link </a>;
91106
· ───────────────
92107
╰────
108+
help: Avoid using ambiguous text like "a link", replace it with more descriptive text that provides context.
93109

94-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
110+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
95111
╭─[anchor_ambiguous_text.tsx:1:1]
96112
1 │ <a>a<i></i> link</a>;
97113
· ────────────────────
98114
╰────
115+
help: Avoid using ambiguous text like "a link", replace it with more descriptive text that provides context.
99116

100-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
117+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
101118
╭─[anchor_ambiguous_text.tsx:1:1]
102119
1 │ <a><i></i>a link</a>;
103120
· ────────────────────
104121
╰────
122+
help: Avoid using ambiguous text like "a link", replace it with more descriptive text that provides context.
105123

106-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
124+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
107125
╭─[anchor_ambiguous_text.tsx:1:1]
108126
1 │ <a><span>click</span> here</a>;
109127
· ──────────────────────────────
110128
╰────
129+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
111130

112-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
131+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
113132
╭─[anchor_ambiguous_text.tsx:1:1]
114133
1 │ <a><span> click </span> here</a>;
115134
· ────────────────────────────────
116135
╰────
136+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
117137

118-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
138+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
119139
╭─[anchor_ambiguous_text.tsx:1:1]
120140
1 │ <a><span aria-hidden>more text</span>learn more</a>;
121141
· ───────────────────────────────────────────────────
122142
╰────
143+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
123144

124-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
145+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
125146
╭─[anchor_ambiguous_text.tsx:1:1]
126147
1 │ <a><span aria-hidden="true">more text</span>learn more</a>;
127148
· ──────────────────────────────────────────────────────────
128149
╰────
150+
help: Avoid using ambiguous text like "learn more", replace it with more descriptive text that provides context.
129151

130-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
152+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
131153
╭─[anchor_ambiguous_text.tsx:1:1]
132154
1 │ <a><img alt="click here"/></a>;
133155
· ──────────────────────────────
134156
╰────
157+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
135158

136-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
159+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
137160
╭─[anchor_ambiguous_text.tsx:1:1]
138161
1<a alt="tutorial on using eslint-plugin-jsx-a11y">click here</a>;
139162
· ────────────────────────────────────────────────────────────────
140163
╰────
164+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
141165

142-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
166+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
143167
╭─[anchor_ambiguous_text.tsx:1:1]
144168
1 │ <a><span alt="tutorial on using eslint-plugin-jsx-a11y">click here</span></a>;
145169
· ─────────────────────────────────────────────────────────────────────────────
146170
╰────
171+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
147172

148-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
173+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
149174
╭─[anchor_ambiguous_text.tsx:1:1]
150175
1 │ <a><CustomElement>click</CustomElement> here</a>;
151176
· ────────────────────────────────────────────────
152177
╰────
178+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
153179

154-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
180+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
155181
╭─[anchor_ambiguous_text.tsx:1:1]
156182
1 │ <Link>here</Link>
157183
· ─────────────────
158184
╰────
185+
help: Avoid using ambiguous text like "here", replace it with more descriptive text that provides context.
159186

160-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
187+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
161188
╭─[anchor_ambiguous_text.tsx:1:1]
162189
1 │ <a><Image alt="click here" /></a>
163190
· ─────────────────────────────────
164191
╰────
192+
help: Avoid using ambiguous text like "click here", replace it with more descriptive text that provides context.
165193

166-
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Unexpected ambagious anchor link text.
194+
eslint-plugin-jsx-a11y(anchor-ambiguous-text): Ambiguous text within anchor, screen reader users rely on link text for context.
167195
╭─[anchor_ambiguous_text.tsx:1:1]
168196
1 │ <a>a disallowed word</a>
169197
· ────────────────────────
170198
╰────
199+
help: Avoid using ambiguous text like "a disallowed word", replace it with more descriptive text that provides context.

0 commit comments

Comments
 (0)
Please sign in to comment.