Skip to content

Commit fb377b5

Browse files
committed
docs(linter): Fix jsx-a11y/img-redundant-alt configuration field names.
These were wrong previously due to the fields having different names in the config object than the actual configuration passed to the rule. Also, I'm not sure that the tests for this rule adequately cover the configuration options? I didn't update those here, though. Separate problem.
1 parent ab4deb0 commit fb377b5

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222

2323
fn img_redundant_alt_diagnostic(span: Span) -> OxcDiagnostic {
2424
OxcDiagnostic::warn("Redundant `alt` attribute.")
25-
.with_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.").with_label(span)
25+
.with_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.").with_label(span)
2626
}
2727

2828
#[derive(Debug, Default, Clone)]
@@ -33,9 +33,9 @@ pub struct ImgRedundantAlt(Box<ImgRedundantAltConfig>);
3333
pub struct ImgRedundantAltConfig {
3434
/// JSX element types to validate (component names) where the rule applies.
3535
/// For example, `["img", "Image"]`.
36-
types_to_validate: Vec<CompactStr>,
36+
components: Vec<CompactStr>,
3737
/// Words considered redundant in alt text that should trigger a warning.
38-
redundant_words: Vec<Cow<'static, str>>,
38+
words: Vec<Cow<'static, str>>,
3939
}
4040

4141
impl std::ops::Deref for ImgRedundantAlt {
@@ -51,16 +51,16 @@ const REDUNDANT_WORDS: [&str; 3] = ["image", "photo", "picture"];
5151
impl Default for ImgRedundantAltConfig {
5252
fn default() -> Self {
5353
Self {
54-
types_to_validate: vec![CompactStr::new("img")],
55-
redundant_words: vec!["image".into(), "photo".into(), "picture".into()],
54+
components: vec![CompactStr::new("img")],
55+
words: vec!["image".into(), "photo".into(), "picture".into()],
5656
}
5757
}
5858
}
5959
impl ImgRedundantAltConfig {
60-
fn new(types_to_validate: Vec<&str>, redundant_words: &[&str]) -> Self {
60+
fn new(components: Vec<&str>, words: &[&str]) -> Self {
6161
Self {
62-
types_to_validate: types_to_validate.into_iter().map(Into::into).collect(),
63-
redundant_words: redundant_words
62+
components: components.into_iter().map(Into::into).collect(),
63+
words: words
6464
.iter()
6565
.map(|w| Cow::Owned(w.cow_to_ascii_lowercase().to_string()))
6666
.collect::<Vec<_>>(),
@@ -131,7 +131,7 @@ impl Rule for ImgRedundantAlt {
131131

132132
let element_type = get_element_type(ctx, jsx_el);
133133

134-
if !self.types_to_validate.iter().any(|comp| comp == &element_type) {
134+
if !self.components.iter().any(|comp| comp == &element_type) {
135135
return;
136136
}
137137

@@ -193,7 +193,7 @@ impl ImgRedundantAlt {
193193
#[inline]
194194
fn is_redundant_alt_text(&self, alt_text: &str) -> bool {
195195
let alt_text = alt_text.cow_to_ascii_lowercase();
196-
for word in &self.redundant_words {
196+
for word in &self.words {
197197
if let Some(index) = alt_text.find(word.as_ref()) {
198198
// check if followed by space or is whole text
199199
if index + word.len() == alt_text.len()

crates/oxc_linter/src/snapshots/jsx_a11y_img_redundant_alt.snap

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,165 +6,165 @@ source: crates/oxc_linter/src/tester.rs
66
1<img alt='Photo of friend.' />;
77
· ───
88
╰────
9-
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.
9+
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.
1010

1111
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
1212
╭─[img_redundant_alt.tsx:1:6]
1313
1<img alt='Picture of friend.' />;
1414
· ───
1515
╰────
16-
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.
16+
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.
1717

1818
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
1919
╭─[img_redundant_alt.tsx:1:6]
2020
1<img alt='Image of friend.' />;
2121
· ───
2222
╰────
23-
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.
23+
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.
2424

2525
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
2626
╭─[img_redundant_alt.tsx:1:6]
2727
1<img alt='PhOtO of friend.' />;
2828
· ───
2929
╰────
30-
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.
30+
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

3232
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
3333
╭─[img_redundant_alt.tsx:1:6]
3434
1<img alt={'photo'} />;
3535
· ───
3636
╰────
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.
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.
3838

3939
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
4040
╭─[img_redundant_alt.tsx:1:6]
4141
1<img alt='piCTUre of friend.' />;
4242
· ───
4343
╰────
44-
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.
44+
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.
4545

4646
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
4747
╭─[img_redundant_alt.tsx:1:6]
4848
1<img alt='imAGE of friend.' />;
4949
· ───
5050
╰────
51-
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.
51+
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.
5252

5353
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
5454
╭─[img_redundant_alt.tsx:1:6]
5555
1<img alt='photo of cool person' aria-hidden={false} />
5656
· ───
5757
╰────
58-
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.
58+
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.
5959

6060
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
6161
╭─[img_redundant_alt.tsx:1:6]
6262
1<img alt='picture of cool person' aria-hidden={false} />
6363
· ───
6464
╰────
65-
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.
65+
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.
6666

6767
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
6868
╭─[img_redundant_alt.tsx:1:6]
6969
1<img alt='image of cool person' aria-hidden={false} />
7070
· ───
7171
╰────
72-
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.
72+
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.
7373

7474
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
7575
╭─[img_redundant_alt.tsx:1:6]
7676
1<img alt='photo' {...this.props} />
7777
· ───
7878
╰────
79-
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.
79+
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.
8080

8181
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
8282
╭─[img_redundant_alt.tsx:1:6]
8383
1<img alt='image' {...this.props} />
8484
· ───
8585
╰────
86-
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.
86+
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.
8787

8888
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
8989
╭─[img_redundant_alt.tsx:1:6]
9090
1<img alt='picture' {...this.props} />
9191
· ───
9292
╰────
93-
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.
93+
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.
9494

9595
eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
9696
╭─[img_redundant_alt.tsx:1:6]
9797
1<img alt={`picture doing ${things}`} {...this.props} />
9898
· ───
9999
╰────
100-
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.
100+
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.
101101
102102
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
103103
╭─[img_redundant_alt.tsx:1:6]
104104
1 │ <img alt={`photo doing ${things}`} {...this.props} />
105105
· ───
106106
╰────
107-
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.
107+
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.
108108
109109
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
110110
╭─[img_redundant_alt.tsx:1:6]
111111
1 │ <img alt={`image doing ${things}`} {...this.props} />
112112
· ───
113113
╰────
114-
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.
114+
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.
115115
116116
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
117117
╭─[img_redundant_alt.tsx:1:6]
118118
1 │ <img alt={`picture doing ${picture}`} {...this.props} />
119119
· ───
120120
╰────
121-
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.
121+
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.
122122
123123
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
124124
╭─[img_redundant_alt.tsx:1:6]
125125
1 │ <img alt={`photo doing ${photo}`} {...this.props} />
126126
· ───
127127
╰────
128-
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.
128+
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.
129129
130130
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
131131
╭─[img_redundant_alt.tsx:1:6]
132132
1 │ <img alt={`image doing ${image}`} {...this.props} />
133133
· ───
134134
╰────
135-
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.
135+
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.
136136
137137
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
138138
╭─[img_redundant_alt.tsx:1:8]
139139
1 │ <Image alt='Photo of a friend' />
140140
· ───
141141
╰────
142-
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.
142+
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.
143143
144144
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
145145
╭─[img_redundant_alt.tsx:1:6]
146146
1 │ <img alt='Word1' />;
147147
· ───
148148
╰────
149-
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.
149+
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.
150150
151151
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
152152
╭─[img_redundant_alt.tsx:1:6]
153153
1 │ <img alt='Word2' />;
154154
· ───
155155
╰────
156-
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.
156+
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.
157157
158158
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
159159
╭─[img_redundant_alt.tsx:1:8]
160160
1 │ <Image alt='Word1' />;
161161
· ───
162162
╰────
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.
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.
164164
165165
⚠ eslint-plugin-jsx-a11y(img-redundant-alt): Redundant `alt` attribute.
166166
╭─[img_redundant_alt.tsx:1:8]
167167
1 │ <Image alt='Word2' />;
168168
· ───
169169
╰────
170-
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.
170+
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.

0 commit comments

Comments
 (0)