Skip to content

Commit 40e20c6

Browse files
committed
refactor: update eslint-plugin-eslint-plugin
1 parent e6789db commit 40e20c6

24 files changed

+154
-118
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"eslint": "^8.57.0 || ^9.13.0",
5353
"eslint-config-airbnb-base": "^15.0.0",
5454
"eslint-doc-generator": "^1.7.1",
55-
"eslint-plugin-eslint-plugin": "^4.3.0",
55+
"eslint-plugin-eslint-plugin": "^6.3.1",
5656
"eslint-plugin-flowtype": "^5.8.0 || ^8.0.3",
5757
"eslint-plugin-import": "^2.31.0",
5858
"estraverse": "^5.3.0",

src/rules/alt-text.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/rules/anchor-has-content.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import getElementType from '../util/getElementType';
1313
import { arraySchema, generateObjSchema } from '../util/schemas';
1414
import hasAccessibleChild from '../util/hasAccessibleChild';
1515

16-
const errorMessage = 'Anchors must have content and the content must be accessible by a screen reader.';
17-
1816
const schema = generateObjSchema({ components: arraySchema });
1917

2018
export default {
@@ -23,6 +21,9 @@ export default {
2321
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/anchor-has-content.md',
2422
description: 'Enforce all anchors to contain accessible content.',
2523
},
24+
messages: {
25+
error: 'Anchors must have content and the content must be accessible by a screen reader.',
26+
},
2627
schema: [schema],
2728
},
2829

@@ -47,8 +48,8 @@ export default {
4748
}
4849

4950
context.report({
51+
messageId: 'error',
5052
node,
51-
message: errorMessage,
5253
});
5354
},
5455
};

src/rules/aria-activedescendant-has-tabindex.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import isInteractiveElement from '../util/isInteractiveElement';
1414
// Rule Definition
1515
// ----------------------------------------------------------------------------
1616

17-
const errorMessage = 'An element that manages focus with `aria-activedescendant` must have a tabindex';
18-
1917
const schema = generateObjSchema();
2018

2119
export default {
@@ -24,6 +22,9 @@ export default {
2422
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-activedescendant-has-tabindex.md',
2523
description: 'Enforce elements with aria-activedescendant are tabbable.',
2624
},
25+
messages: {
26+
error: 'An element that manages focus with `aria-activedescendant` must have a tabindex',
27+
},
2728
schema: [schema],
2829
},
2930

@@ -60,8 +61,8 @@ export default {
6061
}
6162

6263
context.report({
64+
messageId: 'error',
6365
node,
64-
message: errorMessage,
6566
});
6667
},
6768
};

src/rules/aria-props.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ import { propName } from 'jsx-ast-utils';
1212
import { generateObjSchema } from '../util/schemas';
1313
import getSuggestion from '../util/getSuggestion';
1414

15-
const ariaAttributes = [...aria.keys()];
16-
17-
const errorMessage = (name) => {
18-
const suggestions = getSuggestion(name, ariaAttributes);
19-
const message = `${name}: This attribute is an invalid ARIA attribute.`;
20-
21-
if (suggestions.length > 0) {
22-
return `${message} Did you mean to use ${suggestions}?`;
23-
}
24-
25-
return message;
26-
};
27-
2815
const schema = generateObjSchema();
2916

3017
export default {
@@ -33,6 +20,10 @@ export default {
3320
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-props.md',
3421
description: 'Enforce all `aria-*` props are valid.',
3522
},
23+
messages: {
24+
error: '{{name}}: This attribute is an invalid ARIA attribute.',
25+
'error-with-suggestions': '{{name}}: This attribute is an invalid ARIA attribute. Did you mean to use {{suggestions}}?',
26+
},
3627
schema: [schema],
3728
},
3829

@@ -48,9 +39,15 @@ export default {
4839
const isValid = aria.has(name);
4940

5041
if (isValid === false) {
42+
const suggestions = getSuggestion(name, aria.keys());
43+
5144
context.report({
45+
data: {
46+
name,
47+
suggestions,
48+
},
49+
messageId: suggestions.length === 0 ? 'error' : 'error-with-suggestions',
5250
node: attribute,
53-
message: errorMessage(name),
5451
});
5552
}
5653
},

src/rules/aria-proptypes.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,6 @@ import { aria } from 'aria-query';
1111
import { getLiteralPropValue, getPropValue, propName } from 'jsx-ast-utils';
1212
import { generateObjSchema } from '../util/schemas';
1313

14-
const errorMessage = (name, type, permittedValues) => {
15-
switch (type) {
16-
case 'tristate':
17-
return `The value for ${name} must be a boolean or the string "mixed".`;
18-
case 'token':
19-
return `The value for ${name} must be a single token from the following: ${permittedValues}.`;
20-
case 'tokenlist':
21-
return `The value for ${name} must be a list of one or more \
22-
tokens from the following: ${permittedValues}.`;
23-
case 'idlist':
24-
return `The value for ${name} must be a list of strings that represent DOM element IDs (idlist)`;
25-
case 'id':
26-
return `The value for ${name} must be a string that represents a DOM element ID`;
27-
case 'boolean':
28-
case 'string':
29-
case 'integer':
30-
case 'number':
31-
default:
32-
return `The value for ${name} must be a ${type}.`;
33-
}
34-
};
35-
3614
const validityCheck = (value, expectedType, permittedValues) => {
3715
switch (expectedType) {
3816
case 'boolean':
@@ -69,6 +47,17 @@ export default {
6947
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-proptypes.md',
7048
description: 'Enforce ARIA state and property values are valid.',
7149
},
50+
messages: {
51+
boolean: 'The value for {{name}} must be a boolean.',
52+
id: 'The value for {{name}} must be a string that represents a DOM element ID',
53+
idlist: 'The value for {{name}} must be a list of strings that represent DOM element IDs (idlist)',
54+
integer: 'The value for {{name}} must be a integer.',
55+
number: 'The value for {{name}} must be a number.',
56+
string: 'The value for {{name}} must be a string.',
57+
token: 'The value for {{name}} must be a single token from the following: {{permittedValues}}.',
58+
tokenlist: 'The value for {{name}} must be a list of one or more tokens from the following: {{permittedValues}}.',
59+
tristate: 'The value for {{name}} must be a boolean or the string "mixed".',
60+
},
7261
schema: [schema],
7362
},
7463

@@ -105,8 +94,12 @@ export default {
10594
}
10695

10796
context.report({
97+
data: {
98+
name,
99+
permittedValues,
100+
},
101+
messageId: permittedType,
108102
node: attribute,
109-
message: errorMessage(name, permittedType, permittedValues),
110103
});
111104
},
112105
}),

src/rules/aria-role.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { getLiteralPropValue, propName } from 'jsx-ast-utils';
1313
import getElementType from '../util/getElementType';
1414
import { generateObjSchema } from '../util/schemas';
1515

16-
const errorMessage = 'Elements with ARIA roles must use a valid, non-abstract ARIA role.';
17-
1816
const schema = generateObjSchema({
1917
allowedInvalidRoles: {
2018
items: {
@@ -37,6 +35,9 @@ export default {
3735
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-role.md',
3836
description: 'Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role.',
3937
},
38+
messages: {
39+
error: 'Elements with ARIA roles must use a valid, non-abstract ARIA role.',
40+
},
4041
schema: [schema],
4142
},
4243

@@ -74,8 +75,8 @@ export default {
7475
if (isValid === true) { return; }
7576

7677
context.report({
78+
messageId: 'error',
7779
node: attribute,
78-
message: errorMessage,
7980
});
8081
},
8182
});

src/rules/aria-unsupported-elements.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ import { propName } from 'jsx-ast-utils';
1616
import { generateObjSchema } from '../util/schemas';
1717
import getElementType from '../util/getElementType';
1818

19-
const errorMessage = (invalidProp) => (
20-
`This element does not support ARIA roles, states and properties. \
21-
Try removing the prop '${invalidProp}'.`
22-
);
23-
2419
const schema = generateObjSchema();
2520

2621
export default {
@@ -29,6 +24,9 @@ export default {
2924
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-unsupported-elements.md',
3025
description: 'Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes.',
3126
},
27+
messages: {
28+
error: "This element does not support ARIA roles, states and properties. Try removing the prop '{{ invalidProp }}'.",
29+
},
3230
schema: [schema],
3331
},
3432

@@ -58,8 +56,11 @@ export default {
5856

5957
if (invalidAttributes.has(name)) {
6058
context.report({
59+
data: {
60+
invalidProp: name,
61+
},
62+
messageId: 'error',
6163
node,
62-
message: errorMessage(name),
6364
});
6465
}
6566
});

src/rules/autocomplete-valid.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export default {
2121
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/autocomplete-valid.md',
2222
description: 'Enforce that autocomplete attributes are used correctly.',
2323
},
24+
messages: {
25+
error: '{{ message }}',
26+
},
2427
schema: [schema],
2528
},
2629

@@ -54,8 +57,11 @@ export default {
5457
}
5558
// Since we only test one rule, with one node, return the message from first (and only) instance of each
5659
context.report({
60+
data: {
61+
message: violations[0].nodes[0].all[0].message,
62+
},
63+
messageId: 'error',
5764
node,
58-
message: violations[0].nodes[0].all[0].message,
5965
});
6066
},
6167
};

0 commit comments

Comments
 (0)