diff --git a/packages/eslint-plugin-ecmascript-compat/lib/delegation.js b/packages/eslint-plugin-ecmascript-compat/lib/delegation.js index b6e8532..0e0208f 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/delegation.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/delegation.js @@ -1,5 +1,6 @@ function createDelegatee(config, rootContext) { const { definition, options } = config; + const pollyfils = (rootContext.options && rootContext.options[0] && rootContext.options[0].polyfills) || []; // All methods except report() are added later. Define necessary ones for used rules. const contextLaterAddedMethods = { @@ -15,11 +16,26 @@ function createDelegatee(config, rootContext) { report, }; + function matchesPollyfil(data, pollyfil) { + if (data.message) { + return data.message.includes(`'${pollyfil}'`) + } + if (data.name) { + return data.name === pollyfil; + } + return false; + } + function report(params) { // Discard fixer; we can't declare the rule as fixable because not all delegatees are. // Look up messageId on delegate meta; report() would look it up on root rule meta. const { fix, message, messageId, ...otherParams } = params; + // Skip report if known polyfill exists + if (params.data && pollyfils.some(pollyfil => matchesPollyfil(params.data, pollyfil))) { + return; + } + rootContext.report({ ...otherParams, message: messageId ? definition.meta.messages[messageId] : message, diff --git a/packages/eslint-plugin-ecmascript-compat/lib/rule.js b/packages/eslint-plugin-ecmascript-compat/lib/rule.js index 337d106..70b5cbd 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/rule.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/rule.js @@ -11,7 +11,20 @@ const delegateeConfigs = compatibility module.exports = { meta: { type: 'problem', - schema: [], // no options + schema: [ + { + "type": "object", + "properties": { + "pollyfils": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": "false", + } + ] }, create(context) { const visitors = delegateeConfigs.map((config) => createDelegatee(config, context));