close

boolean-prop-naming

Added in v0.5.2

Configuration

rslint.config.ts
import { defineConfig, reactPlugin } from '@rslint/core';

export default defineConfig([
  reactPlugin.configs.recommended,
  {
    rules: {
      'react/boolean-prop-naming': 'error',
    },
  },
]);

Enforces consistent naming for boolean React props.

Rule Details

This rule checks declared React component prop types and reports any boolean-typed prop whose name does not match a configurable regex (default ^(is|has)[A-Z]([A-Za-z0-9]?)+). It looks at:

  • static propTypes = {...} declared on a class that extends React.Component / React.PureComponent / Component / PureComponent
  • Foo.propTypes = {...} assignments where Foo is a known React component
  • createReactClass({propTypes: {...}}) and React.createClass(...) literal arguments
  • TypeScript type annotations on the first parameter of a functional component ((props: Props) => ... or ({a, b}: {a: boolean}) => ...)
  • TypeScript type arguments on the variable's annotation (const Hello: React.FC<Props> = (props) => ...), including intersection / union compositions

Pass an options object to turn the rule on — ["error", {}] is enough, and rule then falls back to its default ^(is|has)[A-Z]([A-Za-z0-9]?)+. Set rule explicitly to enforce a different pattern.

Examples of incorrect code for this rule:

{ "react/boolean-prop-naming": ["error", {}] }
class Hello extends React.Component {
  static propTypes = { something: PropTypes.bool };
  render() { return <div />; }
}
{ "react/boolean-prop-naming": ["error", { "rule": "^is[A-Z]([A-Za-z0-9]?)+" }] }
class Hello extends React.Component {
  static propTypes = { something: PropTypes.bool };
  render() { return <div />; }
}
{ "react/boolean-prop-naming": ["error", { "rule": "^is[A-Z]([A-Za-z0-9]?)+" }] }
type Props = { enabled: boolean };
const Hello = (props: Props) => <div />;

Examples of correct code for this rule:

{ "react/boolean-prop-naming": ["error", { "rule": "^is[A-Z]([A-Za-z0-9]?)+" }] }
class Hello extends React.Component {
  static propTypes = { isSomething: PropTypes.bool };
  render() { return <div />; }
}
{ "react/boolean-prop-naming": ["error", { "rule": "^is[A-Z]([A-Za-z0-9]?)+" }] }
type Props = { isEnabled: boolean };
const Hello: React.FC<Props> = (props) => <div />;

Options

{
  "react/boolean-prop-naming": ["error", {
    "rule": "^(is|has)[A-Z]([A-Za-z0-9]?)+",
    "propTypeNames": ["bool"],
    "message": "Boolean prop names must begin with `is` or `has`",
    "validateNested": false
  }]
}
  • rule (string, default ^(is|has)[A-Z]([A-Za-z0-9]?)+) — regex source the prop name must match. The default is filled in whenever an options object is present, so ["error", {}] enforces it. Configuring the rule with a severity alone ("error", no options object) leaves it a no-op.
  • propTypeNames (string[]) — names treated as boolean PropTypes. Default ["bool"]. Add custom validators (["bool", "mutuallyExclusiveTrueProps"]) to recognize them as boolean.
  • message (string) — custom error message; supports {{ propName }} and {{ pattern }} placeholders.
  • validateNested (boolean, default false) — when true, recurse into the first argument of any call inside a prop value (e.g. nested: PropTypes.shape({ failingItIs: PropTypes.bool })).

Settings

settings.propWrapperFunctions — array of identifiers (or { object, property } pairs) that wrap propTypes objects, so the rule can inspect inside them. Examples:

{
  "settings": {
    "propWrapperFunctions": [
      "forbidExtraProps",
      "merge",
      { "object": "Object", "property": "assign" },
      { "object": "_", "property": "assign" }
    ]
  }
}

Differences from ESLint

  • Flow type annotations (type Props = { x: boolean } with BooleanTypeAnnotation, ObjectTypeProperty, etc.) are not validated — rslint parses these as TypeScript, so only the equivalent TypeScript shapes (TypeLiteralNode, TSPropertySignature, BooleanKeyword) are checked. TypeScript-flavored equivalents of every Flow case in the upstream test suite report identically.

Original Documentation