diff --git a/lib/rules/jsx-props-no-spreading.js b/lib/rules/jsx-props-no-spreading.js index 7081185fff..f8915d8337 100644 --- a/lib/rules/jsx-props-no-spreading.js +++ b/lib/rules/jsx-props-no-spreading.js @@ -10,7 +10,8 @@ const docsUrl = require('../util/docsUrl'); // Constants // ------------------------------------------------------------------------------ -const DEFAULTS = {html: 'enforce', custom: 'enforce', exceptions: []}; +const OPTIONS = {ignore: 'ignore', enforce: 'enforce'}; +const DEFAULTS = {html: OPTIONS.enforce, custom: OPTIONS.enforce, exceptions: []}; // ------------------------------------------------------------------------------ // Rule Definition @@ -25,29 +26,49 @@ module.exports = { url: docsUrl('jsx-props-no-spreading') }, schema: [{ - type: 'object', - properties: { - html: { - enum: ['enforce', 'ignore'] - }, - custom: { - enum: ['enforce', 'ignore'] - }, - exceptions: { - type: 'array', - items: { - type: 'string', - uniqueItems: true + allOf: [{ + type: 'object', + properties: { + html: { + enum: [OPTIONS.enforce, OPTIONS.ignore] + }, + custom: { + enum: [OPTIONS.enforce, OPTIONS.ignore] + }, + exceptions: { + type: 'array', + items: { + type: 'string', + uniqueItems: true + } } } - } + }, { + not: { + type: 'object', + required: ['html', 'custom'], + properties: { + html: { + enum: [OPTIONS.ignore] + }, + custom: { + enum: [OPTIONS.ignore] + }, + exceptions: { + type: 'array', + minItems: 0, + maxItems: 0 + } + } + } + }] }] }, create: function (context) { const configuration = context.options[0] || {}; - const ignoreHtmlTags = (configuration.html || DEFAULTS.html) === 'ignore'; - const ignoreCustomTags = (configuration.custom || DEFAULTS.custom) === 'ignore'; + const ignoreHtmlTags = (configuration.html || DEFAULTS.html) === OPTIONS.ignore; + const ignoreCustomTags = (configuration.custom || DEFAULTS.custom) === OPTIONS.ignore; const exceptions = configuration.exceptions || DEFAULTS.exceptions; const isException = (tag, allExceptions) => allExceptions.indexOf(tag) !== -1; return { diff --git a/tests/lib/rules/jsx-props-no-spreading.js b/tests/lib/rules/jsx-props-no-spreading.js index 900f6b5e16..ac4f28fffc 100644 --- a/tests/lib/rules/jsx-props-no-spreading.js +++ b/tests/lib/rules/jsx-props-no-spreading.js @@ -81,16 +81,6 @@ ruleTester.run('jsx-props-no-spreading', rule, { '' ].join('\n'), options: [{html: 'ignore'}] - }, { - code: [ - 'const props = {src: "dummy.jpg", alt: "dummy"};', - '', - ' ', - '
', - ' ', - '' - ].join('\n'), - options: [{html: 'ignore', custom: 'ignore'}] }], invalid: [{ @@ -147,6 +137,7 @@ ruleTester.run('jsx-props-no-spreading', rule, { '', ' ', ' ', + '
', '' ].join('\n'), options: [{custom: 'ignore', html: 'ignore', exceptions: ['Image', 'img']}],