
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
eslint-plugin-props-checker
Advanced tools
Ensure that given props exists in React or React Native Components
This ESLint plugin is designed to verify that certain components (in React/React Native) have specific props defined. This can be useful to ensure that components have whatever props you want them to have.
If the rules are configured correctly, the plugin will generate an error if a component is missing any of the required props.
The plugin also includes a dependOn feature that allows you to specify that prop validation for a particular component should only be performed if another prop is present. For example, you could use this feature to validate that a testID prop exists only if an onPress prop is also present on a component.
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-props-checker:
npm install eslint-plugin-props-checker --save-dev
Add props-checker to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": ["props-checker"]
}
Then configure the rules you want to use under the rules section. Once you enable this, it will errors for all the components that we have mentioned.
A sample can be found below.
{
'rules':
{
'props-checker/validator':
[
'error',
{
props:
[
{ propName: 'testID', components: ['Button', { component: 'Text', dependOn: 'onPress' }] },
{ propName: 'accessible', components: ['TextInput'] }
]
}
]
}
}
According to the above configuration, the plugin will throw an error,
Button component does not have a testID prop.Text component does not have a testID prop only if it has an onPress prop defined.TextInput component does not have an accessible prop.You can use the following configurations to customize the plugin. But,
props, propName and components are mandatory.components can be a string or an object with component and dependOn properties.Props: Array of validation objects
PropName: Name of the prop to be validated
Components: Array of components to be validated against the propName
dependOn featureIf you need to check whether a prop exists only if another prop exists, you can use the dependOn feature. This feature allows you to specify that prop validation for a particular component should only be performed if another prop is present.
ignoreESLintPropValidation prop featureIf you need to ignore the ESLint prop validation of a component in a specific scenario, you can use the ignoreESLintPropValidation prop. Examples are included below.
##Examples
{ 'rules': { 'props-checker/validator': ['warn', { props: [{ propName: 'customProp', components: ['CustomComponent'] }] }] } }
testID prop.{
'rules':
{
'props-checker/validator':
[
'error',
{
props:
[
{ propName: 'testID', components: [{ component: 'Button', dependOn: 'title' }, { component: 'Text', dependOn: 'onPress' }] }
]
}
]
}
}
ignoreESLintPropValidation propIn this example, as you can see, CustomComponent must have a customProp property. But, we can ignore the ESLint prop validation by using the ignoreESLintPropValidation prop.
{ 'rules': { 'props-checker/validator': ['error', { props: [{ propName: 'anyProp', components: [ 'AnyComponent'] }] }] } }
If you want to ignore the ESLint prop validation of the AnyComponent in a particular situation/screen, you can use the ignoreESLintPropValidation prop.
<AnyComponent ignoreESLintPropValidation>
If this plugin configurations take too much space from your main eslintrc file, you can use the extends feature from eslint to keep these rule settings in another file in another directory. Example can be found here.
All PRs are welcome. Please raise an issue before raising a PR.
FAQs
Ensure that given props exists in React or React Native Components
We found that eslint-plugin-props-checker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.