Skip to content

Commit a2600b2

Browse files
author
Ell Bradshaw
committed
Add tests, fix bug with disallowList on components
Yay tests
1 parent cf08725 commit a2600b2

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

lib/rules/forbid-component-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.exports = {
8282

8383
const propName = typeof value === 'string' ? value : value.propName;
8484
const options = {
85-
allowList: typeof value === 'string' ? [] : (value.allowedFor || []),
85+
allowList: typeof value === 'string' ? null : (value.allowedFor || null),
8686
disallowList: typeof value === 'string' ? null : (value.disallowedFor || null),
8787
message: typeof value === 'string' ? null : value.message,
8888
};

tests/lib/rules/forbid-component-props.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,36 @@ ruleTester.run('forbid-component-props', rule, {
151151
},
152152
],
153153
},
154+
{
155+
code: `
156+
const item = (<Foo className="foo" />);
157+
`,
158+
options: [
159+
{
160+
forbid: [
161+
{
162+
propName: 'className',
163+
disallowedFor: ['ReactModal'],
164+
},
165+
],
166+
},
167+
],
168+
},
169+
{
170+
code: `
171+
const item = (<Foo className="foo" />);
172+
`,
173+
options: [
174+
{
175+
forbid: [
176+
{
177+
propName: 'className',
178+
disallowedFor: ['ReactModal'],
179+
},
180+
],
181+
},
182+
],
183+
},
154184
{
155185
code: `
156186
<fbt:param name="Total number of files" number={true} />
@@ -282,6 +312,54 @@ ruleTester.run('forbid-component-props', rule, {
282312
},
283313
],
284314
},
315+
{
316+
code: `
317+
const item = (<ReactModal className="foo" />);
318+
`,
319+
options: [
320+
{
321+
forbid: [
322+
{
323+
propName: 'className',
324+
disallowedFor: ['ReactModal'],
325+
},
326+
],
327+
},
328+
],
329+
errors: [
330+
{
331+
messageId: 'propIsForbidden',
332+
data: { prop: 'className' },
333+
line: 2,
334+
column: 35,
335+
type: 'JSXAttribute',
336+
},
337+
],
338+
},
339+
{
340+
code: `
341+
const item = (<AntdLayout.Content className="antdFoo" />);
342+
`,
343+
options: [
344+
{
345+
forbid: [
346+
{
347+
propName: 'className',
348+
disallowedFor: ['AntdLayout.Content'],
349+
},
350+
],
351+
},
352+
],
353+
errors: [
354+
{
355+
messageId: 'propIsForbidden',
356+
data: { prop: 'className' },
357+
line: 2,
358+
column: 43,
359+
type: 'JSXAttribute',
360+
},
361+
],
362+
},
285363
{
286364
code: `
287365
const item = (<Foo className="foo" />);

tests/lib/rules/forbid-dom-props.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ ruleTester.run('forbid-dom-props', rule, {
112112
},
113113
],
114114
},
115+
{
116+
code: `
117+
const First = (props) => (
118+
<span otherProp="bar" />
119+
);
120+
`,
121+
options: [
122+
{
123+
forbid: [
124+
{
125+
propName: 'otherProp',
126+
allowedFor: ['span'],
127+
},
128+
],
129+
},
130+
],
131+
},
115132
]),
116133

117134
invalid: parsers.all([

0 commit comments

Comments
 (0)