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.
npm install -D eslint-plugin-react-featuresimport { configs } from 'eslint-plugin-react-features';
export default [configs.recommended];
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
| Aspect | Details |
|---|---|
| Severity | Warning (best practice) |
| Auto-Fix | ❌ No auto-fix |
| Category | React |
| ESLint MCP | ✅ Optimized for ESLint MCP integration |
| Best For | Projects 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
| Option | Type | Default | Description |
|---|---|---|---|
allowInPropTypes | boolean | false | Allow 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-featuresimport 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{ "jsPlugins": ["oxlint-plugin-react-features"], "rules": { "react-features/forbid-foreign-prop-types": "error" }}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.