Skip to content

Commit

Permalink
enforcing exceptions in schemma incase html and custom set to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbhir committed Mar 12, 2019
1 parent 6d21f56 commit a835a3f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
55 changes: 38 additions & 17 deletions lib/rules/jsx-props-no-spreading.js
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
11 changes: 1 addition & 10 deletions tests/lib/rules/jsx-props-no-spreading.js
Expand Up @@ -81,16 +81,6 @@ ruleTester.run('jsx-props-no-spreading', rule, {
'</App>'
].join('\n'),
options: [{html: 'ignore'}]
}, {
code: [
'const props = {src: "dummy.jpg", alt: "dummy"};',
'<App>',
' <img {...props}/>',
' <div {...someOtherProps}/>',
' <Image {...props}/>',
'</App>'
].join('\n'),
options: [{html: 'ignore', custom: 'ignore'}]
}],

invalid: [{
Expand Down Expand Up @@ -147,6 +137,7 @@ ruleTester.run('jsx-props-no-spreading', rule, {
'<App>',
' <Image {...props}/>',
' <img {...props}/>',
' <div {...props}/>',
'</App>'
].join('\n'),
options: [{custom: 'ignore', html: 'ignore', exceptions: ['Image', 'img']}],
Expand Down

0 comments on commit a835a3f

Please sign in to comment.