From 9042e8fed31dc0fb1be9c521404e9cc634c46d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Mon, 24 Jul 2017 12:54:24 +0800 Subject: [PATCH] Chore: use utils.getReportInfo --- lib/rules/no-missing-placeholders.js | 39 +--------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) 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 &&