Skip to main content
interlace
Plugin: react-featuresRules

prop-types

prop-types rule

prop-types rule

Enforce prop types validation for React components. This rule is part of eslint-plugin-react-features.

Quick Summary

AspectDetails
SeverityWarning (type safety)
Auto-Fix❌ No (requires prop type definitions)
CategoryReact
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForJavaScript React projects (TypeScript preferred)

Rule Details

A class component (extending React's Component or PureComponent, by binding, declared or as a class expression) must declare its props. Any of these declares them: a static propTypes (any key spelling), a Card.propTypes = … assignment, or TypeScript props on the base class (React.Component<Props>).

Why This Matters

IssueImpactSolution
🔄 No type safetyRuntime errors from wrong propsDefine PropTypes
🐛 Poor documentationUnclear component APIPropTypes document interface
🔍 Debug difficultySilent failures with wrong typesRuntime warnings in dev

Examples

❌ Incorrect

// BAD: No PropTypes defined
class UserCard extends React.Component {
  render() {
    return (
      <div>
        <h1>{this.props.name}</h1>
        <p>{this.props.email}</p>
      </div>
    );
  }
}

✅ Correct

import PropTypes from 'prop-types';

// GOOD: PropTypes defined
class UserCard extends React.Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
    email: PropTypes.string.isRequired,
    age: PropTypes.number,
    role: PropTypes.oneOf(['admin', 'user', 'guest']),
    onUpdate: PropTypes.func,
  };
  
  static defaultProps = {
    age: 0,
    role: 'user',
  };
  
  render() {
    const { name, email, age, role } = this.props;
    return (
      <div>
        <h1>{name}</h1>
        <p>{email}</p>
      </div>
    );
  }
}

// BETTER: Use TypeScript instead
interface UserCardProps {
  name: string;
  email: string;
  age?: number;
  role?: 'admin' | 'user' | 'guest';
  onUpdate?: () => void;
}

function UserCard({ name, email, age = 0, role = 'user' }: UserCardProps) {
  return (
    <div>
      <h1>{name}</h1>
      <p>{email}</p>
    </div>
  );
}

Options

OptionTypeDefaultDescription
ignorestring[][]Component names to ignore
customValidatorsstring[][]Accepted for compatibility; it has no effect
skipUndeclaredbooleanfalseSkip if no props are accessed

Configuration with Options

{
  rules: {
    'react-features/prop-types': ['warn', {
      ignore: ['Link', 'Router'],           // Third-party components
      skipUndeclared: true                  // Skip components not using props
    }]
  }
}

Configuration Examples

Basic Usage

{
  rules: {
    'react-features/prop-types': 'warn'
  }
}

Strict Usage

{
  rules: {
    'react-features/prop-types': 'error'
  }
}

Further Reading

Known False Negatives

  • Function components are not checked; the rule reads class components only.
  • A component that never reads this.props is still reported under the default skipUndeclared: false.

Use this rule

npm install -D oxlint-plugin-react-features
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-react-features"],  "rules": {    "react-features/prop-types": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-react-features'],    rules: {      'react-features/prop-types': 'error',    },  },});

oxlint-plugin-react-features re-exports eslint-plugin-react-features/oxlint: the same rules under the same IDs, and no ESLint install. Why oxlint.

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.