Skip to content

Commit

Permalink
Run deep booleans name check only if option is true
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelnvk committed Apr 11, 2019
1 parent e8dc9c1 commit ad3d774
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
15 changes: 14 additions & 1 deletion docs/rules/boolean-prop-naming.md
Expand Up @@ -30,7 +30,12 @@ var Hello = createReactClass({

```js
...
"react/boolean-prop-naming": [<enabled>, { "propTypeNames": Array<string>, "rule": <string>, "message": <string> }]
"react/boolean-prop-naming": [<enabled>, {
"propTypeNames": Array<string>,
"rule": <string>,
"message": <string>,
"validateNested": <boolean>
}]
...
```

Expand Down Expand Up @@ -86,3 +91,11 @@ And the failure would look like so:
```
It is better if your prop (something) matches this pattern: (^is[A-Z]([A-Za-z0-9]?)+)
```

### `validateNested`

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:

```jsx
"react/boolean-prop-naming": ["error", { "validateNested": true }]
```
6 changes: 5 additions & 1 deletion lib/rules/boolean-prop-naming.js
Expand Up @@ -41,6 +41,10 @@ module.exports = {
message: {
minLength: 1,
type: 'string'
},
validateNested: {
default: false,
type: 'boolean'
}
},
type: 'object'
Expand Down Expand Up @@ -152,7 +156,7 @@ module.exports = {
proptypes = proptypes || [];

proptypes.forEach(prop => {
if (nestedPropTypes(prop)) {
if (config.validateNested && nestedPropTypes(prop)) {
runCheck(prop.value.arguments[0].properties, addInvalidProp);
return;
}
Expand Down
12 changes: 9 additions & 3 deletions tests/lib/rules/boolean-prop-naming.js
Expand Up @@ -408,7 +408,11 @@ ruleTester.run('boolean-prop-naming', rule, {
})
})
};
`
`,
options: [{
rule: '^is[A-Z]([A-Za-z0-9]?)+',
validateNested: true
}]
}],

invalid: [{
Expand Down Expand Up @@ -861,7 +865,8 @@ ruleTester.run('boolean-prop-naming', rule, {
};
`,
options: [{
rule: '^is[A-Z]([A-Za-z0-9]?)+'
rule: '^is[A-Z]([A-Za-z0-9]?)+',
validateNested: true
}],
errors: [{
message: 'Prop name (failingItIs) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
Expand All @@ -886,7 +891,8 @@ ruleTester.run('boolean-prop-naming', rule, {
};
`,
options: [{
rule: '^is[A-Z]([A-Za-z0-9]?)+'
rule: '^is[A-Z]([A-Za-z0-9]?)+',
validateNested: true
}],
errors: [{
message: 'Prop name (failingItIs) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
Expand Down

0 comments on commit ad3d774

Please sign in to comment.