Skip to content

Commit 0608b03

Browse files
MichaelDeBoeyljharb
andcommitted
[Refactor] use messageId instead of message
Co-authored-by: Michaël De Boey <info@michaeldeboey.be> Co-authored-by: Jordan Harband <ljharb@gmail.com>
1 parent e6789db commit 0608b03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+205
-183
lines changed

__tests__/src/rules/alt-text-test.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,40 @@ import rule from '../../../src/rules/alt-text';
1818

1919
const ruleTester = new RuleTester();
2020

21-
const missingPropError = (type) => ({
22-
message: `${type} elements must have an alt prop, either with meaningful text, or an empty string for decorative images.`,
21+
const missingPropError = (nodeType) => ({
22+
messageId: 'img-no-alt',
23+
data: { nodeType },
2324
type: 'JSXOpeningElement',
2425
});
2526

26-
const altValueError = (type) => ({
27-
message: `Invalid alt value for ${type}. \
28-
Use alt="" for presentational images.`,
27+
const altValueError = (nodeType) => ({
28+
messageId: 'img-invalid-alt',
29+
data: { nodeType },
2930
type: 'JSXOpeningElement',
3031
});
3132

3233
const ariaLabelValueError = {
33-
message: 'The aria-label attribute must have a value. The alt attribute is preferred over aria-label for images.',
34+
messageId: 'img-no-aria-label-value',
3435
};
3536
const ariaLabelledbyValueError = {
36-
message: 'The aria-labelledby attribute must have a value. The alt attribute is preferred over aria-labelledby for images.',
37+
messageId: 'img-no-aria-labelledby-value',
3738
};
3839

3940
const preferAltError = () => ({
40-
message: 'Prefer alt="" over a presentational role. First rule of aria is to not use aria if it can be achieved via native HTML.',
41+
messageId: 'img-presentation-role',
4142
type: 'JSXOpeningElement',
4243
});
4344

4445
const objectError = {
45-
message: 'Embedded <object> elements must have alternative text by providing inner text, aria-label or aria-labelledby props.',
46+
messageId: 'object',
4647
};
4748

4849
const areaError = {
49-
message: 'Each area of an image map must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.',
50+
messageId: 'area',
5051
};
5152

5253
const inputImageError = {
53-
message: '<input> elements with type="image" must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.',
54+
messageId: 'input-image',
5455
};
5556

5657
const componentsSettings = {

__tests__/src/rules/anchor-has-content-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import rule from '../../../src/rules/anchor-has-content';
1919
const ruleTester = new RuleTester();
2020

2121
const expectedError = {
22-
message: 'Anchors must have content and the content must be accessible by a screen reader.',
22+
messageId: 'error',
2323
type: 'JSXOpeningElement',
2424
};
2525

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import rule from '../../../src/rules/aria-activedescendant-has-tabindex';
1919
const ruleTester = new RuleTester();
2020

2121
const expectedError = {
22-
message: 'An element that manages focus with `aria-activedescendant` must have a tabindex',
22+
messageId: 'error',
2323
type: 'JSXOpeningElement',
2424
};
2525

__tests__/src/rules/aria-props-test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@ const ariaAttributes = [...aria.keys()];
2323

2424
const errorMessage = (name) => {
2525
const suggestions = getSuggestion(name, ariaAttributes);
26-
const message = `${name}: This attribute is an invalid ARIA attribute.`;
2726

2827
if (suggestions.length > 0) {
2928
return {
3029
type: 'JSXAttribute',
31-
message: `${message} Did you mean to use ${suggestions}?`,
30+
messageId: 'error-with-suggestions',
31+
data: {
32+
name,
33+
suggestions,
34+
},
3235
};
3336
}
3437

3538
return {
3639
type: 'JSXAttribute',
37-
message,
40+
messageId: 'error',
41+
data: { name },
3842
};
3943
};
4044

__tests__/src/rules/aria-proptypes-test.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,10 @@ const errorMessage = (name) => {
2929
values: permittedValues,
3030
} = aria.get(name.toLowerCase());
3131

32-
switch (type) {
33-
case 'tristate':
34-
return { message: `The value for ${name} must be a boolean or the string "mixed".` };
35-
case 'token':
36-
return { message: `The value for ${name} must be a single token from the following: ${permittedValues}.` };
37-
case 'tokenlist':
38-
return {
39-
message: `The value for ${name} must be a list of one or more \
40-
tokens from the following: ${permittedValues}.`,
41-
};
42-
case 'idlist':
43-
return { message: `The value for ${name} must be a list of strings that represent DOM element IDs (idlist)` };
44-
case 'id':
45-
return { message: `The value for ${name} must be a string that represents a DOM element ID` };
46-
case 'boolean':
47-
case 'string':
48-
case 'integer':
49-
case 'number':
50-
default:
51-
return { message: `The value for ${name} must be a ${type}.` };
52-
}
32+
return {
33+
messageId: type,
34+
data: { name, permittedValues, type },
35+
};
5336
};
5437

5538
test('validityCheck', (t) => {

__tests__/src/rules/aria-role-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import rule from '../../../src/rules/aria-role';
2020
const ruleTester = new RuleTester();
2121

2222
const errorMessage = {
23-
message: 'Elements with ARIA roles must use a valid, non-abstract ARIA role.',
23+
messageId: 'error',
2424
type: 'JSXAttribute',
2525
};
2626

__tests__/src/rules/aria-unsupported-elements-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import rule from '../../../src/rules/aria-unsupported-elements';
2121
const ruleTester = new RuleTester();
2222

2323
const errorMessage = (invalidProp) => ({
24-
message: `This element does not support ARIA roles, states and properties. \
25-
Try removing the prop '${invalidProp}'.`,
24+
messageId: 'error',
25+
data: { invalidProp },
2626
type: 'JSXOpeningElement',
2727
});
2828

__tests__/src/rules/autocomplete-valid-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import rule from '../../../src/rules/autocomplete-valid';
2020
const ruleTester = new RuleTester();
2121

2222
const invalidAutocomplete = [{
23-
message: axeFailMessage('autocomplete-valid'),
23+
messageId: 'error',
24+
data: { message: axeFailMessage('autocomplete-valid') },
2425
type: 'JSXOpeningElement',
2526
}];
2627

2728
const inappropriateAutocomplete = [{
28-
message: axeFailMessage('autocomplete-appropriate'),
29+
messageId: 'error',
30+
data: { message: axeFailMessage('autocomplete-appropriate') },
2931
type: 'JSXOpeningElement',
3032
}];
3133

__tests__/src/rules/click-events-have-key-events-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ import rule from '../../../src/rules/click-events-have-key-events';
1818

1919
const ruleTester = new RuleTester();
2020

21-
const errorMessage = 'Visible, non-interactive elements with click handlers must have at least one keyboard listener.';
22-
2321
const expectedError = {
24-
message: errorMessage,
22+
messageId: 'error',
2523
type: 'JSXOpeningElement',
2624
};
2725

__tests__/src/rules/heading-has-content-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import rule from '../../../src/rules/heading-has-content';
1919
const ruleTester = new RuleTester();
2020

2121
const expectedError = {
22-
message: 'Headings must have content and the content must be accessible by a screen reader.',
22+
messageId: 'error',
2323
type: 'JSXOpeningElement',
2424
};
2525

0 commit comments

Comments
 (0)