Skip to content

Commit d384401

Browse files
committed
Use messageId for errors
1 parent 60862ad commit d384401

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

lib/rules/await-async-query.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const VALID_PARENTS = [
88

99
const ASYNC_QUERIES_REGEXP = /^find(All)?By(LabelText|PlaceholderText|Text|AltText|Title|DisplayValue|Role|TestId)$/;
1010

11-
const getError = nodeName => `\`${nodeName}\` must have \`await\` operator`;
12-
1311
module.exports = {
1412
meta: {
1513
type: 'problem',
@@ -20,6 +18,9 @@ module.exports = {
2018
recommended: true,
2119
url: 'TODO',
2220
},
21+
messages: {
22+
awaitAsyncQuery: '`{{ name }}` must have `await` operator',
23+
},
2324
fixable: null,
2425
schema: [],
2526
},
@@ -39,7 +40,10 @@ module.exports = {
3940
if (hasError) {
4041
context.report({
4142
node,
42-
message: getError(node.name),
43+
messageId: 'awaitAsyncQuery',
44+
data: {
45+
name: node.name,
46+
},
4347
});
4448
}
4549
},

lib/rules/no-await-sync-query.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const SYNC_QUERIES_REGEXP = /^(get|query)(All)?By(LabelText|PlaceholderText|Text|AltText|Title|DisplayValue|Role|TestId)$/;
44

5-
const getError = nodeName => `\`${nodeName}\` does not need \`await\` operator`;
6-
75
module.exports = {
86
meta: {
97
type: 'problem',
@@ -13,6 +11,9 @@ module.exports = {
1311
recommended: true,
1412
url: 'TODO',
1513
},
14+
messages: {
15+
noAwaitSyncQuery: '`{{ name }}` does not need `await` operator',
16+
},
1617
fixable: null,
1718
schema: [],
1819
},
@@ -24,7 +25,10 @@ module.exports = {
2425
) {
2526
context.report({
2627
node,
27-
message: getError(node.name),
28+
messageId: 'noAwaitSyncQuery',
29+
data: {
30+
name: node.name,
31+
},
2832
});
2933
},
3034
};

tests/lib/rules/await-async-query.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ruleTester.run('await-async-query', rule, {
6868
`,
6969
errors: [
7070
{
71-
message: '`findByText` must have `await` operator',
71+
messageId: 'awaitAsyncQuery',
7272
},
7373
],
7474
},
@@ -80,7 +80,7 @@ ruleTester.run('await-async-query', rule, {
8080
`,
8181
errors: [
8282
{
83-
message: '`findByText` must have `await` operator',
83+
messageId: 'awaitAsyncQuery',
8484
},
8585
],
8686
},
@@ -92,7 +92,7 @@ ruleTester.run('await-async-query', rule, {
9292
`,
9393
errors: [
9494
{
95-
message: '`findAllByText` must have `await` operator',
95+
messageId: 'awaitAsyncQuery',
9696
},
9797
],
9898
},

tests/lib/rules/no-await-sync-query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ruleTester.run('no-await-sync-query', rule, {
3030
`,
3131
errors: [
3232
{
33-
message: '`getByText` does not need `await` operator',
33+
messageId: 'noAwaitSyncQuery',
3434
},
3535
],
3636
},

0 commit comments

Comments
 (0)