-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
prefer-message-ids.js
54 lines (47 loc) · 1.46 KB
/
prefer-message-ids.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
const utils = require('../utils');
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'require using `messageId` instead of `message` to report rule violations',
category: 'Rules',
recommended: false,
},
fixable: null,
schema: [],
messages: {
foundMessage: 'Use `messageId` instead of `message`.',
},
},
create (context) {
let contextIdentifiers;
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
return {
Program (ast) {
contextIdentifiers = utils.getContextIdentifiers(context, ast);
},
CallExpression (node) {
if (
node.callee.type === 'MemberExpression' &&
contextIdentifiers.has(node.callee.object) &&
node.callee.property.type === 'Identifier' && node.callee.property.name === 'report'
) {
const reportInfo = utils.getReportInfo(node.arguments, context);
if (!reportInfo || !reportInfo.message) {
return;
}
context.report({
node: reportInfo.message.parent,
messageId: 'foundMessage',
});
}
},
};
},
};