Skip to content

Commit 9302e63

Browse files
committed
chore(linter): Add a few more tests.
Also rename 'array' to 'config_array' for clarity.
1 parent 2c9b754 commit 9302e63

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

crates/oxc_linter/src/rules/jsx_a11y/img_redundant_alt.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl ImgRedundantAlt {
213213
fn test() {
214214
use crate::tester::Tester;
215215

216-
fn array() -> serde_json::Value {
216+
fn config_array() -> serde_json::Value {
217217
serde_json::json!([{
218218
"components": ["Image"],
219219
"words": ["Word1", "Word2"]
@@ -275,6 +275,17 @@ fn test() {
275275
Some(serde_json::json!([{ "words": ["not to say"] }])),
276276
None,
277277
),
278+
(
279+
r"<PicVersionThree alt='this is a photo' />;",
280+
Some(serde_json::json!([{ "components": ["PicVersionThree"] }])),
281+
None,
282+
),
283+
// TODO: if there is a period immediately after the banned word, it does not get recognized by the current logic.
284+
// (
285+
// r"<PicVersionThree alt='this is a photo.' />;",
286+
// Some(serde_json::json!([{ "components": ["PicVersionThree"] }])),
287+
// None,
288+
// ),
278289
(r"<img alt='PhOtO of friend.' />;", None, None),
279290
(r"<img alt={'photo'} />;", None, None),
280291
(r"<img alt='piCTUre of friend.' />;", None, None),
@@ -291,12 +302,13 @@ fn test() {
291302
(r"<img alt={`picture doing ${picture}`} {...this.props} />", None, None),
292303
(r"<img alt={`photo doing ${photo}`} {...this.props} />", None, None),
293304
(r"<img alt={`image doing ${image}`} {...this.props} />", None, None),
305+
(r"<Image alt='Photo of a friend' />", Some(config_array()), None),
294306
(r"<Image alt='Photo of a friend' />", None, Some(settings())),
295307
// TESTS FOR ARRAY OPTION TESTS
296-
(r"<img alt='Word1' />;", Some(array()), None),
297-
(r"<img alt='Word2' />;", Some(array()), None),
298-
(r"<Image alt='Word1' />;", Some(array()), None),
299-
(r"<Image alt='Word2' />;", Some(array()), None),
308+
(r"<img alt='Word1' />;", Some(config_array()), None),
309+
(r"<img alt='Word2' />;", Some(config_array()), None),
310+
(r"<Image alt='Word1' />;", Some(config_array()), None),
311+
(r"<Image alt='Word2' />;", Some(config_array()), None),
300312
// non-english tests, they need to be enabled after we fix the code.
301313
// (r"<img alt='イメージ' />", Some(serde_json::json!([{ "words": ["イメージ"] }])), None),
302314
// (r"<img alt='イメージです' />", Some(serde_json::json!([{ "words": ["イメージ"] }])), None),

crates/oxc_linter/src/snapshots/jsx_a11y_img_redundant_alt.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ source: crates/oxc_linter/src/tester.rs
2929
╰────
3030
help: Provide no redundant alt text for image. Screen-readers already announce `img` tags as an image. You don't need to use the words `image`, `photo`, or `picture` (or any specified custom words) in the `alt` prop.
3131

32+
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
33+
╭─[img_redundant_alt.tsx:1:18]
34+
1<PicVersionThree alt='this is a photo' />;
35+
· ───
36+
╰────
37+
help: Provide no redundant alt text for image. Screen-readers already announce `img` tags as an image. You don't need to use the words `image`, `photo`, or `picture` (or any specified custom words) in the `alt` prop.
38+
3239
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
3340
╭─[img_redundant_alt.tsx:1:6]
3441
1<img alt='PhOtO of friend.' />;
@@ -148,6 +155,13 @@ source: crates/oxc_linter/src/tester.rs
148155
╰────
149156
help: Provide no redundant alt text for image. Screen-readers already announce `img` tags as an image. You don't need to use the words `image`, `photo`, or `picture` (or any specified custom words) in the `alt` prop.
150157
158+
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
159+
╭─[img_redundant_alt.tsx:1:8]
160+
1 │ <Image alt='Photo of a friend' />
161+
· ───
162+
╰────
163+
help: Provide no redundant alt text for image. Screen-readers already announce `img` tags as an image. You don't need to use the words `image`, `photo`, or `picture` (or any specified custom words) in the `alt` prop.
164+
151165
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
152166
╭─[img_redundant_alt.tsx:1:6]
153167
1 │ <img alt='Word1' />;

0 commit comments

Comments
 (0)