diff --git a/lib/rules/no-missing-placeholders.js b/lib/rules/no-missing-placeholders.js index 6d755ea2..2b16cd4d 100644 --- a/lib/rules/no-missing-placeholders.js +++ b/lib/rules/no-missing-placeholders.js @@ -11,43 +11,6 @@ const utils = require('../utils'); // Rule Definition // ------------------------------------------------------------------------------ -/** -* Gets report info for a context.report() call -* TODO: Combine this with logic from no-deprecated-report-api -* @param {ASTNode[]} reportArgs The arguments to the context.report() call -* @returns {object} -*/ -function getReportInfo (reportArgs) { - if (reportArgs.length === 1) { - if (reportArgs[0].type === 'ObjectExpression') { - const messageProp = reportArgs[0].properties.find(prop => utils.getKeyName(prop) === 'message'); - const dataProp = reportArgs[0].properties.find(prop => utils.getKeyName(prop) === 'data'); - - return { - message: messageProp && messageProp.value, - data: dataProp && dataProp.value, - }; - } - } else if (reportArgs.length) { - if (reportArgs[1].type === 'Literal' && typeof reportArgs[1].value === 'string') { - return { - message: reportArgs[1], - data: reportArgs[2], - }; - } else if ( - reportArgs[1].type === 'ObjectExpression' || - reportArgs[1].type === 'ArrayExpression' || - (reportArgs[1].type === 'Literal' && typeof reportArgs[1].value !== 'string') - ) { - return { - message: reportArgs[2], - data: reportArgs[3], - }; - } - } - return null; -} - module.exports = { meta: { docs: { @@ -76,7 +39,7 @@ module.exports = { contextIdentifiers.has(node.callee.object) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = getReportInfo(node.arguments); + const reportInfo = utils.getReportInfo(node.arguments); if ( reportInfo &&