Skip to content

Use more efficient regex for boolean-prop-naming #2190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/rules/boolean-prop-naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The list of prop type names that are considered to be booleans. By default this

### `rule`

The RegExp pattern to use when validating the name of the prop. The default value for this option is set to: `"^(is|has)[A-Z]([A-Za-z0-9]?)+"` to enforce `is` and `has` prefixes.
The RegExp pattern to use when validating the name of the prop. The default value for this option is set to: `"^(is|has)[A-Z]"` to enforce `is` and `has` prefixes.

For supporting "is" and "has" naming (default):

Expand All @@ -54,7 +54,7 @@ For supporting "is" and "has" naming (default):
- hasLOL

```jsx
"react/boolean-prop-naming": ["error", { "rule": "^(is|has)[A-Z]([A-Za-z0-9]?)+" }]
"react/boolean-prop-naming": ["error", { "rule": "^(is|has)[A-Z]" }]
```

For supporting "is" naming:
Expand All @@ -63,7 +63,7 @@ For supporting "is" naming:
- isAFK

```jsx
"react/boolean-prop-naming": ["error", { "rule": "^is[A-Z]([A-Za-z0-9]?)+" }]
"react/boolean-prop-naming": ["error", { "rule": "^is[A-Z]" }]
```

### `message`
Expand All @@ -75,7 +75,7 @@ If you choose to use a custom message, you have access to two template variables
* `propName` – the name of the prop that does not match the pattern
* `pattern` – the pattern against which all prop names are tested

For example, if a prop is named `something`, and if the rule's pattern is set to `"^(is|has)[A-Z]([A-Za-z0-9]?)+"`, you could set the custom message as follows:
For example, if a prop is named `something`, and if the rule's pattern is set to `"^(is|has)[A-Z]"`, you could set the custom message as follows:

```js
message: 'It is better if your prop ({{ propName }}) matches this pattern: ({{ pattern }})'
Expand All @@ -84,5 +84,5 @@ message: 'It is better if your prop ({{ propName }}) matches this pattern: ({{ p
And the failure would look like so:

```
It is better if your prop (something) matches this pattern: (^is[A-Z]([A-Za-z0-9]?)+)
It is better if your prop (something) matches this pattern: (^is[A-Z])
```
2 changes: 1 addition & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
uniqueItems: true
},
rule: {
default: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
default: '^(is|has)[A-Z]',
minLength: 1,
type: 'string'
},
Expand Down
Loading