Skip to content

Commit ad3d774

Browse files
author
Paweł Nowak
committed
Run deep booleans name check only if option is true
1 parent e8dc9c1 commit ad3d774

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

docs/rules/boolean-prop-naming.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ var Hello = createReactClass({
3030

3131
```js
3232
...
33-
"react/boolean-prop-naming": [<enabled>, { "propTypeNames": Array<string>, "rule": <string>, "message": <string> }]
33+
"react/boolean-prop-naming": [<enabled>, {
34+
"propTypeNames": Array<string>,
35+
"rule": <string>,
36+
"message": <string>,
37+
"validateNested": <boolean>
38+
}]
3439
...
3540
```
3641

@@ -86,3 +91,11 @@ And the failure would look like so:
8691
```
8792
It is better if your prop (something) matches this pattern: (^is[A-Z]([A-Za-z0-9]?)+)
8893
```
94+
95+
### `validateNested`
96+
97+
This value is boolean. It tells if nested props should be validated as well. By default this is set to false but you can change it to true, to validate deeper layers of object:
98+
99+
```jsx
100+
"react/boolean-prop-naming": ["error", { "validateNested": true }]
101+
```

lib/rules/boolean-prop-naming.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ module.exports = {
4141
message: {
4242
minLength: 1,
4343
type: 'string'
44+
},
45+
validateNested: {
46+
default: false,
47+
type: 'boolean'
4448
}
4549
},
4650
type: 'object'
@@ -152,7 +156,7 @@ module.exports = {
152156
proptypes = proptypes || [];
153157

154158
proptypes.forEach(prop => {
155-
if (nestedPropTypes(prop)) {
159+
if (config.validateNested && nestedPropTypes(prop)) {
156160
runCheck(prop.value.arguments[0].properties, addInvalidProp);
157161
return;
158162
}

tests/lib/rules/boolean-prop-naming.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,11 @@ ruleTester.run('boolean-prop-naming', rule, {
408408
})
409409
})
410410
};
411-
`
411+
`,
412+
options: [{
413+
rule: '^is[A-Z]([A-Za-z0-9]?)+',
414+
validateNested: true
415+
}]
412416
}],
413417

414418
invalid: [{
@@ -861,7 +865,8 @@ ruleTester.run('boolean-prop-naming', rule, {
861865
};
862866
`,
863867
options: [{
864-
rule: '^is[A-Z]([A-Za-z0-9]?)+'
868+
rule: '^is[A-Z]([A-Za-z0-9]?)+',
869+
validateNested: true
865870
}],
866871
errors: [{
867872
message: 'Prop name (failingItIs) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
@@ -886,7 +891,8 @@ ruleTester.run('boolean-prop-naming', rule, {
886891
};
887892
`,
888893
options: [{
889-
rule: '^is[A-Z]([A-Za-z0-9]?)+'
894+
rule: '^is[A-Z]([A-Za-z0-9]?)+',
895+
validateNested: true
890896
}],
891897
errors: [{
892898
message: 'Prop name (failingItIs) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'

0 commit comments

Comments
 (0)