Skip to main content
Skip to Content
interlace
Plugin: react-featuresRules

forbid-foreign-prop-types

Disallow using another component's propTypes

Next step

forbid-foreign-prop-types ships in eslint-plugin-react-features, with 11 of its 68 rules in the recommended preset.

Install
npm install -D eslint-plugin-react-features
eslint.config.js
import { configs } from 'eslint-plugin-react-features';

export default [configs.recommended];

Plugin pagenpmSource on GitHub

Foo.propTypes is not safe to read from another component: production builds that strip propTypes leave undefined behind. This rule is part of eslint-plugin-react-features and follows eslint-plugin-react/forbid-foreign-prop-types in behaviour and options. Its upstream test cases (eslint-plugin-react 7.37.5, MIT) run against it: 38 of 38 agree.

Quick Summary

AspectDetails
SeverityWarning (best practice)
Auto-Fix❌ No auto-fix
CategoryReact
ESLint MCP✅ Optimized for ESLint MCP integration
Best ForProjects that still use prop-types

Rule Details

The rule reports a read of .propTypes (also ['propTypes']) and a destructured propTypes key (const { propTypes } = Foo). Writing a component's own Foo.propTypes = {...} is fine.

Examples

❌ Incorrect

var propTypes = Foo.propTypes;

var { propTypes } = SomeComponent;

var foo = { propTypes: SomeComponent.propTypes };

Bar.propTypes = Foo.propTypes;

✅ Correct

Foo.propTypes = { a: PropTypes.string };

var sharedShape = { a: PropTypes.string };

Options

OptionTypeDefaultDescription
allowInPropTypesbooleanfalseAllow the read when it sits inside a X.propTypes = {...} assignment or a static propTypes = {...} class field (shape reuse in a declaration)
'react-features/forbid-foreign-prop-types': ['error', { allowInPropTypes: true }]

When Not To Use It

When production builds keep propTypes, or the project has no propTypes at all.

Use this rule

npm install -D eslint-plugin-react-features
eslint.config.js
import reactFeatures from 'eslint-plugin-react-features';export default [  {    plugins: { 'react-features': reactFeatures },    rules: {      'react-features/forbid-foreign-prop-types': 'error'    },  },];
npm install -D oxlint-plugin-react-features
.oxlintrc.json
{  "jsPlugins": ["oxlint-plugin-react-features"],  "rules": {    "react-features/forbid-foreign-prop-types": "error"  }}
vite.config.ts
import { defineConfig } from 'vite-plus';export default defineConfig({  lint: {    jsPlugins: ['oxlint-plugin-react-features'],    rules: {      'react-features/forbid-foreign-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.