Skip to content

Commit c9b07ce

Browse files
authored
Chore: use utils.getReportInfo (#27)
1 parent 8ac484c commit c9b07ce

File tree

1 file changed

+1
-38
lines changed

1 file changed

+1
-38
lines changed

lib/rules/no-missing-placeholders.js

+1-38
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,6 @@ const utils = require('../utils');
1111
// Rule Definition
1212
// ------------------------------------------------------------------------------
1313

14-
/**
15-
* Gets report info for a context.report() call
16-
* TODO: Combine this with logic from no-deprecated-report-api
17-
* @param {ASTNode[]} reportArgs The arguments to the context.report() call
18-
* @returns {object}
19-
*/
20-
function getReportInfo (reportArgs) {
21-
if (reportArgs.length === 1) {
22-
if (reportArgs[0].type === 'ObjectExpression') {
23-
const messageProp = reportArgs[0].properties.find(prop => utils.getKeyName(prop) === 'message');
24-
const dataProp = reportArgs[0].properties.find(prop => utils.getKeyName(prop) === 'data');
25-
26-
return {
27-
message: messageProp && messageProp.value,
28-
data: dataProp && dataProp.value,
29-
};
30-
}
31-
} else if (reportArgs.length) {
32-
if (reportArgs[1].type === 'Literal' && typeof reportArgs[1].value === 'string') {
33-
return {
34-
message: reportArgs[1],
35-
data: reportArgs[2],
36-
};
37-
} else if (
38-
reportArgs[1].type === 'ObjectExpression' ||
39-
reportArgs[1].type === 'ArrayExpression' ||
40-
(reportArgs[1].type === 'Literal' && typeof reportArgs[1].value !== 'string')
41-
) {
42-
return {
43-
message: reportArgs[2],
44-
data: reportArgs[3],
45-
};
46-
}
47-
}
48-
return null;
49-
}
50-
5114
module.exports = {
5215
meta: {
5316
docs: {
@@ -76,7 +39,7 @@ module.exports = {
7639
contextIdentifiers.has(node.callee.object) &&
7740
node.callee.property.type === 'Identifier' && node.callee.property.name === 'report'
7841
) {
79-
const reportInfo = getReportInfo(node.arguments);
42+
const reportInfo = utils.getReportInfo(node.arguments);
8043

8144
if (
8245
reportInfo &&

0 commit comments

Comments
 (0)