@@ -53,8 +53,8 @@ const ruleByElement = {
5353 if ( altProp === undefined ) {
5454 if ( isPresentationRole ( nodeType , node . attributes ) ) {
5555 context . report ( {
56+ messageId : 'img-presentation-role' ,
5657 node,
57- message : 'Prefer alt="" over a presentational role. First rule of aria is to not use aria if it can be achieved via native HTML.' ,
5858 } ) ;
5959 return ;
6060 }
@@ -65,8 +65,8 @@ const ruleByElement = {
6565 if ( ariaLabelProp !== undefined ) {
6666 if ( ! ariaLabelHasValue ( ariaLabelProp ) ) {
6767 context . report ( {
68+ messageId : 'img-no-aria-label-value' ,
6869 node,
69- message : 'The aria-label attribute must have a value. The alt attribute is preferred over aria-label for images.' ,
7070 } ) ;
7171 }
7272 return ;
@@ -78,16 +78,19 @@ const ruleByElement = {
7878 if ( ariaLabelledbyProp !== undefined ) {
7979 if ( ! ariaLabelHasValue ( ariaLabelledbyProp ) ) {
8080 context . report ( {
81+ messageId : 'img-no-aria-labelledby-value' ,
8182 node,
82- message : 'The aria-labelledby attribute must have a value. The alt attribute is preferred over aria-labelledby for images.' ,
8383 } ) ;
8484 }
8585 return ;
8686 }
8787
8888 context . report ( {
89+ data : {
90+ nodeType,
91+ } ,
92+ messageId : 'img-no-alt' ,
8993 node,
90- message : `${ nodeType } elements must have an alt prop, either with meaningful text, or an empty string for decorative images.` ,
9194 } ) ;
9295 return ;
9396 }
@@ -102,8 +105,11 @@ const ruleByElement = {
102105
103106 // Undefined alt prop error.
104107 context . report ( {
108+ data : {
109+ nodeType,
110+ } ,
111+ messageId : 'img-invalid-alt' ,
105112 node,
106- message : `Invalid alt value for ${ nodeType } . Use alt="" for presentational images.` ,
107113 } ) ;
108114 } ,
109115
@@ -119,8 +125,8 @@ const ruleByElement = {
119125 }
120126
121127 context . report ( {
128+ messageId : 'object' ,
122129 node,
123- message : 'Embedded <object> elements must have alternative text by providing inner text, aria-label or aria-labelledby props.' ,
124130 } ) ;
125131 } ,
126132
@@ -136,8 +142,8 @@ const ruleByElement = {
136142 const altProp = getProp ( node . attributes , 'alt' ) ;
137143 if ( altProp === undefined ) {
138144 context . report ( {
145+ messageId : 'area' ,
139146 node,
140- message : 'Each area of an image map must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.' ,
141147 } ) ;
142148 return ;
143149 }
@@ -150,8 +156,8 @@ const ruleByElement = {
150156 }
151157
152158 context . report ( {
159+ messageId : 'area' ,
153160 node,
154- message : 'Each area of an image map must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.' ,
155161 } ) ;
156162 } ,
157163
@@ -172,8 +178,8 @@ const ruleByElement = {
172178 const altProp = getProp ( node . attributes , 'alt' ) ;
173179 if ( altProp === undefined ) {
174180 context . report ( {
181+ messageId : 'input-image' ,
175182 node,
176- message : '<input> elements with type="image" must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.' ,
177183 } ) ;
178184 return ;
179185 }
@@ -186,8 +192,8 @@ const ruleByElement = {
186192 }
187193
188194 context . report ( {
195+ messageId : 'input-image' ,
189196 node,
190- message : '<input> elements with type="image" must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.' ,
191197 } ) ;
192198 } ,
193199} ;
@@ -198,6 +204,16 @@ export default {
198204 url : 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/alt-text.md' ,
199205 description : 'Enforce all elements that require alternative text have meaningful information to relay back to end user.' ,
200206 } ,
207+ messages : {
208+ area : 'Each area of an image map must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.' ,
209+ 'img-invalid-alt' : 'Invalid alt value for {{nodeType}}. Use alt="" for presentational images.' ,
210+ 'img-presentation-role' : 'Prefer alt="" over a presentational role. First rule of aria is to not use aria if it can be achieved via native HTML.' ,
211+ 'img-no-alt' : "'{{nodeType}}' elements must have an alt prop, either with meaningful text, or an empty string for decorative images." ,
212+ 'img-no-aria-label-value' : 'The aria-label attribute must have a value. The alt attribute is preferred over aria-label for images.' ,
213+ 'img-no-aria-labelledby-value' : 'The aria-labelledby attribute must have a value. The alt attribute is preferred over aria-labelledby for images.' ,
214+ 'input-image' : '<input> elements with type="image" must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.' ,
215+ object : 'Embedded <object> elements must have alternative text by providing inner text, aria-label or aria-labelledby props.' ,
216+ } ,
201217 schema : [ schema ] ,
202218 } ,
203219
0 commit comments