Skip to content

Commit a835a3f

Browse files
committed
enforcing exceptions in schemma incase html and custom set to ignore
1 parent 6d21f56 commit a835a3f

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

lib/rules/jsx-props-no-spreading.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const docsUrl = require('../util/docsUrl');
1010
// Constants
1111
// ------------------------------------------------------------------------------
1212

13-
const DEFAULTS = {html: 'enforce', custom: 'enforce', exceptions: []};
13+
const OPTIONS = {ignore: 'ignore', enforce: 'enforce'};
14+
const DEFAULTS = {html: OPTIONS.enforce, custom: OPTIONS.enforce, exceptions: []};
1415

1516
// ------------------------------------------------------------------------------
1617
// Rule Definition
@@ -25,29 +26,49 @@ module.exports = {
2526
url: docsUrl('jsx-props-no-spreading')
2627
},
2728
schema: [{
28-
type: 'object',
29-
properties: {
30-
html: {
31-
enum: ['enforce', 'ignore']
32-
},
33-
custom: {
34-
enum: ['enforce', 'ignore']
35-
},
36-
exceptions: {
37-
type: 'array',
38-
items: {
39-
type: 'string',
40-
uniqueItems: true
29+
allOf: [{
30+
type: 'object',
31+
properties: {
32+
html: {
33+
enum: [OPTIONS.enforce, OPTIONS.ignore]
34+
},
35+
custom: {
36+
enum: [OPTIONS.enforce, OPTIONS.ignore]
37+
},
38+
exceptions: {
39+
type: 'array',
40+
items: {
41+
type: 'string',
42+
uniqueItems: true
43+
}
4144
}
4245
}
43-
}
46+
}, {
47+
not: {
48+
type: 'object',
49+
required: ['html', 'custom'],
50+
properties: {
51+
html: {
52+
enum: [OPTIONS.ignore]
53+
},
54+
custom: {
55+
enum: [OPTIONS.ignore]
56+
},
57+
exceptions: {
58+
type: 'array',
59+
minItems: 0,
60+
maxItems: 0
61+
}
62+
}
63+
}
64+
}]
4465
}]
4566
},
4667

4768
create: function (context) {
4869
const configuration = context.options[0] || {};
49-
const ignoreHtmlTags = (configuration.html || DEFAULTS.html) === 'ignore';
50-
const ignoreCustomTags = (configuration.custom || DEFAULTS.custom) === 'ignore';
70+
const ignoreHtmlTags = (configuration.html || DEFAULTS.html) === OPTIONS.ignore;
71+
const ignoreCustomTags = (configuration.custom || DEFAULTS.custom) === OPTIONS.ignore;
5172
const exceptions = configuration.exceptions || DEFAULTS.exceptions;
5273
const isException = (tag, allExceptions) => allExceptions.indexOf(tag) !== -1;
5374
return {

tests/lib/rules/jsx-props-no-spreading.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ ruleTester.run('jsx-props-no-spreading', rule, {
8181
'</App>'
8282
].join('\n'),
8383
options: [{html: 'ignore'}]
84-
}, {
85-
code: [
86-
'const props = {src: "dummy.jpg", alt: "dummy"};',
87-
'<App>',
88-
' <img {...props}/>',
89-
' <div {...someOtherProps}/>',
90-
' <Image {...props}/>',
91-
'</App>'
92-
].join('\n'),
93-
options: [{html: 'ignore', custom: 'ignore'}]
9484
}],
9585

9686
invalid: [{
@@ -147,6 +137,7 @@ ruleTester.run('jsx-props-no-spreading', rule, {
147137
'<App>',
148138
' <Image {...props}/>',
149139
' <img {...props}/>',
140+
' <div {...props}/>',
150141
'</App>'
151142
].join('\n'),
152143
options: [{custom: 'ignore', html: 'ignore', exceptions: ['Image', 'img']}],

0 commit comments

Comments
 (0)