Skip to content

Commit 9ff162d

Browse files
committed
add schema and docs for disallowedForPatterns option
1 parent 5019c92 commit 9ff162d

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

docs/rules/forbid-component-props.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,6 @@ custom message, and a component allowlist:
5555
}
5656
```
5757

58-
For glob string patterns:
59-
60-
```js
61-
{
62-
"propNamePattern": '**-**',
63-
"allowedFor": ['div'],
64-
"message": "Avoid using kebab-case except div"
65-
}
66-
```
67-
6858
Use `disallowedFor` as an exclusion list to warn on props for specific components. `disallowedFor` must have at least one item.
6959

7060
```js
@@ -75,13 +65,13 @@ Use `disallowedFor` as an exclusion list to warn on props for specific component
7565
}
7666
```
7767

78-
For glob string patterns:
68+
For `propNamePattern` glob string patterns:
7969

8070
```js
8171
{
82-
"propNamePattern": "**-**",
83-
"disallowedFor": ["MyComponent"],
84-
"message": "Avoid using kebab-case for MyComponent"
72+
"propNamePattern": '**-**',
73+
"allowedFor": ['div'],
74+
"message": "Avoid using kebab-case except div"
8575
}
8676
```
8777

@@ -95,6 +85,16 @@ Use `allowedForPatterns` for glob string patterns:
9585
}
9686
```
9787

88+
Use `disallowedForPatterns` for glob string patterns:
89+
90+
```js
91+
{
92+
"propName": "someProp",
93+
"disallowedForPatterns": ["*Component"],
94+
"message": "Avoid using `someProp` for components that match the `*Component` pattern"
95+
}
96+
```
97+
9898
### Related rules
9999

100100
- [forbid-dom-props](./forbid-dom-props.md)

lib/rules/forbid-component-props.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,36 @@ module.exports = {
7171
minItems: 1,
7272
items: { type: 'string' },
7373
},
74+
disallowedForPatterns: {
75+
type: 'array',
76+
uniqueItems: true,
77+
items: { type: 'string' },
78+
},
7479
message: { type: 'string' },
7580
},
7681
required: ['disallowedFor'],
7782
additionalProperties: false,
7883
},
84+
{
85+
type: 'object',
86+
properties: {
87+
propName: { type: 'string' },
88+
disallowedFor: {
89+
type: 'array',
90+
uniqueItems: true,
91+
items: { type: 'string' },
92+
},
93+
disallowedForPatterns: {
94+
type: 'array',
95+
uniqueItems: true,
96+
minItems: 1,
97+
items: { type: 'string' },
98+
},
99+
message: { type: 'string' },
100+
},
101+
required: ['disallowedForPatterns'],
102+
additionalProperties: false,
103+
},
79104

80105
{
81106
type: 'object',
@@ -105,11 +130,36 @@ module.exports = {
105130
minItems: 1,
106131
items: { type: 'string' },
107132
},
133+
disallowedForPatterns: {
134+
type: 'array',
135+
uniqueItems: true,
136+
items: { type: 'string' },
137+
},
108138
message: { type: 'string' },
109139
},
110140
required: ['disallowedFor'],
111141
additionalProperties: false,
112142
},
143+
{
144+
type: 'object',
145+
properties: {
146+
propNamePattern: { type: 'string' },
147+
disallowedFor: {
148+
type: 'array',
149+
uniqueItems: true,
150+
items: { type: 'string' },
151+
},
152+
disallowedForPatterns: {
153+
type: 'array',
154+
uniqueItems: true,
155+
minItems: 1,
156+
items: { type: 'string' },
157+
},
158+
message: { type: 'string' },
159+
},
160+
required: ['disallowedForPatterns'],
161+
additionalProperties: false,
162+
},
113163
],
114164
},
115165
},

0 commit comments

Comments
 (0)